Files
danyang-match/miniapp/components/photo-uploader/index.js
T

59 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-09-09 22:05:00 +08:00
/**
* PhotoUploader 照片上传器(规范 §22, §115 PHOTO_STATUS)
*
* 多图上传 + 审核状态展示 + 排序 + 删除。
* 不变量(AGENTS.md 第 8 条):本组件不接收身份证号/手机号等敏感字段,
* 仅处理生活照 URL(已上传至 OSS 后由 Profile.photos 引用)。
* 上传凭证由调用方通过 profileService.requestUploadToken 获取后注入。
*
* 用法:
* <ui-photo-uploader photos="{{photos}}" max="{{6}}"
* bind:add="onAddPhoto" bind:remove="onRemovePhoto" bind:tap="onPreviewPhoto" />
*/
Component({
options: { addGlobalClass: true },
properties: {
photos: { type: Array, value: [] },
max: { type: Number, value: 6 },
readonly: { type: Boolean, value: false },
// 是否显示审核状态徽标
showReviewStatus: { type: Boolean, value: true },
},
data: {
photoStatusKindMap: {
local: 'warning',
uploading: 'info',
uploaded: 'success',
failed: 'danger',
review_pending: 'warning',
},
photoStatusLabelMap: {
local: '本地',
uploading: '上传中',
uploaded: '已上传',
failed: '失败',
review_pending: '审核中',
},
},
methods: {
onAdd() {
if (this.data.readonly) return;
if (this.data.photos.length >= this.data.max) return;
this.triggerEvent('add', {});
},
onRemove(e) {
if (this.data.readonly) return;
const { index } = e.currentTarget.dataset;
this.triggerEvent('remove', { index });
},
onTap(e) {
const { index } = e.currentTarget.dataset;
this.triggerEvent('tap', { index });
},
onRetry(e) {
const { index } = e.currentTarget.dataset;
this.triggerEvent('retry', { index });
},
},
});