01 / Overview
cu-shop-review-form
发布评价表单:商品卡回显订单商品,星级、文字(带计数)、选图与匿名勾选组成表单主体;点提交时按 `validateReview` 就地校验并回显错误,提交载荷同时带提交数据、校验结论与错误清单,真实上传与接口调用交给宿主。
商品与导购
11 条 props
7 事件
已实现
02 / Demo
实时预览
演示页:/pages/shop/review-form。右侧的预览由站点脚本把 H5 演示页装进 iframe;数据与交互在演示页内操作,不在此处留静态截图。
依赖
- 基础件:
cu-rate、cu-textarea、cu-upload - Shop 共享件:
locale/index.uts(cuShopT/cuShopTf)、utils/review.uts(validateReview) - 实体:
ShopOrderItem(字段见docs/01-交付与接入/电商数据字典.md)
03 / Props · Events · Slots
全量契约
props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| show | 是否渲染表单;关闭只发 update:show(false),受控 | boolean | false |
| orderItem | 订单商品(ShopOrderItem);为空对象时不显示商品卡 | Object | {} |
| score | 评分 1–5,受控;改动发 update:score | number | 5 |
| maxImages | 图片上限,同时约束 cu-upload 与 validateReview | number | 9 |
| maxLength | 文字上限,同时约束 cu-textarea 与 validateReview | number | 500 |
| anonymous | 匿名评价,受控;点击发 update:anonymous | boolean | false |
| submitting | 提交中;为 true 时提交按钮禁用并显示「提交中…」 | boolean | false |
| customStyle | 根节点自定义样式 | Object | {} |
| customClass | 根节点自定义类名 | string | '' |
| url | 透传字段,本件未接线 | string | '' |
| linkType | 透传字段,本件未接线 | string | 'navigateTo' |
events
| 事件 | 说明 | 载荷 |
|---|---|---|
| @update:show | 点关闭时发 false | boolean |
| @update:score | 星级改动 | number |
| @update:anonymous | 匿名勾选切换 | boolean |
| @submit | 点提交;data 含 orderId / goodsId / score / content / images / anonymous;errors 为 { field, code }[] | { data, valid, errors } |
| @upload | 选图后立即发;file 为 cu-upload 的 afterRead 载荷数组 | { file } |
| @deleteImage | 删除第 index 张图片 | { index } |
| @change | field 为 score / content / anonymous | { field, value } |
slots
| 插槽 | 作用域 | 说明 |
|---|---|---|
| header | 无 | 标题与商品卡之间的附加区 |
| before-submit | 无 | 匿名行与提交按钮之间 |
| footer | 无 | 提交按钮之后的附加区 |
04 / Example
代码示例
<cu-shop-review-form :show="show" :orderItem="orderItem" :score="score" :anonymous="anonymous"
:submitting="submitting" @update:show="show = $event" @update:score="score = $event"
@update:anonymous="anonymous = $event" @submit="onSubmit" @upload="onUpload" @deleteImage="onDelete" />
05 / Notes
注意事项
校验走 utils/review.uts 的 validateReview,5 个错误码:scoreInvalid / contentTooShort / contentRequiredForLowScore / imagesTooMany / contentTooLong;错误只在点过一次提交后显示
contentTooShort 为文字少于 5 字;contentRequiredForLowScore 为 1–2 星时文字必填,两者按 content 是否为空互斥
图片列表是组件内部状态(props 无 images 入口):选图结果立即显示,submit 载荷带本地路径,真实上传由宿主在 upload 事件里完成
submit 无论校验是否通过都发,由宿主按 valid 决定是否落库或提示
submitting=true 时提交点击被拦,不发 submit
不请求接口、不持久化、不弹 toast、不调剪贴板
安装 colorui-shop 全量包与安装任意 cu-shop-* 单件包二选一,不要同时装。单件包的前提是已安装完整 colorui-x。