first commit

This commit is contained in:
2026-09-11 01:45:04 +08:00
commit 0a8d60d87f
145 changed files with 40978 additions and 0 deletions
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"clothes-card": "/components/clothes-card/clothes-card"
}
}
@@ -0,0 +1,148 @@
import { request } from '../../utils/request'
import { ClothesItem, PagedResult, UserInfo } from '../../types/models'
import { STORAGE_KEYS } from '../../utils/config'
const CATEGORIES = [
{ name: '全部', value: '' },
{ name: '上装', value: '上装' },
{ name: '下装', value: '下装' },
{ name: '连衣裙', value: '连衣裙' },
{ name: '外套', value: '外套' },
{ name: '鞋', value: '鞋' },
{ name: '配饰', value: '配饰' },
]
const EXPIRE_OPTIONS = [
{ label: '1 天', days: 1 },
{ label: '7 天', days: 7 },
{ label: '30 天', days: 30 },
{ label: '长期有效', days: 0 },
]
Page({
data: {
view: 'config' as 'config' | 'select' | 'success',
shareType: 1,
expireDays: 7,
expireOptions: EXPIRE_OPTIONS,
selectedUuids: [] as string[],
categories: CATEGORIES,
activeCategory: 0,
allClothes: [] as ClothesItem[],
selectLoading: true,
shareUuid: '',
nickname: '微信用户',
avatar: '',
selectedCount: 0,
},
onLoad() {
this.loadUserInfo()
},
loadUserInfo() {
const cached = wx.getStorageSync(STORAGE_KEYS.USER_INFO) as Record<string, any>
if (cached) {
this.setData({ nickname: cached.username || '微信用户', avatar: cached.avatar || '' })
}
// 头像为带时间戳的签名 URL,缓存可能过期,实时刷新并回写缓存。
request<UserInfo>({ url: '/user/info', showError: false })
.then((user) => {
wx.setStorageSync(STORAGE_KEYS.USER_INFO, user)
this.setData({ nickname: user.username || '微信用户', avatar: user.avatar || '' })
})
.catch(() => {})
},
selectPartial() {
this.setData({ shareType: 1 })
},
selectFull() {
this.setData({ shareType: 2 })
},
selectExpire(e: WechatMiniprogram.TouchEvent) {
const days = Number(e.currentTarget.dataset.days)
this.setData({ expireDays: days })
},
openSelect() {
this.setData({ view: 'select', selectLoading: true })
this.fetchAllClothes()
},
fetchAllClothes() {
const cat = CATEGORIES[this.data.activeCategory].value
const params: Record<string, any> = { page: 1, page_size: 50 }
if (cat) params.category_main = cat
request<PagedResult<ClothesItem>>({ url: '/clothes', data: params })
.then((res) => {
const list = res.list.map((it) => ({
...it,
_selected: this.data.selectedUuids.indexOf(it.clothes_uuid) >= 0,
}))
this.setData({ allClothes: list, selectLoading: false })
})
.catch(() => this.setData({ selectLoading: false }))
},
onCategoryTap(e: WechatMiniprogram.TouchEvent) {
const index = Number(e.currentTarget.dataset.index)
if (index === this.data.activeCategory) return
this.setData({ activeCategory: index, selectLoading: true })
this.fetchAllClothes()
},
onToggleSelect(e: WechatMiniprogram.CustomEvent) {
const item = e.detail.item as ClothesItem
const uuids = this.data.selectedUuids
const idx = uuids.indexOf(item.clothes_uuid)
if (idx >= 0) {
this.syncSelect(uuids.filter((u) => u !== item.clothes_uuid))
} else {
this.syncSelect([...uuids, item.clothes_uuid])
}
},
syncSelect(uuids: string[]) {
this.setData({
selectedUuids: uuids,
allClothes: this.data.allClothes.map((it) => ({
...it,
_selected: uuids.indexOf(it.clothes_uuid) >= 0,
})),
})
},
confirmSelect() {
this.setData({ view: 'config', selectedCount: this.data.selectedUuids.length })
},
backToConfig() {
this.setData({ view: 'config' })
},
onConfirm() {
const body: Record<string, any> = { share_type: this.data.shareType }
if (this.data.shareType === 1) {
if (!this.data.selectedUuids.length) {
wx.showToast({ title: '请选择要分享的衣物', icon: 'none' })
return
}
body.clothes_uuids = this.data.selectedUuids
}
const days = this.data.expireDays
body.expire_time = days > 0 ? Math.floor(Date.now() / 1000) + days * 86400 : 0
request<{ share_uuid: string }>({ url: '/closet-share', method: 'POST', data: body })
.then((res) => this.setData({ shareUuid: res.share_uuid, view: 'success' }))
.catch(() => {})
},
onViewShare() {
wx.redirectTo({ url: `/pages/closet-share-detail/closet-share-detail?uuid=${this.data.shareUuid}` })
},
onDone() {
wx.navigateBack()
},
})
@@ -0,0 +1,102 @@
<view class="page create-page">
<navigation-bar title="创建分享" />
<!-- 配置视图 -->
<scroll-view wx:if="{{view === 'config'}}" scroll-y class="scroll-body">
<view class="section-title">分享方式</view>
<view class="type-card card {{shareType === 1 ? 'active' : ''}}" bindtap="selectPartial">
<view class="type-name">部分衣物</view>
<view class="type-desc">挑选几件衣物分享给好友</view>
<view wx:if="{{shareType === 1}}" class="icon icon-check type-check"></view>
</view>
<view class="type-card card {{shareType === 2 ? 'active' : ''}}" bindtap="selectFull">
<view class="type-name">全量快照</view>
<view class="type-desc">分享当前衣橱的全部衣物</view>
<view wx:if="{{shareType === 2}}" class="icon icon-check type-check"></view>
</view>
<!-- 选择衣物入口(部分衣物) -->
<view wx:if="{{shareType === 1}}" class="card select-entry" bindtap="openSelect">
<view class="entry-left">
<view class="entry-icon"><view class="icon icon-shirt"></view></view>
<view class="entry-title">选择衣物</view>
</view>
<view class="entry-right">
<text class="entry-count {{selectedCount ? 'on' : ''}}">{{selectedCount ? '已选 ' + selectedCount + ' 件' : '未选择'}}</text>
<view class="icon icon-chevron-right"></view>
</view>
</view>
<view class="section-title">有效期</view>
<view class="card expire-card">
<view
class="expire-item hairline"
wx:for="{{expireOptions}}"
wx:key="days"
data-days="{{item.days}}"
bindtap="selectExpire"
>
<text>{{item.label}}</text>
<view wx:if="{{expireDays === item.days}}" class="icon icon-check expire-check"></view>
</view>
</view>
<view class="footer">
<view class="btn btn-primary" bindtap="onConfirm">确认分享(消耗 1 次衣柜分享额度)</view>
</view>
</scroll-view>
<!-- 选择衣物视图 -->
<view wx:elif="{{view === 'select'}}" class="select-view">
<scroll-view scroll-x class="cat-scroll" show-scrollbar="{{false}}">
<view class="cat-row">
<view
wx:for="{{categories}}"
wx:key="name"
class="cat-item {{activeCategory === index ? 'active' : ''}}"
data-index="{{index}}"
bindtap="onCategoryTap"
>{{item.name}}</view>
</view>
</scroll-view>
<scroll-view scroll-y class="select-body">
<view wx:if="{{selectLoading}}" class="grid">
<view class="grid-item" wx:for="{{[1, 2, 3, 4]}}" wx:key="*this">
<view class="skeleton sk-card"></view>
</view>
</view>
<view wx:else class="grid">
<view class="grid-item" wx:for="{{allClothes}}" wx:key="clothes_uuid">
<clothes-card item="{{item}}" selectable selected="{{item._selected}}" bind:select="onToggleSelect" />
</view>
</view>
</scroll-view>
<view class="select-footer">
<view class="sf-count">已选 <text class="t-primary">{{selectedUuids.length}}</text> 件</view>
<view class="sf-confirm btn btn-primary" bindtap="confirmSelect">确定</view>
</view>
</view>
<!-- 成功预览 -->
<view wx:else class="success-view">
<view class="success-icon"><view class="icon icon-check"></view></view>
<view class="success-title">分享已创建</view>
<view class="preview-card">
<view class="preview-top">
<view class="avatar">
<image wx:if="{{avatar}}" class="avatar-img" src="{{avatar}}" mode="aspectFill" />
<view wx:else class="icon icon-user avatar-placeholder"></view>
</view>
<text class="preview-name">{{nickname}} 向你分享了 {{selectedCount || '全部'}} 件衣物</text>
</view>
<view class="preview-body">
<view class="icon icon-hanger"></view>
</view>
<view class="preview-btn">查看衣橱</view>
</view>
<view class="success-btns">
<view class="btn btn-outline" bindtap="onDone">完成</view>
<view class="btn btn-primary" bindtap="onViewShare">查看分享</view>
</view>
</view>
</view>
@@ -0,0 +1,322 @@
.create-page {
height: 100vh;
display: flex;
flex-direction: column;
}
.scroll-body {
flex: 1;
height: 0;
}
.section-title {
font-size: 26rpx;
color: #8E8E93;
padding: 24rpx 24rpx 16rpx;
}
.type-card {
position: relative;
margin: 0 24rpx 20rpx;
border: 2rpx solid transparent;
}
.type-card.active {
border-color: #007AFF;
}
.type-name {
font-size: 30rpx;
font-weight: 600;
color: #000;
}
.type-desc {
font-size: 24rpx;
color: #8E8E93;
margin-top: 8rpx;
}
.type-check {
position: absolute;
top: 32rpx;
right: 32rpx;
width: 36rpx;
height: 36rpx;
color: #007AFF;
}
.select-entry {
margin: 0 24rpx 20rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.entry-left {
display: flex;
align-items: center;
}
.entry-icon {
width: 72rpx;
height: 72rpx;
border-radius: 24rpx;
background: rgba(0, 122, 255, 0.1);
color: #007AFF;
display: flex;
align-items: center;
justify-content: center;
margin-right: 24rpx;
}
.entry-icon .icon {
width: 40rpx;
height: 40rpx;
}
.entry-title {
font-size: 28rpx;
font-weight: 600;
color: #1C1C1E;
}
.entry-right {
display: flex;
align-items: center;
color: #8E8E93;
}
.entry-count {
font-size: 26rpx;
margin-right: 8rpx;
}
.entry-count.on {
color: #007AFF;
}
.entry-right .icon {
width: 28rpx;
height: 28rpx;
color: #C7C7CC;
}
.expire-card {
margin: 0 24rpx;
padding: 0 32rpx;
}
.expire-item {
display: flex;
align-items: center;
justify-content: space-between;
height: 88rpx;
font-size: 28rpx;
color: #000;
}
.expire-check {
width: 36rpx;
height: 36rpx;
color: #007AFF;
}
.footer {
padding: 24rpx;
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
}
/* 选择视图 */
.select-view {
flex: 1;
height: 0;
display: flex;
flex-direction: column;
}
.cat-scroll {
background: #fff;
white-space: nowrap;
flex-shrink: 0;
}
.cat-row {
display: inline-flex;
padding: 20rpx 24rpx;
}
.cat-item {
flex-shrink: 0;
padding: 0 32rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 30rpx;
font-size: 26rpx;
color: #3C3C43;
background: #F2F2F7;
margin-right: 16rpx;
}
.cat-item.active {
background: #007AFF;
color: #fff;
}
.select-body {
flex: 1;
height: 0;
}
.grid {
display: flex;
flex-wrap: wrap;
padding: 24rpx;
gap: 24rpx;
}
.grid-item {
width: calc(50% - 12rpx);
box-sizing: border-box;
}
.sk-card {
height: 360rpx;
border-radius: 32rpx;
}
.select-footer {
flex-shrink: 0;
background: #fff;
border-top: 1rpx solid #E5E5EA;
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 32rpx;
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
}
.sf-count {
font-size: 30rpx;
font-weight: 600;
color: #1C1C1E;
}
.sf-confirm {
width: 200rpx;
height: 80rpx;
font-size: 28rpx;
}
/* 成功视图 */
.success-view {
flex: 1;
padding: 48rpx 24rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.success-icon {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: #34C759;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
}
.success-icon .icon {
width: 64rpx;
height: 64rpx;
}
.success-title {
font-size: 34rpx;
font-weight: 600;
color: #000;
margin-top: 24rpx;
}
.preview-card {
width: 100%;
background: #fff;
border-radius: 32rpx;
margin-top: 40rpx;
padding: 32rpx;
box-sizing: border-box;
}
.preview-top {
display: flex;
align-items: center;
}
.avatar {
width: 64rpx;
height: 64rpx;
border-radius: 50%;
background: #F2F2F7;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
color: #C7C7CC;
margin-right: 16rpx;
}
.avatar-img {
width: 100%;
height: 100%;
}
.avatar-placeholder {
width: 40rpx;
height: 40rpx;
}
.preview-name {
font-size: 26rpx;
color: #000;
}
.preview-body {
height: 320rpx;
background: #F8F8FA;
border-radius: 24rpx;
margin-top: 24rpx;
display: flex;
align-items: center;
justify-content: center;
color: #C7C7CC;
}
.preview-body .icon {
width: 96rpx;
height: 96rpx;
}
.preview-btn {
margin-top: 24rpx;
height: 88rpx;
border-radius: 24rpx;
background: #007AFF;
color: #fff;
font-size: 28rpx;
display: flex;
align-items: center;
justify-content: center;
}
.success-btns {
width: 100%;
display: flex;
gap: 20rpx;
margin-top: 40rpx;
}
.success-btns .btn {
flex: 1;
}