需求:小程序端代码要同时同步到服务器与 git 远程仓库,此前前端仅存在于本地目录(无 remote,从未推送), 服务器与 gitcode 上只有后端。现并入本仓库,复用现有「push 即部署」链路,一次推送双端落地。 - 新增 uniapp/:小程序端源码全量快照(150 文件 / 1.2M) pages(13 页面) · components(fc-navbar/fc-tabbar/fc-post-card/fc-empty) · common(api·utils·mock·assets·store·config) · static(74 图标 + 3 轮播插画 + LOGO) · docs(01-04 交付文档) · tests(零依赖全链路用例) · tools(图标/主题/轮播配图生成脚本) - 明确排除:AGENTS.md(含后台密码、服务器 root 密码、小程序 AppSecret,切勿入库)、 unpackage/(构建产物,由 uniapp/.gitignore 忽略)、node_modules、.DS_Store、*.log - .gitignore 新增 /uniapp/AGENTS.md 兜底(与根 /AGENTS.md、/fluniapp/ 同一约定) - README.md 增补「本项目结构 + 部署链路」章节,说明 uniapp/ 为源码快照、 小程序真正上线仍需微信开发者工具 cli upload 说明:本次为源码快照,未携带前端本地仓库历史——其历史提交中含 AGENTS.md 凭据, 若做 subtree 合并会把密码永久写入本仓库历史,故采用快照方式。
56 行
2.1 KiB
JavaScript
56 行
2.1 KiB
JavaScript
/**
|
||
* 接口模块 · 认证与登录(用户端)
|
||
* 对应模块:认证与登录
|
||
*/
|
||
import { get, post, buildUrl, buildHeaders } from '../utils/request.js'
|
||
|
||
export const authApi = {
|
||
/** 微信一键授权登录:code -> token */
|
||
wxLogin: (payload) => post('/auth/wx-login', payload, { silent: true }),
|
||
/** 手机号绑定(手动输入 11 位手机号) */
|
||
bindPhone: (payload) => post('/auth/bind-phone', payload, { silent: true }),
|
||
/** 微信手机号快捷获取(<button open-type="getPhoneNumber"> 回调的 code) */
|
||
wxPhone: (payload) => post('/auth/wx-phone', payload, { silent: true }),
|
||
/** 更新个人资料(微信昵称 / 头像路径) */
|
||
saveProfile: (payload) => post('/auth/profile', payload, { silent: true }),
|
||
/**
|
||
* 上传微信头像(chooseAvatar 得到的临时文件路径)
|
||
* 小程序环境走 uni.uploadFile(multipart/form-data);Node 测试环境回落 mock 路由。
|
||
* @returns {Promise<{url:string, avatar:string}>}
|
||
*/
|
||
uploadAvatar(filePath) {
|
||
if (typeof uni === 'undefined' || !uni.uploadFile) {
|
||
return post('/auth/avatar', { file: filePath }, { silent: true })
|
||
}
|
||
return new Promise((resolve, reject) => {
|
||
const header = buildHeaders()
|
||
// uni.uploadFile 自行设置 multipart 边界,不能带 application/json
|
||
delete header['Content-Type']
|
||
uni.uploadFile({
|
||
url: buildUrl('/auth/avatar'),
|
||
filePath,
|
||
name: 'file',
|
||
header,
|
||
success: (res) => {
|
||
let body = res && res.data
|
||
try {
|
||
body = JSON.parse(res.data)
|
||
} catch (e) {}
|
||
if (body && body.code === 0) {
|
||
resolve(body.data)
|
||
return
|
||
}
|
||
reject(new Error((body && body.message) || '头像上传失败'))
|
||
},
|
||
fail: () => reject(new Error('头像上传失败')),
|
||
})
|
||
})
|
||
},
|
||
/** 个人 / 商家用户类型切换(商家需资质) */
|
||
switchType: (payload) => post('/auth/switch-type', payload, { silent: true }),
|
||
/** 获取当前用户资料 */
|
||
profile: () => get('/auth/profile', {}, { silent: true }),
|
||
}
|
||
|
||
export default authApi
|