微信小程序前后端开发(含150+API接口一键前后端对接生成)
下载地址
https://www.zhengdianxue.com/wp-content/uploads/skills/org-w6z3mi51--miniprogram-general-dev.zip将提示词发送给你的 AI 安装该 skills
请根据 https://skillhub.cn/install/skillhub.md,安装 @org-w6z3mi51/miniprogram-general-dev。生成通用微信小程序前端代码(不限于商城),覆盖账号、资讯、分销、营销、会员、地址、商品、订单等全部业务。内置 dev.ushopun.com OpenAPI(/api/v2 前缀,camelCase 返回体 code/content/data,guid/token/shopId 鉴权)完整接口对接与页面展示规范,含每个方法的调用示例。
当用户需要开发非商城或通用业务微信小程序时调用此Skill。商城场景请使用 xiaochengxushangcheng(miniprogram-mall-urshop-official)。
阅读全文 (展开查看完整说明)
概述
通用微信小程序前端开发规范
本 Skill 的定位:通用微信小程序前端开发工具,不限于商城。商城只是其中一种可选业务分支,同样支持资讯内容、分销代理、营销活动、会员资产、表单收集、签到任务、订单交易等多元化小程序业务。
后端数据源:
dev.ushopun.com(优社云 OpenAPI)。接口前缀统一为/api/v2,返回体统一为{ code, content, data, success }(camelCase),鉴权通过请求头guid(用户 GUID)+authorization(JWT Token)+shopId(店铺/自提点)完成。与商城 Skill 的区别:本 Skill 强调「通用」与「模块可裁剪」,商品/购物车/订单等交易模块为可选,剔除后即可生成纯资讯、纯分销、纯会员、纯表单小程序。如需完整商城,请使用同级
xiaochengxushangcheng(miniprogram-mall-urshop-official)。连接器 ApiToken(Agent 前置授权):本 Skill 被 workbuddy / trae 等 AI Agent 使用时,Agent 需先引导用户到
ushopun.com登录账号 → 在后台/控制台创建连接器并复制「连接器 ApiToken」→ 提供给 Agent,用于读取接口文档、验证字段或联调。该凭证为租户级敏感凭证,禁止写死进生成的小程序源码,仅通过配置占位符/环境变量承载。
技术栈
- 框架:原生微信小程序(不使用 Taro / uni-app)
- API 层:自封装请求模块(
api/api.js+api/conf.js) - 鉴权:Header 携带
guid(用户标识)+authorization(JWT Token)+shopId(店铺/自提点) - 样式:WXSS,尺寸单位
rpx(750rpx = 屏幕宽度),图标用 iconfont - 富文本:可选 wxParse 组件
项目目录结构(通用)
miniProgram/
├── api/
│ ├── conf.js # 所有 API 端点常量(统一管理,禁止硬编码 URL)
│ └── api.js # HTTP 请求封装(自动注入 guid/token/shopId)
├── pages/ # 业务页面(每页 .js/.wxml/.wxss/.json 四件套)
│ ├── index/ # 通用首页(轮播 + 自定义业务入口)
│ ├── login/ # 账号登录注册页(通用)
│ ├── member/ # 通用个人中心
│ ├── address/ # 地址管理(交易类通用)
│ ├── blog/ # 资讯文章(内容类)
│ ├── agent-center/ # 分销代理中心
│ ├── coupon/ # 优惠券中心
│ ├── wallet/ # 钱包资产中心
│ ├── form-page/ # 通用自定义表单收集页
│ ├── cart/ # 购物车(电商可选)
│ └── order/ # 订单列表/详情(交易可选)
├── components/ # 通用可复用组件(非商城专属)
├── utils/ # 工具函数(时间格式化、脱敏、缓存等)
├── images/ # 静态图片资源
├── data/ # 静态数据(省市区、字典等)
├── app.js # 全局入口(globalData + onLaunch)
├── app.json # 应用配置(页面路由、TabBar、窗口样式)
└── app.wxss # 全局样式入口一、API 对接规范
1.1 基础配置
// app.js globalData
globalData: {
host: 'https://dev.ushopun.com', // 后端 API 基础地址(不含 /api/v2)
token: '', // 登录后写入的 JWT Token
guid: '', // 登录后写入的用户 GUID
customer: null // 当前用户信息
}
conf.js中的端点不含/api/v2前缀,由api.js通过${host}/api/v2${url}拼接出完整地址。
1.2 统一返回结构(camelCase)
{
"code": 200,
"content": "请求成功!",
"data": { },
"success": true
}| code | 含义 | 前端处理 |
|---|---|---|
| 200 | 成功,业务数据在 data | 取 data 渲染 |
| 250 | 业务警告,content 为提示语 | wx.showToast({ title: content, icon: 'none' }) |
| 301 | 跳转新地址,content 为 URL | wx.redirectTo 或 wx.navigateTo |
| 400 | 错误请求 | 提示 content |
| 401 | 未授权/未登录 | 清 token 跳登录页 |
| 403 | 模块未开启(module not open) | 提示「功能未开启」 |
| 404 | 找不到(not found) | 提示「数据不存在」 |
| 220 | 升级/需审核(is's update) | 引导用户申请升级 |
| 350 | 未批准(disapproved) | 提示「审核未通过」 |
特殊:
/account/checkaccount接口的code为1(账号可用)/0(已存在),非标准码,需单独处理。
1.3 鉴权机制
| Header | 说明 | 来源 |
|---|---|---|
guid | 用户 GUID | 登录后由 JWT 解析,或注册/登录接口返回 |
authorization | JWT Token | /account/login 返回的 token |
shopId | 店铺/自提点 ID | 用户选择门店后本地缓存(adress.id) |
鉴权标记:
| 标记 | 含义 |
|---|---|
[ApiAuthorize] | 必须登录(header authorization 为有效 JWT),失败返回 { code: 401 } |
[ApiAuthorize(false)] | 匿名可访问,但会尝试解析 JWT 注入 guid |
| 无标记 | 公开接口,无需登录 |
1.4 api.js — 请求封装(核心)
// api/api.js
const app = getApp()
const request = (url, options) => {
return new Promise((resolve, reject) => {
const fullUrl = `${app.globalData.host}/api/v2${url}`
wx.request({
url: fullUrl,
method: options.method,
data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
header: {
'Content-Type': 'application/json; charset=UTF-8',
guid: wx.getStorageSync('guid') || app.globalData.guid || '',
authorization: wx.getStorageSync('token') || app.globalData.token || '',
shopId: (wx.getStorageSync('adress') && wx.getStorageSync('adress').id) || 0
},
success(request) {
const res = request.data || {}
if (res.code === 200) {
resolve(res) // 成功,调用方取 res.data
} else if (res.code === 401) {
wx.removeStorageSync('token')
wx.removeStorageSync('guid')
wx.navigateTo({ url: '/pages/login/login' })
reject(res)
} else {
reject(res) // 250 业务警告 / 404 等,调用方用 content 提示
}
},
fail(error) {
wx.showToast({ title: '网络异常,请稍后重试', icon: 'none' })
reject(error)
}
})
})
}
const get = (url, options = {}) => request(url, { method: 'GET', data: options })
const post = (url, options) => request(url, { method: 'POST', data: options })
const put = (url, options) => request(url, { method: 'PUT', data: options })
const remove = (url, options) => request(url, { method: 'DELETE', data: options })
module.exports = { get, post, put, remove }1.5 页面调用模式
import api from '../../api/api'
import { productId, orderList } from '../../api/conf'
Page({
data: { model: {}, list: [] },
onLoad(options) {
// GET 调用
api.get(productId, { id: options.id })
.then(res => this.setData({ model: res.data }))
.catch(err => wx.showToast({ title: err.content || '加载失败', icon: 'none' }))
// POST 调用
api.post(orderList, { orderstatus: 0, page: 1 })
.then(res => this.setData({ list: res.data.items }))
.catch(err => wx.showToast({ title: err.content || '加载失败', icon: 'none' }))
}
})二、完整接口清单(按业务模块,含每个方法的调用方式)
下表均来自
dev.ushopun.com真实后端(openapi.json为接口权威文档),路径前缀统一/api/v2。「鉴权」列:✔= 必须登录([ApiAuthorize]),○= 匿名可访问([ApiAuthorize(false)]),-= 公开。所有接口统一用api.get(conf.xxx, params)/api.post(conf.xxx, data)调用,返回体统一{ code, content, data, success },业务数据在data。
2.1 通用模块 CommonController(前缀 /api/v2/common)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
banner | GET | /banner | name: string, picsize: int=50 | MoBannerZone | – |
referrerinfo | GET | /referrerinfo | code: string | MoReferrerInfo | – |
referrerauto | GET | /referrerauto | – | MoReferrerInfo | ✔ |
forminfo | GET | /forminfo | name: string | MoFormInfo | – |
formsubmit | POST | /formsubmit | name: string, model: MoFormSubmit | int | – |
getform | POST | /getform | id: long | MoFormData | – |
levels | GET | /levels | – | List<MoAllLevel> | – |
allprovinces | POST | /allprovinces | – | List<MoProvinces> | – |
uploadpicture | POST | /uploadpicture | upload: MoBase64 | MoPictureResponse | ✔ |
picturepost | POST | /picturepost | form: IFormCollection | MoPictureResponse | ✔ |
producttype | GET | /producttype | – | List<KeyValueStrModel> | – |
orderstatus | GET | /orderstatus | – | List<KeyValueStrModel> | – |
ordertype | GET | /ordertype | – | List<KeyValueStrModel> | – |
returnreasons | GET | /returnreasons | – | List<string> | – |
returnactions | GET | /returnactions | – | List<string> | – |
requesttypes | GET | /requesttypes | – | List<KeyValueStrModel> | – |
paymentstatus | GET | /paymentstatus | – | List<KeyValueStrModel> | – |
shippingstatus | GET | /shippingstatus | – | List<KeyValueStrModel> | – |
pluginscenes | GET | /pluginscenes | – | List<KeyValueStrModel> | – |
customattrtype | GET | /customattrtype | – | List<KeyValueStrModel> | – |
messagetype | GET | /messagetype | – | List<KeyValueStrModel> | – |
调用示例:
api.get(banner, { name: 'homehotbanner' }).then(res => this.setData({ banners: res.data.items }))
api.post(allprovinces).then(res => this.setData({ provinces: res.data }))
api.post(uploadpicture, { upload: { base64: 'data:image/png;base64,...' } })
api.post(formsubmit, { name: 'consult', model: { phone: '138...', content: '...' } })2.2 账号模块 AccountController(前缀 /api/v2/account)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
login | POST | /login | model: MoLogin(name, password) | { guid, token, nickname } | – |
online | GET | /online | guid(URL 追加) | int(1已注册/0未注册) | ○ |
logout | GET | /logout | – | – | – |
register | POST | /register | model: MoRegister(phone, password, token, inviteCode) | – | – |
sendsmsforregister | POST | /sendsmsforregister | phone: string | – | – |
chanagepwd | POST | /chanagepwd | model: MoChangePassword | – | ○ |
sendsmsforfindpwd | POST | /sendsmsforfindpwd | phone: string | – | – |
pwdset | POST | /pwdset | model: MoPasswordRecovery | – | – |
checkaccount | GET | /checkaccount | account: string | code=1可用/0不可用 | – |
登录对接流程:
// 1. 账号密码登录
api.post(login, { model: { name: '13800138000', password: '123456' } })
.then(res => {
// res.data = { guid, token, nickname }
wx.setStorageSync('guid', res.data.guid)
wx.setStorageSync('token', res.data.token)
})
// 2. 注册(先发验证码)
api.post(sendsmsforregister, { phone: '13800138000' })
api.post(register, { model: { phone: '13800138000', password: '123456', token: '短信验证码', inviteCode: '邀请码' } })
// 3. 检查账号可用性(特殊:code=1 可用)
api.get(checkaccount, { account: '13800138000' }).then(res => {
if (res.code === 1) { /* 可用 */ } else { /* 已存在 */ }
})2.3 用户模块 CustomerController(前缀 /api/v2/customer,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
getcustomer | GET | /get | – | MoInfo |
customerinfo | GET | /info | – | MoCustomerInfo |
customersubmit | POST | /submit | model: MoCustomerRequest | – |
customerpoints | GET | /points | page: int=1, size: int=12 | MoPoints |
uploadavatar | POST | /uploadavatar | uploadAvatar: MoUploadAvatar | MoAvatar |
checkshop | POST | /checkshop | id: long | – |
myinvitecode | GET | /myinvitecode | – | MoInviteCode |
myinvitees | GET | /myinvitees | page: int=1, size: int=12 | MoInvitees |
调用示例:
api.get(getcustomer).then(res => this.setData({ customer: res.data }))
api.get(myinvitecode).then(res => this.setData({ inviteCode: res.data.code }))
api.get(myinvitees, { page: 1, size: 12 }).then(res => this.setData({ invitees: res.data }))2.4 地址模块 AddressController(前缀 /api/v2/address,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
addressList | GET | /list | – | List<MoAddress> |
addressdelete | POST | /delete | addressId: long | – |
addressadd | POST | /add | model: MoAddressEdit | – |
addressdefault | POST | /default | addressId: long | – |
addressedit | POST | /edit | addressId: long, model: MoAddressEdit | – |
调用示例:
api.get(addressList).then(res => this.setData({ list: res.data }))
api.post(addressadd, { model: { name: '张三', phone: '138...', provinceName: '广东省', address: '...' } })
api.post(addressdelete, { addressId: 123 })2.5 消息模块 PMController(前缀 /api/v2/pm,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
pmmarkRead | POST | /markRead | msgIds: IList<long> | – |
pmsend | POST | /send | model: MoSendMessage | – |
pmlist | GET | /list | type: int=0, page: int=1, size: int=12 | MoMessageList |
pmdelpm | GET | /delpm | msgId: long | – |
2.6 内容资讯模块(Topic / News / Blog)
TopicController(/api/v2/topic)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
topiclist | GET | /list | page: int=1, size: int=12 | MoTopicList |
topicdetail | GET | /detail | systemName: string | MoTopic(含富文本 body) |
NewsController(/api/v2/news)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
newslist | GET | /list | page: int=1, size: int=12 | MoNewsList |
newsitem | GET | /item | id: long | MoNews |
BlogController(/api/v2/blog)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
bloglist | GET | /list | customerId: long, page: int=1, size: int=12 | MoBlogList | – |
blogitem | GET | /item | id: long | MoBlog | – |
blogpost | POST | /post | model: MoBlogPost | MoBlog | ✔ |
blogcategories | GET | /categories | – | List<MoPaperCategory> | – |
blogpapers | GET | /papers | categoryId: long | List<MoPaper> | – |
调用示例:
api.get(topicdetail, { systemName: 'about' }).then(res => this.setData({ body: res.data.body })) // 富文本
api.get(newslist, { page: 1, size: 12 }).then(res => this.setData({ news: res.data }))
api.post(blogpost, { model: { title: '...', content: '...' } })2.7 商品模块 ProductController(前缀 /api/v2/product)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
featuredbycid | GET | /featuredbycid | cid: long, count: int, picsize: int?, specshow/tagshow/fullshow: bool=false | List<MoProductOverview> | – |
homePro | GET | /homeproducts | picsize: int?, specshow/tagshow/fullshow: bool=false | List<MoProductOverview> | – |
specialproducts | GET | /specialproducts | count: int, picsize: int?, … | List<MoProductOverview> | – |
alsopurchased | GET | /alsopurchased | pId: long, count: int, picsize: int?, … | List<MoProductOverview> | – |
taglist | GET | /taglist | count: int=MaxValue | List<MoProductTag> | – |
productbytag | GET | /getbytag | tagName: string, count: int, picsize: int?, … | List<MoProductOverview> | – |
getproductattr | GET | /getproductattr | pId: long | MoProductAttrList | – |
getproductspec | GET | /getproductspec | pId: long | List<MoProductSpec> | – |
productId | GET | /getbyid | id: long | MoProduct | – |
productbysku | GET | /getbysku | sku: string | MoProduct | – |
productpost | POST | /post | mo: MoProductRequest | long | ✔ |
调用示例:
api.get(productId, { id: 123 }).then(res => this.setData({ product: res.data }))
api.get(homePro, { picsize: 200 }).then(res => this.setData({ products: res.data }))
api.get(getproductattr, { pId: 123 }).then(res => this.setData({ attrs: res.data.attrs, tables: res.data.tables }))2.8 分类模块 CategoryController(前缀 /api/v2/category)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
homecategories | GET | /homecategories | – | List<MoCategory> |
categoryget | GET | /get | id: long | MoCategory |
category | GET | /sublist | loadsub: bool=false, catId: long=0 | List<MoCategoryList> |
2.9 品牌模块 BrandController(前缀 /api/v2/brand)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
brandlist | GET | /list | name: string="", picsize: int?, page: int=1, size: int=12 | MoBrandList |
brandfeaturelist | GET | /featurelist | picsize: int? | List<MoSimpleBrand> |
brandget | GET | /get | mid: long, picsize: int? | MoSimpleBrand |
brandfeaturedproducts | GET | /featuredproducts | mid: long, count: int, … | List<MoProductOverview> |
2.10 搜索模块 SearchController(前缀 /api/v2/search)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
search | GET | /find | q: string, sid: bool=false, mid: long=0, cid: long=0, minPrice: decimal?, maxPrice: decimal?, page: int=1, size: int=12, orderBy: int=0, specshow: bool=false, tagshow: bool=false, producttype: int=-1 | MoSearch |
searCate | GET | /findbycid | cid: long, mid: long=0, tagName: string="", minPrice/maxPrice, page: int=1, size: int=12, orderBy: int=0, … | MoCategory |
findbymid | GET | /findbymid | mid: long=0, cid: long=0, tagName, minPrice/maxPrice, page, size, orderBy, … | MoBrand |
findbyoid | GET | /findbyoid | oid: long, mid, cid, tagName, minPrice/maxPrice, page, size, orderBy, … | MoCustomerSearch |
hotcategory | GET | /hotcategory | – | List<KeyValueModel> |
hotsearch | GET | /hot | – | List<string> |
searchhistory | GET | /history | – | List<string> |
调用示例:
api.get(search, { q: '关键词', page: 1, size: 12 }).then(res => this.setData({ result: res.data }))
api.get(searCate, { cid: 10, page: 1, size: 12 }).then(res => this.setData({ items: res.data.items }))
api.get(hotsearch).then(res => this.setData({ hot: res.data }))2.11 收藏模块 FavoritesController(前缀 /api/v2/favorites,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
favoriteslist | GET | /list | picsize: int?=200, specshow/tagshow/fullshow, page: int=1, size: int=12 | MoFavoritesList |
favoritessubmit | POST | /submit | model: MoFavoritesRequest | – |
favoritesremove | POST | /remove | id: long | – |
recentproductlist | GET | /list-recentproduct | 同上 | MoFavoritesList |
recentproductsubmit | POST | /submit-recentproduct | model: MoFavoritesRequest | – |
recentproductremove | POST | /remove-recentproduct | id: long | – |
2.12 阶梯价模块 TierPriceController(前缀 /api/v2/tierprice,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
tierprices | GET | /tierprices | productId: long | List<MoTierPrice> |
2.13 购物车模块 ShoppingCartController(前缀 /api/v2/shoppingcart,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
getShoppingcart | GET | /get | – | MoCart |
cartCount | GET | /count | – | int |
producttocart | POST | /producttocart | model: MoAddCart | long |
productstocart | POST | /productstocart | model: IList<MoAddCart> | – |
producttocheckout | POST | /producttocheckout | model: MoAddCart | long |
cartallselected | POST | /cartallselected | selected: bool | – |
updatecartitem | POST | /updatecartitem | item: MoUpdateCart | MoUpdateCart |
removecartitem | POST | /removecartitem | id: long | – |
removecart | POST | /removecart | – | – |
wishlist | GET | /wishlist | page: int=1, size: int=12 | MoCart |
removewishlistitem | POST | /removewishlistitem | id: long | – |
iscollect | POST | /iscollect | pid: long | int |
towishlist | POST | /towishlist | model: MoAddCart | long |
tocheckout | POST | /tocheckout | – | – |
调用示例:
api.get(getShoppingcart).then(res => this.setData({ cart: res.data }))
api.post(producttocart, { model: { pId: 123, qty: 1, attrValue: 'combination_1_2' } })
api.post(updatecartitem, { item: { id: 1, quantity: 2, selected: true } })
api.get(cartCount).then(res => this.setData({ count: res.data }))2.14 结算模块 CheckoutController(前缀 /api/v2/checkout,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
checkminsubtotal | GET | /checkminsubtotal | – | – |
getcheckout | GET | /get | – | MoCheckout |
getpaymentmethod | GET | /getpaymentmethod | – | List<MoPaymentMethod> |
getshippingmethod | GET | /getshippingmethod | – | List<MoShippingMethod> |
submitcheckout | POST | /submit | request: MoCheckoutRequest | MoCheckoutResponse |
quicksubmit | POST | /quicksubmit | request: MoQuickOrderRequest | MoQuickOrderResponse |
调用示例:
api.get(getcheckout).then(res => this.setData({ checkout: res.data }))
api.post(submitcheckout, { request: { addressId: 1, paymentMethod: 'weixin', remark: '...', couponId: 0 } })
.then(res => { /* res.data 含订单信息 */ })2.15 订单模块 OrderController(前缀 /api/v2/order,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
returnrequests | GET | /returnrequests | typeId: long=0, page: int=1, size: int=12 | MoReturnList |
returnpost | POST | /returnpost | moReturn: MoReturn | – |
orderList | GET | /list | startTime: DateTime?, endTime: DateTime?, orderstatus: int=0, page: int=1, size: int=12 | MoOrderList |
orderDetail | GET | /detail | oid: long | MoOrderDetail |
orderconfirm | POST | /complete | mo: MoOrderCancel | – |
orderdeliver | POST | /deliver | mo: MoOrderDeliver | – |
ordercancel | POST | /cancel | mo: MoOrderCancel | – |
调用示例:
api.get(orderList, { orderstatus: 0, page: 1, size: 12 }).then(res => this.setData({ orders: res.data.items }))
api.get(orderDetail, { oid: 123 }).then(res => this.setData({ order: res.data }))
api.post(ordercancel, { mo: { orderGuid: '...' } })
api.post(orderconfirm, { mo: { orderGuid: '...' } })2.16 物流模块(Shipping / Kdniao)
ShippingController(/api/v2/shipping)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
pickuplist | GET | /pickuplist | – | List<MoPickupPoint> | – |
shopsearch | GET | /shopsearch | keyword: string, lat: decimal?, lng: decimal?, page: int=1, size: int=20 | object | – |
shipments | GET | /shipments | oid: long | MoShipmentBrief | ✔ |
KdniaoController(/api/v2/kdniao)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
expresskdniaoapiurl | GET | /expresskdniaoapiurl | company: string, number: string | MoExpressInfo | ✔ |
2.17 支付模块 PlugInController(前缀 /api/v2/plugin)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
weixinwaploginenabled | GET | /weixinwaploginenabled | – | – | – |
weixinwaploginurl | GET | /weixinwaploginurl | callback: string | object | ✔ |
weixinopenloginenabled | GET | /weixinopenloginenabled | – | – | – |
weixinopenlogin | GET | /weixinopenlogin | code: string, state: string, encryptedData: string="", iv: string="" | TokenEntity | – |
weixinopenphonenumber | GET | /weixinopenphonenumber | code: string, encryptedData: string, iv: string | PhoneEntity | – |
weixinwappaymentenabled | GET | /weixinwappaymentenabled | – | – | – |
weixinwapaymenturl | GET | /weixinwapaymenturl | orderId: long, paytype: string | MoPayment | ✔ |
weixinopenpaymentenabled | GET | /weixinopenpaymentenabled | – | – | – |
weixinopenpaymenturl | GET | /weixinopenpaymenturl | orderId: long, paytype: string | MoPayment | ✔ |
alipaywappaymentenabled | GET | /alipaywappaymentenabled | – | – | – |
alipaywappaymenturl | GET | /alipaywappaymenturl | orderId: long, paytype: string | MoPayment | ✔ |
支付对接流程:
api.get(weixinopenpaymenturl, { orderId: 123, paytype: 'Order' }).then(res => {
const p = res.data // MoPayment 含支付参数
wx.requestPayment({
timeStamp: p.timeStamp, nonceStr: p.nonceStr,
package: p.package, signType: p.signType, paySign: p.paySign,
success() { /* 支付成功 */ },
fail() { /* 支付失败 */ }
})
})2.18 钱包模块 WalletController(前缀 /api/v2/wallet,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
wallet | GET | /get | – | MoWallet |
walletrecharge | POST | /recharge | model: MoRechargePost | MoRecharge |
walletrechargelist | POST | /rechargelist | ps: int=0, page: int=1, size: int=10 | MoRechargeList |
walletexchange | POST | /exchange | model: MoExchange | MoExchange |
walletexchangelist | POST | /exchangelist | page: int, size: int | MoExchangeList |
walletcardexchange | POST | /cardexchange | moCard: MoCardExchange | – |
walletrecordlist | GET | /recordlist | page: int, size: int | MoWalletRecordList |
调用示例:
api.get(wallet).then(res => this.setData({ wallet: res.data }))
api.post(walletrecharge, { model: { amount: 100 } }).then(res => this.setData({ recharge: res.data }))
api.get(walletrecordlist, { page: 1, size: 12 }).then(res => this.setData({ records: res.data.items }))2.19 积分兑换模块 PointsExchangeController(前缀 /api/v2/pointsexchange,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
pointsexchangelist | GET | /list | – | object |
pointsexchange | POST | /exchange | ruleId: long | object |
2.20 充值卡模块(RechargeCard / RechargeCardItem)
RechargeCardController(/api/v2/rechargecard)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
rechargecardlist | GET | /list | page: int=1, size: int=12 | MoRechargeCardList |
rechargecarditem | GET | /item | id: long | MoRechargeCard |
RechargeCardItemController(/api/v2/rechargecarditem)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
rechargecarditemlist | GET | /list | cardId: long, page: int=1, size: int=12 | MoRechargeCardItemList |
rechargecarditemget | GET | /item | id: long | MoRechargeCardItem |
2.21 优惠券模块 CouponController(前缀 /api/v2/coupon)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
couponshow | POST | /show | request: MoCouponPost | List<MoCoupon> | – |
couponlist | GET | /couponlist | type: int, page: int=1, size: int=12 | MoCouponList | ✔ |
coupon_center | GET | /center | page: int=1, size: int=12 | MoCouponList | ✔ |
getcoupon | POST | /getcoupon | request: MoCouponPost | – | ✔ |
usablecoupon | GET | /usablecoupon | orderTotal: decimal | List<MoCoupon> | ✔ |
调用示例:
api.get(coupon_center, { page: 1, size: 12 }).then(res => this.setData({ coupons: res.data }))
api.post(getcoupon, { request: { code: 'xxx' } }).then(() => wx.showToast({ title: '领取成功' }))
api.get(usablecoupon, { orderTotal: 100 }).then(res => this.setData({ usable: res.data }))2.22 秒杀模块 SeckillController(前缀 /api/v2/seckill)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
seckillstatus | GET | /status | – | MoSeckillStatus |
seckilllist | GET | /list | page: int=1, size: int=10 | List<MoSeckillProduct> |
seckilldetail | GET | /{id} | id: long | MoSeckillDetail |
2.23 拼团模块 PinTuanController(前缀 /api/v2/pintuan)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
pintuanproduct | GET | /product | pId: long, ptcId: long=0 | MoPinTuanProduct | ✔ |
pintuangroup | GET | /group | – | MoPinTuan | – |
pintuankaituan | POST | /kaituan | kaituan: MoKaiTuan | object | ✔ |
2.24 签到模块 SignInController(前缀 /api/v2/signin,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
signinstatus | GET | /status | – | SignInStatusResponse |
signin | POST | /signin | – | SignInResultResponse |
signinrecords | GET | /records | page: int=1, size: int=10 | MoSignInRecords |
signincalendar | GET | /calendar | year: int?, month: int? | MoSignInCalendar |
2.25 任务模块 TaskController(前缀 /api/v2/task,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
tasklist | GET | /list | – | object |
taskclaim | POST | /claim | taskRecordId: long | object |
taskunclaimed | GET | /unclaimed | – | object |
2.26 分享模块 ShareController(前缀 /api/v2/share,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
sharereward | POST | /reward | – | MoShareReward |
2.27 预售模块 PreOrderController(前缀 /api/v2/preorder,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
preorderpayrest | POST | /pay-rest | orderId: long, paymentMethod: string | MoPayRestResult |
preorderrestinfo | GET | /rest-info | orderId: long | MoPreOrderRest |
2.28 代理模块 AgentController(前缀 /api/v2/agents,类级 ✔)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
agentupgrade | GET | /upgrade | – | code=220 需审核 |
agentmyinfo | GET | /myinfo | – | MyAgentInfo |
agentspostinfo | POST | /postinfo | moPostInfo: MoPostInfo | – |
agentmysummary | GET | /mysummary | – | MoBonusSummary |
agentmyusers | GET | /myusers | page: int=1, size: int=12 | MoInvitees |
agentmyorders | GET | /myorders | page: int=1, size: int=12 | MoAgentOrder |
agentmybonus | GET | /mybonus | page: int=1, size: int=12 | MoAgentBonus |
调用示例:
api.get(agentmyinfo).then(res => this.setData({ agent: res.data }))
api.get(agentupgrade).then(res => {
if (res.code === 200) { /* 已代理 */ }
else if (res.code === 220) { /* 需申请,弹出申请表单 */ }
})
api.get(agentmybonus, { page: 1, size: 12 }).then(res => this.setData({ bonus: res.data }))2.29 评价模块 ReviewController(前缀 /api/v2/productreview)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 | 鉴权 |
|---|---|---|---|---|---|
commentlist | GET | /list | pId: long, page: int=1, size: int=12 | MoProductReviewList | – |
myreviews | GET | /myreviews | page: int=1, size: int=12 | MoMyReviewList | ✔ |
productreviewing | GET | /productreviewing | page: int=1, size: int=12 | MoOrderNoReviewList | ✔ |
commentsubmit | POST | /submit | model: MoReviewRequest | – | ✔ |
2.30 捆绑商品模块 BundleController(前缀 /api/v2/bundle)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
bundlelist | GET | /list | – | object |
bundledetail | GET | /{id} | id: long | object |
2.31 页面模块 PageController(前缀 /api/v2/page)
| 端点常量 | HTTP | 子路由 | 参数 | 返回 |
|---|---|---|---|---|
pageindex | GET | /index | – | MoBrandList |
pagefeaturelist | GET | /featurelist | picsize: int? | List<MoSimpleBrand> |
pageget | GET | /get | mid: long, picsize: int? | MoSimpleBrand |
pagefeaturedproducts | GET | /featuredproducts | mid: long, count: int, … | List<MoProductOverview> |
三、完整 conf.js 端点常量清单
所有端点均不含
/api/v2前缀(由api.js拼接),直接复制即可对接全部后端接口。
// ============ 通用 Common ============
const banner = '/common/banner'
const referrerinfo = '/common/referrerinfo'
const referrerauto = '/common/referrerauto'
const forminfo = '/common/forminfo'
const formsubmit = '/common/formsubmit'
const getform = '/common/getform'
const levels = '/common/levels'
const allprovinces = '/common/allprovinces'
const uploadpicture = '/common/uploadpicture'
const picturepost = '/common/picturepost'
const producttype = '/common/producttype'
const orderstatus = '/common/orderstatus'
const ordertype = '/common/ordertype'
const returnreasons = '/common/returnreasons'
const returnactions = '/common/returnactions'
const requesttypes = '/common/requesttypes'
const paymentstatus = '/common/paymentstatus'
const shippingstatus = '/common/shippingstatus'
const pluginscenes = '/common/pluginscenes'
const customattrtype = '/common/customattrtype'
const messagetype = '/common/messagetype'
// ============ 账号 Account ============
const login = '/account/login'
const online = '/account/online'
const logout = '/account/logout'
const register = '/account/register'
const sendsmsforregister = '/account/sendsmsforregister'
const chanagepwd = '/account/chanagepwd'
const sendsmsforfindpwd = '/account/sendsmsforfindpwd'
const pwdset = '/account/pwdset'
const checkaccount = '/account/checkaccount'
// ============ 用户 Customer ============
const getcustomer = '/customer/get'
const customerinfo = '/customer/info'
const customersubmit = '/customer/submit'
const customerpoints = '/customer/points'
const uploadavatar = '/customer/uploadavatar'
const checkshop = '/customer/checkshop'
const myinvitecode = '/customer/myinvitecode'
const myinvitees = '/customer/myinvitees'
// ============ 地址 Address ============
const addressList = '/address/list'
const addressdelete = '/address/delete'
const addressadd = '/address/add'
const addressdefault = '/address/default'
const addressedit = '/address/edit'
// ============ 消息 PM ============
const pmmarkRead = '/pm/markRead'
const pmsend = '/pm/send'
const pmlist = '/pm/list'
const pmdelpm = '/pm/delpm'
// ============ 内容 Topic / News / Blog ============
const topiclist = '/topic/list'
const topicdetail = '/topic/detail'
const newslist = '/news/list'
const newsitem = '/news/item'
const bloglist = '/blog/list'
const blogitem = '/blog/item'
const blogpost = '/blog/post'
const blogcategories = '/blog/categories'
const blogpapers = '/blog/papers'
// ============ 商品 Product ============
const featuredbycid = '/product/featuredbycid'
const homePro = '/product/homeproducts'
const specialproducts = '/product/specialproducts'
const alsopurchased = '/product/alsopurchased'
const taglist = '/product/taglist'
const productbytag = '/product/getbytag'
const getproductattr = '/product/getproductattr'
const getproductspec = '/product/getproductspec'
const productId = '/product/getbyid'
const productbysku = '/product/getbysku'
const productpost = '/product/post'
// ============ 分类 / 品牌 / 搜索 ============
const homecategories = '/category/homecategories'
const categoryget = '/category/get'
const category = '/category/sublist'
const brandlist = '/brand/list'
const brandfeaturelist = '/brand/featurelist'
const brandget = '/brand/get'
const brandfeaturedproducts = '/brand/featuredproducts'
const search = '/search/find'
const searCate = '/search/findbycid'
const findbymid = '/search/findbymid'
const findbyoid = '/search/findbyoid'
const hotcategory = '/search/hotcategory'
const hotsearch = '/search/hot'
const searchhistory = '/search/history'
// ============ 收藏 / 阶梯价 ============
const favoriteslist = '/favorites/list'
const favoritessubmit = '/favorites/submit'
const favoritesremove = '/favorites/remove'
const recentproductlist = '/favorites/list-recentproduct'
const recentproductsubmit = '/favorites/submit-recentproduct'
const recentproductremove = '/favorites/remove-recentproduct'
const tierprices = '/tierprice/tierprices'
// ============ 购物车 ShoppingCart ============
const getShoppingcart = '/shoppingcart/get'
const cartCount = '/shoppingcart/count'
const producttocart = '/shoppingcart/producttocart'
const productstocart = '/shoppingcart/productstocart'
const producttocheckout = '/shoppingcart/producttocheckout'
const cartallselected = '/shoppingcart/cartallselected'
const updatecartitem = '/shoppingcart/updatecartitem'
const removecartitem = '/shoppingcart/removecartitem'
const removecart = '/shoppingcart/removecart'
const wishlist = '/shoppingcart/wishlist'
const removewishlistitem = '/shoppingcart/removewishlistitem'
const iscollect = '/shoppingcart/iscollect'
const towishlist = '/shoppingcart/towishlist'
const tocheckout = '/shoppingcart/tocheckout'
// ============ 结算 Checkout ============
const checkminsubtotal = '/checkout/checkminsubtotal'
const getcheckout = '/checkout/get'
const getpaymentmethod = '/checkout/getpaymentmethod'
const getshippingmethod = '/checkout/getshippingmethod'
const submitcheckout = '/checkout/submit'
const quicksubmit = '/checkout/quicksubmit'
// ============ 订单 Order ============
const returnrequests = '/order/returnrequests'
const returnpost = '/order/returnpost'
const orderList = '/order/list'
const orderDetail = '/order/detail'
const orderconfirm = '/order/complete'
const orderdeliver = '/order/deliver'
const ordercancel = '/order/cancel'
// ============ 物流 Shipping / Kdniao ============
const pickuplist = '/shipping/pickuplist'
const shopsearch = '/shipping/shopsearch'
const shipments = '/shipping/shipments'
const expresskdniaoapiurl = '/kdniao/expresskdniaoapiurl'
// ============ 支付 Plugin ============
const weixinwaploginenabled = '/plugin/weixinwaploginenabled'
const weixinwaploginurl = '/plugin/weixinwaploginurl'
const weixinopenloginenabled = '/plugin/weixinopenloginenabled'
const weixinopenlogin = '/plugin/weixinopenlogin'
const weixinopenphonenumber = '/plugin/weixinopenphonenumber'
const weixinwappaymentenabled = '/plugin/weixinwappaymentenabled'
const weixinwapaymenturl = '/plugin/weixinwapaymenturl'
const weixinopenpaymentenabled = '/plugin/weixinopenpaymentenabled'
const weixinopenpaymenturl = '/plugin/weixinopenpaymenturl'
const alipaywappaymentenabled = '/plugin/alipaywappaymentenabled'
const alipaywappaymenturl = '/plugin/alipaywappaymenturl'
// ============ 钱包 Wallet ============
const wallet = '/wallet/get'
const walletrecharge = '/wallet/recharge'
const walletrechargelist = '/wallet/rechargelist'
const walletexchange = '/wallet/exchange'
const walletexchangelist = '/wallet/exchangelist'
const walletcardexchange = '/wallet/cardexchange'
const walletrecordlist = '/wallet/recordlist'
// ============ 积分 / 充值卡 ============
const pointsexchangelist = '/pointsexchange/list'
const pointsexchange = '/pointsexchange/exchange'
const rechargecardlist = '/rechargecard/list'
const rechargecarditem = '/rechargecard/item'
const rechargecarditemlist = '/rechargecarditem/list'
const rechargecarditemget = '/rechargecarditem/item'
// ============ 优惠券 Coupon ============
const couponshow = '/coupon/show'
const couponlist = '/coupon/couponlist'
const coupon_center = '/coupon/center'
const getcoupon = '/coupon/getcoupon'
const usablecoupon = '/coupon/usablecoupon'
// ============ 秒杀 / 拼团 / 签到 / 任务 / 分享 / 预售 ============
const seckillstatus = '/seckill/status'
const seckilllist = '/seckill/list'
const pintuanproduct = '/pintuan/product'
const pintuangroup = '/pintuan/group'
const pintuankaituan = '/pintuan/kaituan'
const signinstatus = '/signin/status'
const signin = '/signin/signin'
const signinrecords = '/signin/records'
const signincalendar = '/signin/calendar'
const tasklist = '/task/list'
const taskclaim = '/task/claim'
const taskunclaimed = '/task/unclaimed'
const sharereward = '/share/reward'
const preorderpayrest = '/preorder/pay-rest'
const preorderrestinfo = '/preorder/rest-info'
// ============ 代理 Agent ============
const agentupgrade = '/agents/upgrade'
const agentmyinfo = '/agents/myinfo'
const agentspostinfo = '/agents/postinfo'
const agentmysummary = '/agents/mysummary'
const agentmyusers = '/agents/myusers'
const agentmyorders = '/agents/myorders'
const agentmybonus = '/agents/mybonus'
// ============ 评价 Review ============
const commentlist = '/productreview/list'
const myreviews = '/productreview/myreviews'
const productreviewing = '/productreview/productreviewing'
const commentsubmit = '/productreview/submit'
// ============ 捆绑 / 页面 ============
const bundlelist = '/bundle/list'
const pageindex = '/page/index'
const pagefeaturelist = '/page/featurelist'
const pageget = '/page/get'
const pagefeaturedproducts = '/page/featuredproducts'
module.exports = {
// Common
banner, referrerinfo, referrerauto, forminfo, formsubmit, getform, levels,
allprovinces, uploadpicture, picturepost, producttype, orderstatus, ordertype,
returnreasons, returnactions, requesttypes, paymentstatus, shippingstatus,
pluginscenes, customattrtype, messagetype,
// Account
login, online, logout, register, sendsmsforregister, chanagepwd,
sendsmsforfindpwd, pwdset, checkaccount,
// Customer
getcustomer, customerinfo, customersubmit, customerpoints, uploadavatar,
checkshop, myinvitecode, myinvitees,
// Address
addressList, addressdelete, addressadd, addressdefault, addressedit,
// PM
pmmarkRead, pmsend, pmlist, pmdelpm,
// Topic/News/Blog
topiclist, topicdetail, newslist, newsitem, bloglist, blogitem, blogpost,
blogcategories, blogpapers,
// Product
featuredbycid, homePro, specialproducts, alsopurchased, taglist, productbytag,
getproductattr, getproductspec, productId, productbysku, productpost,
// Category/Brand/Search
homecategories, categoryget, category, brandlist, brandfeaturelist, brandget,
brandfeaturedproducts, search, searCate, findbymid, findbyoid, hotcategory,
hotsearch, searchhistory,
// Favorites/TierPrice
favoriteslist, favoritessubmit, favoritesremove, recentproductlist,
recentproductsubmit, recentproductremove, tierprices,
// ShoppingCart
getShoppingcart, cartCount, producttocart, productstocart, producttocheckout,
cartallselected, updatecartitem, removecartitem, removecart, wishlist,
removewishlistitem, iscollect, towishlist, tocheckout,
// Checkout
checkminsubtotal, getcheckout, getpaymentmethod, getshippingmethod,
submitcheckout, quicksubmit,
// Order
returnrequests, returnpost, orderList, orderDetail, orderconfirm, orderdeliver,
ordercancel,
// Shipping/Kdniao
pickuplist, shopsearch, shipments, expresskdniaoapiurl,
// Plugin
weixinwaploginenabled, weixinwaploginurl, weixinopenloginenabled,
weixinopenlogin, weixinopenphonenumber, weixinwappaymentenabled,
weixinwapaymenturl, weixinopenpaymentenabled, weixinopenpaymenturl,
alipaywappaymentenabled, alipaywappaymenturl,
// Wallet
wallet, walletrecharge, walletrechargelist, walletexchange, walletexchangelist,
walletcardexchange, walletrecordlist,
// Points/RechargeCard
pointsexchangelist, pointsexchange, rechargecardlist, rechargecarditem,
rechargecarditemlist, rechargecarditemget,
// Coupon
couponshow, couponlist, coupon_center, getcoupon, usablecoupon,
// Seckill/PinTuan/SignIn/Task/Share/PreOrder
seckillstatus, seckilllist, pintuanproduct, pintuangroup, pintuankaituan,
signinstatus, signin, signinrecords, signincalendar, tasklist, taskclaim,
taskunclaimed, sharereward, preorderpayrest, preorderrestinfo,
// Agent
agentupgrade, agentmyinfo, agentspostinfo, agentmysummary, agentmyusers,
agentmyorders, agentmybonus,
// Review
commentlist, myreviews, productreviewing, commentsubmit,
// Bundle/Page
bundlelist, pageindex, pagefeaturelist, pageget, pagefeaturedproducts
}四、核心业务流程
4.1 登录授权流
① 账号密码登录:
api.post(login, { model: { name, password } })
→ res.data = { guid, token, nickname }
→ wx.setStorageSync('guid', guid); wx.setStorageSync('token', token)
② 微信授权登录:
wx.login() → code
→ wx.getUserProfile() → encryptedData, iv
→ api.get(weixinopenlogin, { code, state, encryptedData, iv })
→ res.data = { guid, token, openId }(TokenEntity)
→ 存储 guid + token
③ 绑定手机号:
<button open-type="getPhoneNumber">
→ api.get(weixinopenphonenumber, { code, encryptedData, iv })
→ res.data = { phone }4.2 购买流(电商可选)
详情选 SKU → 加入购物车(producttocart) / 立即购买(producttocheckout)
→ 购物车列表勾选(getShoppingcart + cartallselected)
→ 结算页(getcheckout)选地址/优惠券/支付方式
→ api.post(submitcheckout, { request: {...} }) → 创建订单
→ api.get(weixinopenpaymenturl, { orderId, paytype }) → 支付参数
→ wx.requestPayment → 支付成功 → 跳转支付成功页4.3 分销流
用户分享(path 携带 code)→ 新用户进入存储 code
→ api.get(referrerauto) → 自动绑定推荐关系
→ 新用户下单 → 推荐人获佣金/分红
→ 代理中心(agentmyinfo/mysummary/mybonus)查看收益五、页面展示规范
5.1 页面四件套
| 文件 | 作用 |
|---|---|
页面名.js | 页面逻辑(数据、生命周期、事件) |
页面名.wxml | 页面结构(WXML 模板语法) |
页面名.wxss | 页面样式 |
页面名.json | 页面配置(导航栏标题等) |
5.2 JS 页面结构模板
import api from '../../api/api'
import { /* 需要的端点 */ } from '../../api/conf'
Page({
data: { /* 响应式变量 */ },
onLoad(options) { /* 页面加载,处理路由参数 */ },
onShow() { /* 页面显示/切回前台 */ },
onReady() { /* 初次渲染完成 */ },
getData() { /* 业务方法,驼峰命名,动词开头 */ },
onShareAppMessage() { return { title: '分享标题', path: '/pages/xxx/xxx?id=' + this.data.id } }
})5.3 通用组件(跨业务复用,脱离商城限制)
| 组件 | 用途 |
|---|---|
empty-tip | 空状态提示 |
loading-modal | 加载弹窗 |
form-input | 表单输入框 |
address-item | 地址列表项 |
action-sheet | 底部操作弹窗 |
coupon-item | 优惠券卡片(营销可选) |
product-card | 商品卡片(电商可选) |
5.4 状态覆盖
所有列表/详情页必须覆盖四种状态:加载中 / 空数据 / 错误 / 正常;按钮需覆盖业务状态(如商品:正常、售罄、下架、即将开卖)。
六、交互与反馈规范
| 场景 | 实现 | ||
|---|---|---|---|
| 加载中 | wx.showLoading({ title: '加载中', mask: true }) / wx.hideLoading() | ||
| 成功 | wx.showToast({ title: '成功' }) | ||
| 失败 | `wx.showToast({ title: err.content | '失败', icon: 'none' })` | |
| 确认 | wx.showModal({ title, content, success }) | ||
| 下拉刷新 | onPullDownRefresh + wx.stopPullDownRefresh() | ||
| 触底加载 | onReachBottom + page++ | ||
| 分享 | onShareAppMessage 返回 { title, path } |
七、部署上线
- 修改
app.js中globalData.host为后端 API 地址(生产可替换域名,开发用https://dev.ushopun.com) - 在
project.config.json填写小程序 AppID - 后端管理后台配置微信支付商户信息
- 替换腾讯地图 SDK key(如使用定位)
- 配置合法域名(request/uploadFile 域名,含
dev.ushopun.com) - 微信开发者工具上传代码、提交审核
对接前必读:先在
https://dev.ushopun.com示例站点确认目标模块已开通、接口可达(域名白名单、鉴权、模块开关)。若模块返回code: 403(module not open)或code: 220(需升级),说明需在后台开通对应功能,具体开通与付费请直接联系优社电商官方。
八、开发硬性要求
- API 端点必须在
conf.js定义常量,禁止在页面中硬编码 URL - 所有请求通过
api.js封装方法调用,禁止直接wx.request - 请求头自动携带
guid(用户标识)、authorization(JWT Token)、shopId(店铺) - 使用
this.setData()更新数据,数组项更新用字符串 key:['arr[' + i + '].field'] - 图片必须设置
mode属性(推荐widthFix) - 列表渲染必须指定
wx:key - 覆盖所有状态:加载中 / 空数据 / 错误 / 正常
- 响应码:
code === 200成功,code === 250业务警告(提示content),code === 401未授权(跳登录),code === 220需审核,code === 404找不到 - 错误提示优先取
err.content(业务错误描述),成功数据统一从res.data读取;checkaccount接口特殊:code === 1可用、code === 0已存在 - 金额字段统一
Number(x).toFixed(2)保留两位小数;分页默认每页 12 条(个别接口按后端默认值),触底加载page++ - 尺寸单位统一使用
rpx(750rpx = 屏幕宽度),确保多端适配;图片必须设置mode(推荐widthFix) - 代码遵循微信小程序最新基础库规范,纯原生 wx,无第三方框架依赖,可直接导入微信开发者工具运行