feat(uniapp): 小程序端(用户端 uni-app)源码入库到 uniapp/ 目录
需求:小程序端代码要同时同步到服务器与 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 合并会把密码永久写入本仓库历史,故采用快照方式。
这个提交包含在:
425
uniapp/pages/auth/login.vue
普通文件
425
uniapp/pages/auth/login.vue
普通文件
@@ -0,0 +1,425 @@
|
||||
<template>
|
||||
<view class="login">
|
||||
<view class="login__bg"></view>
|
||||
<view class="login__status" :style="{ height: statusBarHeight + 'px' }"></view>
|
||||
|
||||
<view class="login__brand">
|
||||
<image class="fc-logo fc-logo--lg" :src="logoUrl()" mode="aspectFit" />
|
||||
<text class="login__title">{{ siteName }}</text>
|
||||
<text class="login__slogan">招聘 · 房产 · 二手 · 本地服务,一站直达</text>
|
||||
</view>
|
||||
|
||||
<view class="login__panel">
|
||||
<text class="login__panel-title">选择身份</text>
|
||||
<view class="login__types">
|
||||
<view class="login__type" :class="{ 'login__type--active': userType === 1 }" @click="userType = 1">
|
||||
<image class="fc-icon--badge-sm" :src="iconUrl('login-person')" mode="aspectFit" />
|
||||
<text class="login__type-name">个人用户</text>
|
||||
<text class="login__type-desc">发布闲置 / 查看信息</text>
|
||||
</view>
|
||||
<view class="login__type" :class="{ 'login__type--active': userType === 2 }" @click="userType = 2">
|
||||
<image class="fc-icon--badge-sm" :src="iconUrl('login-shop')" mode="aspectFit" />
|
||||
<text class="login__type-name">商家用户</text>
|
||||
<text class="login__type-desc">需营业执照资质认证</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="userType === 2" class="login__license">
|
||||
<view class="login__license-box" @click="chooseLicense">
|
||||
<text v-if="!license">+ 上传营业执照</text>
|
||||
<text v-else class="login__license-file">已选择:{{ license }}</text>
|
||||
</view>
|
||||
<text class="login__license-tip">提交后由后台人工审核,审核期间可正常浏览</text>
|
||||
</view>
|
||||
|
||||
<!-- 微信资料(可选):头像用官方 chooseAvatar,昵称用官方 nickname 输入组件 -->
|
||||
<view class="login__profile">
|
||||
<button class="login__avatar" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
|
||||
<image v-if="avatarUrl" class="login__avatar-img" :src="avatarUrl" mode="aspectFill" />
|
||||
<text v-else class="login__avatar-ph">+</text>
|
||||
</button>
|
||||
<view class="login__profile-fields">
|
||||
<input class="login__nickname" type="nickname" v-model="nickname" placeholder="点击获取微信昵称"
|
||||
placeholder-class="login__nickname-ph" />
|
||||
<text class="login__profile-tip">同步您的微信头像与昵称(可跳过)</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="login__btn" :class="{ 'login__btn--disabled': loading }" @click="onLogin">
|
||||
<text>{{ loading ? '登录中…' : '微信一键登录' }}</text>
|
||||
</view>
|
||||
<!-- 手机号绑定:优先微信一键获取(open-type=getPhoneNumber),失败/不支持时回落手动输入 -->
|
||||
<button class="login__phone" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
|
||||
<image class="fc-icon fc-icon--sm" :src="iconUrl('phonebind')" mode="aspectFit" />
|
||||
<text class="login__phone-text">{{ phoneText }}</text>
|
||||
</button>
|
||||
|
||||
<text class="login__agree">登录即代表同意《用户协议》与《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useUserStore } from '@/common/store/index.js'
|
||||
import authApi from '@/common/api/auth.js'
|
||||
import config from '@/common/config/index.js'
|
||||
import { iconUrl, logoUrl, loadUiConfig, uiState } from '@/common/store/ui.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
statusBarHeight: 20,
|
||||
userType: config.constants.USER_TYPE.PERSON,
|
||||
license: '',
|
||||
loading: false,
|
||||
// 微信资料(可选):昵称 + 头像临时路径(登录拿到 token 后再上传落库)
|
||||
nickname: '',
|
||||
avatarUrl: '',
|
||||
pendingAvatar: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
siteName() {
|
||||
return uiState.siteName || '同城分类信息'
|
||||
},
|
||||
userInfo() {
|
||||
try {
|
||||
return useUserStore().state.userInfo || {}
|
||||
} catch (e) {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
phoneText() {
|
||||
const phone = this.userInfo.phone || ''
|
||||
return phone ? '已绑定 ' + this.maskPhone(phone) : '手机号授权绑定'
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
try {
|
||||
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 20
|
||||
} catch (e) {}
|
||||
loadUiConfig()
|
||||
},
|
||||
methods: {
|
||||
iconUrl,
|
||||
logoUrl,
|
||||
chooseLicense() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
const f = (res.tempFilePaths && res.tempFilePaths[0]) || 'license.jpg'
|
||||
this.license = String(f).split('/').pop()
|
||||
uni.showToast({ title: '已选择资质文件', icon: 'none' })
|
||||
},
|
||||
fail: () => {
|
||||
this.license = '营业执照.jpg'
|
||||
},
|
||||
})
|
||||
},
|
||||
async onLogin() {
|
||||
if (this.loading) return
|
||||
if (this.userType === config.constants.USER_TYPE.BUSINESS && !this.license) {
|
||||
uni.showToast({ title: '商家用户请先上传营业执照', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.loading = true
|
||||
const store = useUserStore()
|
||||
try {
|
||||
const wxCode = await this.getWxCode()
|
||||
// 登录时带上微信昵称(头像需先登录拿 token 再上传,见下方)
|
||||
await store.login({ code: wxCode, nickname: this.nickname || undefined })
|
||||
// 头像:chooseAvatar 拿到的是本地临时文件,登录后上传到服务端并写回资料
|
||||
if (this.pendingAvatar) {
|
||||
try {
|
||||
const up = await authApi.uploadAvatar(this.pendingAvatar)
|
||||
if (up && up.avatar) await authApi.saveProfile({ avatar: up.avatar })
|
||||
} catch (e) {
|
||||
// 头像上传失败不影响登录
|
||||
}
|
||||
}
|
||||
if (this.nickname || this.pendingAvatar) {
|
||||
await store.fetchProfile()
|
||||
}
|
||||
const res = await store.switchType(this.userType, this.license)
|
||||
uni.showToast({ title: res.needAudit ? '已提交资质,等待审核' : '登录成功', icon: 'none' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 600)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '登录失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
getWxCode() {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
if (typeof uni !== 'undefined' && uni.login) {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (r) => resolve(r.code || 'mock_code'),
|
||||
fail: () => resolve('mock_code'),
|
||||
})
|
||||
return
|
||||
}
|
||||
} catch (e) {}
|
||||
resolve('mock_code')
|
||||
})
|
||||
},
|
||||
/** 选择微信头像(官方组件回调,返回的是本地临时文件) */
|
||||
onChooseAvatar(e) {
|
||||
const temp = (e && e.detail && e.detail.avatarUrl) || ''
|
||||
if (!temp) return
|
||||
this.pendingAvatar = temp
|
||||
this.avatarUrl = temp // 本地预览
|
||||
},
|
||||
async onGetPhoneNumber(e) {
|
||||
// e.detail.code:微信手机号快捷验证的临时凭证(有效期 5 分钟,一次性)
|
||||
const code = (e && e.detail && e.detail.code) || ''
|
||||
if (!code) {
|
||||
// 用户点了「拒绝」或当前环境(H5/模拟器)不支持快捷获取 → 手动输入兜底
|
||||
this.manualBindPhone('可手动输入手机号完成绑定')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await authApi.wxPhone({ code })
|
||||
this.applyPhone(res.phone)
|
||||
uni.showToast({ title: '手机号已绑定', icon: 'none' })
|
||||
} catch (err) {
|
||||
// 快捷验证未开通/额度用尽/code 失效等 → 手动输入兜底,保证仍能拿到号码
|
||||
this.manualBindPhone(err && err.message)
|
||||
}
|
||||
},
|
||||
/** 手动输入手机号绑定(真实落库,替代原先前端拼假号的做法) */
|
||||
manualBindPhone(tip) {
|
||||
uni.showModal({
|
||||
title: '绑定手机号',
|
||||
editable: true,
|
||||
placeholderText: '请输入 11 位手机号',
|
||||
content: tip || '',
|
||||
success: async (r) => {
|
||||
if (!r.confirm) return
|
||||
const phone = String(r.content || '').trim()
|
||||
if (!/^1\d{10}$/.test(phone)) {
|
||||
uni.showToast({ title: '手机号格式不正确', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await authApi.bindPhone({ phone })
|
||||
this.applyPhone(res.phone)
|
||||
uni.showToast({ title: '手机号已绑定', icon: 'none' })
|
||||
} catch (err) {
|
||||
uni.showToast({ title: (err && err.message) || '绑定失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
applyPhone(phone) {
|
||||
const store = useUserStore()
|
||||
store.state.userInfo = { ...(store.state.userInfo || {}), phone }
|
||||
},
|
||||
maskPhone(phone) {
|
||||
return String(phone || '').replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login {
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
}
|
||||
.login__bg {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 620rpx;
|
||||
background: $fc-gradient-hero;
|
||||
border-radius: 0 0 60rpx 60rpx;
|
||||
}
|
||||
.login__brand {
|
||||
position: relative;
|
||||
padding: 120rpx 60rpx 60rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.login__title {
|
||||
margin-top: 28rpx;
|
||||
color: #ffffff;
|
||||
font-size: 44rpx;
|
||||
font-weight: 700;
|
||||
letter-spacing: 2rpx;
|
||||
}
|
||||
.login__slogan {
|
||||
margin-top: 12rpx;
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
font-size: $fc-font-sm;
|
||||
}
|
||||
.login__panel {
|
||||
position: relative;
|
||||
margin: 40rpx 40rpx 0;
|
||||
background: #ffffff;
|
||||
border-radius: 32rpx;
|
||||
padding: 40rpx 32rpx;
|
||||
box-shadow: $fc-shadow-lg;
|
||||
}
|
||||
.login__panel-title {
|
||||
font-size: $fc-font-lg;
|
||||
font-weight: 700;
|
||||
color: $fc-text;
|
||||
}
|
||||
.login__types {
|
||||
display: flex;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.login__type {
|
||||
flex: 1;
|
||||
border: 2rpx solid $fc-border;
|
||||
border-radius: $fc-radius-lg;
|
||||
padding: 24rpx 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: $fc-bg;
|
||||
&:first-child {
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
&--active {
|
||||
border-color: $fc-primary-text;
|
||||
background: $fc-primary-lighter;
|
||||
}
|
||||
}
|
||||
.login__type-name {
|
||||
margin-top: 16rpx;
|
||||
font-size: $fc-font-lg;
|
||||
font-weight: 700;
|
||||
color: $fc-text;
|
||||
}
|
||||
.login__type-desc {
|
||||
margin-top: 6rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-secondary;
|
||||
}
|
||||
.login__license {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
.login__license-box {
|
||||
height: 120rpx;
|
||||
border: 2rpx dashed $fc-primary-text;
|
||||
border-radius: $fc-radius;
|
||||
background: $fc-bg;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: $fc-primary-text;
|
||||
font-size: $fc-font;
|
||||
}
|
||||
.login__license-file {
|
||||
color: $fc-success;
|
||||
}
|
||||
.login__license-tip {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.login__btn {
|
||||
margin-top: 40rpx;
|
||||
height: 92rpx;
|
||||
border-radius: $fc-radius-pill;
|
||||
background: $fc-gradient-primary;
|
||||
color: $fc-primary-ink;
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 10rpx 28rpx rgba(4, 48, 30, 0.35);
|
||||
&--disabled {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
.login__profile {
|
||||
margin-top: 32rpx;
|
||||
padding: 24rpx;
|
||||
border-radius: $fc-radius;
|
||||
background: rgba(255, 255, 255, 0.78);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.login__avatar {
|
||||
width: 108rpx;
|
||||
height: 108rpx;
|
||||
padding: 0;
|
||||
line-height: 1;
|
||||
border-radius: 50%;
|
||||
background: $fc-primary-lighter;
|
||||
border: 2rpx solid $fc-primary-soft;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
/* 小程序 button 默认自带 ::after 边框,需清除 */
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
.login__avatar-img {
|
||||
width: 108rpx;
|
||||
height: 108rpx;
|
||||
}
|
||||
.login__avatar-ph {
|
||||
font-size: 40rpx;
|
||||
color: $fc-primary-text;
|
||||
font-weight: 700;
|
||||
}
|
||||
.login__profile-fields {
|
||||
flex: 1;
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
.login__nickname {
|
||||
height: 60rpx;
|
||||
font-size: $fc-font;
|
||||
color: $fc-text;
|
||||
border-bottom: 2rpx solid $fc-border;
|
||||
}
|
||||
.login__nickname-ph {
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
.login__profile-tip {
|
||||
display: block;
|
||||
margin-top: 10rpx;
|
||||
font-size: 22rpx;
|
||||
color: $fc-text-secondary;
|
||||
}
|
||||
.login__phone {
|
||||
margin-top: 24rpx;
|
||||
height: 88rpx;
|
||||
line-height: 1;
|
||||
border-radius: $fc-radius-pill;
|
||||
border: 2rpx solid $fc-primary-text;
|
||||
color: $fc-primary-text;
|
||||
background: transparent;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: $fc-font;
|
||||
/* 小程序 button 默认自带 ::after 边框,需清除以保证描边样式一致 */
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
.login__phone-text {
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
.login__agree {
|
||||
display: block;
|
||||
margin-top: 28rpx;
|
||||
text-align: center;
|
||||
font-size: $fc-font-xs;
|
||||
color: $fc-text-placeholder;
|
||||
}
|
||||
</style>
|
||||
|
||||
在新工单中引用
屏蔽一个用户