Commit 98b8895d by 胡悦

feat: 添加修改密码功能和相关组件

- 新增 ChangePassword 组件,支持用户修改密码功能
- 在 HomeFrame 组件中集成 ChangePassword 组件,并添加相应的事件处理
- 更新登录页面,支持用户输入账号和密码,并进行登录验证
- 优化用户体验,添加输入框清除功能和密码可见性切换
- 更新 API 调用,确保密码加密传输
- 添加登录流程说明文档,详细描述登录和门店选择的流程
1 parent b1431c62
import http from '../request/http'
import environment from '@/env'
module.exports = {
/**查询当前门店是否有客户档案权限 */
haveCustomerAccess (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.findPermissionsMerchantList',
projectName: 'boutique',
...data
})
},
/**查询当前门店客户档案列表 */
getCustomerFileList (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.customerInfoPage',
projectName: 'boutique',
...data
})
},
/* 删除客户档案*/
delCustomerFile (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.deleteVisitsInfo',
projectName: 'boutique',
...data
})
},
/** 根据业务查询接待场景 */
findAllSence (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.findAllSence',
projectName: 'boutique',
...data
})
},
/**根据业务查询客户标签 */
findCustomerTags (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.findSenceTag',
projectName: 'boutique',
...data
})
},
/**
* 查询客户档案详情
*/
findVisitsInfo (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.findVisitsInfo',
projectName: 'boutique',
...data
})
},
/*
* 保存客户档案
*/
saveVisitsInfo (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.saveVisitsInfo',
projectName: 'boutique',
...data
})
},
/**
* 更新客户档案
*/
updateVisitsInfo (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.updateVisitsInfo',
projectName: 'boutique',
...data
})
},
/**查询客户档案列表 */
getCustomerInfoList (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.customerInfoList',
projectName: 'boutique',
...data
})
},
/**接待客户素材
*
*/
getMaterialResponsePage (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.getMaterialResponsePage',
projectName: 'boutique',
...data
})
},
/**素材详情 查询素材详情 */
getMaterialDetail (data) {
return http.post({
method: 'dj.api.smartcarlife.customervisits.getMaterialById',
projectName: 'boutique',
...data
})
},
/**直营驻店人员 */
saleOpen (data) {
return http.post({
method: 'dj.api.car.boutique.resident.direct.sale.merchant',
projectName: 'boutique',
...data
})
}
}
......@@ -12,5 +12,28 @@ module.exports = {
},
getUserInfo () {
return http.shukeRequest('linkwechat-api/system/user/getInfo', {}, 'GET', true)
},
loginIn (data) {
return http.shukeRequest('linkwe-gateway/auth/accountLoginSp/init', data, 'POST', true)
},
// 获取单店列表
getStoreList (spCode) {
return http.shukeRequest('linkwe-gateway/auth/accountLoginSp/stores', { spCode }, 'POST', true)
},
// 确认登录单店
confirmLoginStore (data) {
return http.shukeRequest('linkwe-gateway/auth/accountLoginSp/confirm', data, 'POST', true)
},
// 修改密码
updateUserPwd (oldPassword, newPassword) {
return http.shukeRequest(`linkwechat-api/system/user/profile/updatePwd?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`, {}, 'PUT', true)
},
// 保存登录信息
saveLoginInfo(data) {
return http.shukeRequest('linkwe-gateway/auth/accountLoginSp/save', data, 'POST', true)
},
// 恢复登录信息
restoreLoginInfo(data) {
return http.shukeRequest('linkwe-gateway/auth/accountLoginSp/restore', data, 'POST', true)
}
}
\ No newline at end of file
import http from '../request/http'
module.exports = {
/**查询所有业务场景 */
getSceneMarketMaterialMenu (data = {}) {
return http.post({
method: 'dj.api.carboutique.material.scenemarket.findAllLevel',
projectName: 'boutique',
...data
})
}, /**根据场景查询素材列表 */
getSceneMarketMaterialList (data = {}) {
return http.post({
method: 'dj.api.carboutique.material.scenemarket.findByOneCode',
projectName: 'boutique',
...data
})
},
/**获取智能体 */
getAiagent (data = {}) {
return http.post({
method: 'dj.pad.api.aiagent.get.special.agent',
projectName: 'pad',
...data
})
}
}
\ No newline at end of file
import http from '../request/http'
module.exports = {
/**获取短信 */
getSmsCode(data = {}) {
data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.sms.get.code', data)
},
/**手机验证码登录 */
smsLogin(data = {}) {
data.projectName = 'boutique'
data.source = 'MINIAPP'
data.productCode = 'PC00c2'
return http.fetch('dj.api.smartcarlife.sms.applogin', data)
},
/**免登 */
autoLogin(data = {}) {
data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.sms.noSignIn.login', data)
},
// 获取园区店下的4s店
getSceneMerchantRefStoreList(data) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.scenemerchantref.query4SRefByYqShopByLogin',
...data
})
},
/**获取帐号列表 */
getListSelectAccount(data = {}) {
data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.workWechat.listSelectAccount', data)
},
/**选择帐号登陆 */
selectAccountLogin(data) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.workWechat.selectAccountLogin',
...data
})
},
// 选择4s店和场景
selectMerchantScene(data) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.selectMerchantScene',
...data
})
},
// 获取园区店开通的场景入口
getYqMerchantSceneConfigAPI(data) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.select.openScene.info',
...data
})
},
/**退出*/
logout(data = {}) {
data.projectName = 'boutique'
return http.fetch('dj.api.smartcarlife.logout', data)
},
/**
* 查询门店品牌 "渠道标识channelType 1.问界 2.比亚迪 3.其他"
*/
getMerchantBrand(data = {}) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.recepiton.findMerchantBrand',
...data
})
},
/**
* 查询门店保险权益
*/
getMerchantInsuranceList(data = {}) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.recepiton.findMerchantItem',
...data
})
},
/**
* 员工隐私密码验证
*/
verifyStaffPassword(data = {}) {
data.projectName = 'boutique'
return http.post({
method: 'dj.api.smartcarlife.staff.private.password.verify',
...data
})
}
}
......@@ -201,6 +201,7 @@ class Request {
dataType: 'json',
responseType: 'text',
success (response) {
console.log('response', response)
try {
let { data, statusCode } = response
if (!data || statusCode != 200) {
......@@ -217,17 +218,71 @@ class Request {
}
let { code, msg } = data
if (code == 401) {
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.hideLoading()
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`HTTP Triggered Logout: params:${JSON.stringify(params)} method: ${params.method}->code:${code} msg:${msg} currentPage:${currentPage.route}`)
uni.hideLoading()
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
// 检查是否有 30 天免登标识
const noSignInUuid = uni.$storage.get('noSignInUuid')
const currentSessionId = uni.$storage.get('sessionId')
if (noSignInUuid && currentSessionId) {
// 尝试调用 restoreLoginInfo 恢复登录
uni.request({
url: `${shukeDomain}/linkwe-gateway/auth/accountLoginSp/restore`,
data: { token: currentSessionId },
method: 'POST',
header: { 'content-type': 'application/json' },
success: function(restoreRes) {
const restoreData = restoreRes.data
if (restoreData && restoreData.code === 0) {
// 恢复成功,更新 sessionId 和 userInfo
const newToken = restoreData.data?.token || restoreData.data?.sessionId || restoreData.data?.access_token
const userInfo = restoreData.data?.loginUser || restoreData.data?.user || {}
if (newToken) {
uni.$storage.set('sessionId', newToken)
}
if (userInfo && Object.keys(userInfo).length > 0) {
uni.$storage.set('userInfo', userInfo)
}
// 重新发起原请求
resolve(_this.shukeRequest(url, params, method, returnAll))
} else {
// restoreLoginInfo 返回 code 不为 0,清除缓存跳转登录
failHandler()
}
},
fail: function() {
// restoreLoginInfo 失败,清除缓存跳转登录
failHandler()
}
})
function failHandler() {
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.$storage.set('noSignInUuid', '')
uni.hideLoading()
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`restoreLoginInfo 失败,跳转登录页:currentPage:${currentPage.route}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: `/pages/common/login?username=${noSignInUuid}`
})
}
reject('登录已过期,请重新登录')
}
return
} else {
// 没有 30 天免登标识,直接清除缓存跳转登录
uni.$storage.set('sessionId', '')
uni.$storage.set('userInfo', {})
uni.hideLoading()
const pages = getCurrentPages(),
currentPage = pages[pages.length - 1]
uni.$logger.local.warn(`HTTP Triggered Logout: params:${JSON.stringify(params)}->code:${code} msg:${msg} currentPage:${currentPage.route}`)
if (currentPage.route != 'pages/common/login') {
uni.reLaunch({
url: '/pages/common/login'
})
}
}
} else resolve(data.data)
} catch (error) {
......
......@@ -80,6 +80,11 @@ export default {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: toRpx(32);
max-height: toRpx(600);
overflow-y: auto;
padding: toRpx(10);
margin: toRpx(-10);
box-sizing: border-box;
}
.option-item {
......
<template>
<uni-popup ref="popup" type="center" border-radius="20px" @maskClick="false">
<view class="change-password-box">
<!-- 关闭按钮 -->
<view class="close" @click="close">
<uni-icons type="closeempty" :size="18" color="#1A1A1A"></uni-icons>
</view>
<!-- 左侧装饰图 -->
<view class="left-decoration">
<view class="lock-icon sprite-icon icon-locker-icon"></view>
</view>
<!-- 右侧表单区域 -->
<view class="form-content">
<view class="title">修改密码</view>
<!-- 旧密码输入框 -->
<view class="form-item">
<view class="form-label">旧密码</view>
<view class="form-input-wrapper">
<input
:type="showOldPassword ? 'text' : 'password'"
v-model="formData.oldPassword"
placeholder="请输入旧密码"
:class="['form-input', { error: error.oldPassword }]"
@input="clearError('oldPassword')"
/>
<view class="pwd-eye" @click="showOldPassword = !showOldPassword">
<uni-icons :type="showOldPassword ? 'eye' : 'eye-slash'" :size="18" color="#858A94"></uni-icons>
</view>
</view>
<view v-if="error.oldPassword" class="error-text">{{ error.oldPassword }}</view>
</view>
<!-- 新密码输入框 -->
<view class="form-item">
<view class="form-label">新密码</view>
<view class="form-input-wrapper">
<input
:type="showNewPassword ? 'text' : 'password'"
v-model="formData.newPassword"
placeholder="请输入新密码"
:class="['form-input', { error: error.newPassword }]"
@input="clearError('newPassword')"
/>
<view class="pwd-eye" @click="showNewPassword = !showNewPassword">
<uni-icons :type="showNewPassword ? 'eye' : 'eye-slash'" :size="18" color="#858A94"></uni-icons>
</view>
</view>
<view v-if="error.newPassword" class="error-text">{{ error.newPassword }}</view>
</view>
<!-- 确认新密码输入框 -->
<view class="form-item">
<view class="form-label">重复新密码</view>
<view class="form-input-wrapper">
<input
:type="showConfirmPassword ? 'text' : 'password'"
v-model="formData.confirmPassword"
placeholder="请再次输入新密码"
:class="['form-input', { error: error.confirmPassword }]"
@input="clearError('confirmPassword')"
/>
<view class="pwd-eye" @click="showConfirmPassword = !showConfirmPassword">
<uni-icons :type="showConfirmPassword ? 'eye' : 'eye-slash'" :size="18" color="#858A94"></uni-icons>
</view>
</view>
<view v-if="error.confirmPassword" class="error-text">{{ error.confirmPassword }}</view>
</view>
<!-- 完成设置按钮 -->
<view class="submit-btn" :class="{ disabled: !canSubmit }" @click="submit">
完成设置
</view>
</view>
</view>
</uni-popup>
</template>
<script type="text/ecmascript-6">
import { encrypt } from '@/utils/jsencrypt'
export default {
name: 'ChangePassword',
data() {
return {
formData: {
oldPassword: '',
newPassword: '',
confirmPassword: ''
},
showOldPassword: false,
showNewPassword: false,
showConfirmPassword: false,
error: {
oldPassword: '',
newPassword: '',
confirmPassword: ''
}
}
},
computed: {
canSubmit() {
// 所有输入框不为空时启用
return this.formData.oldPassword && this.formData.newPassword && this.formData.confirmPassword
}
},
methods: {
open() {
this.$refs.popup.open('center')
// 重置表单
this.formData = {
oldPassword: '',
newPassword: '',
confirmPassword: ''
}
this.error = {
oldPassword: '',
newPassword: '',
confirmPassword: ''
}
this.showOldPassword = false
this.showNewPassword = false
this.showConfirmPassword = false
},
close() {
this.$refs.popup.close()
},
clearError(field) {
this.error[field] = ''
},
validate() {
let isValid = true
const { oldPassword, newPassword, confirmPassword } = this.formData
// 重置错误
this.error = {
oldPassword: '',
newPassword: '',
confirmPassword: ''
}
// 校验新密码长度
if (newPassword.length < 6 || newPassword.length > 20) {
this.error.newPassword = '新密码长度不能少于 6 位'
isValid = false
return isValid
}
// 校验两次密码是否一致
if (newPassword !== confirmPassword) {
this.error.confirmPassword = '两次输入的密码不一致'
isValid = false
return isValid
}
return isValid
},
async submit() {
if (!this.canSubmit) return
// 表单验证
if (!this.validate()) return
uni.showLoading({
mask: true,
title: '提交中...'
})
try {
// 调用修改密码接口,密码需要加密
const res = await uni.$api.loginApi.updateUserPwd(
encrypt(this.formData.oldPassword),
encrypt(this.formData.newPassword)
)
uni.hideLoading()
// 判断是否成功 (参考 getUserInfo 的返回格式,code 为 0 表示成功)
if (res.code === 0 || res.code === 200) {
uni.showToast({
title: '操作成功',
icon: 'success'
})
this.close()
} else {
// 旧密码错误等其他情况
if (res.code === 401 || (res.message && res.message.includes('旧密码'))) {
this.error.oldPassword = '旧密码错误'
} else {
uni.showToast({
title: '操作失败',
icon: 'none'
})
}
}
} catch (error) {
uni.hideLoading()
uni.showToast({
title: '操作失败',
icon: 'none'
})
}
}
}
}
</script>
<style scoped lang="scss">
.change-password-box {
position: relative;
width: toRpx(1200);
min-height: toRpx(600);
background: #ffffff;
border-radius: toRpx(40);
display: flex;
flex-direction: row;
overflow: hidden;
.close {
position: absolute;
top: toRpx(24);
right: toRpx(24);
width: toRpx(60);
height: toRpx(60);
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
}
.left-decoration {
width: toRpx(350);
background: linear-gradient(135deg, #f0f4ff 0%, #e8efff 100%);
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.form-content {
flex: 1;
padding: toRpx(80) toRpx(60) toRpx(60);
display: flex;
flex-direction: column;
.title {
font-size: toRpx(40);
font-weight: 600;
color: #333333;
margin-bottom: toRpx(60);
}
.form-item {
margin-bottom: toRpx(40);
.form-label {
font-size: toRpx(28);
color: #333333;
margin-bottom: toRpx(16);
font-weight: 500;
}
.form-input-wrapper {
position: relative;
display: flex;
align-items: center;
.form-input {
width: 100%;
height: toRpx(80);
background: #f7f8fa;
border: toRpx(2) solid #e8e8e8;
border-radius: toRpx(40);
padding: 0 toRpx(80) 0 toRpx(32);
font-size: toRpx(28);
color: #333333;
transition: all 0.3s;
&.error {
border-color: #ff4d4f;
background: #fff1f0;
}
}
.pwd-eye {
position: absolute;
right: toRpx(24);
display: flex;
align-items: center;
justify-content: center;
width: toRpx(40);
height: toRpx(40);
}
}
.error-text {
font-size: toRpx(24);
color: #ff4d4f;
margin-top: toRpx(12);
padding-left: toRpx(12);
}
}
.submit-btn {
width: 100%;
height: toRpx(80);
background: linear-gradient(90deg, #6b8cff 0%, #8f7aff 100%);
border-radius: toRpx(40);
display: flex;
align-items: center;
justify-content: center;
font-size: toRpx(32);
color: #ffffff;
font-weight: 600;
margin-top: toRpx(40);
cursor: pointer;
transition: all 0.3s;
&.disabled {
background: #d9d9d9;
cursor: not-allowed;
opacity: 0.6;
}
}
}
}
</style>
......@@ -36,6 +36,7 @@
<setting-box
ref="settingRef"
@stopAudio="$emit('stopAudio')"
@openChangePassword="$emit('openChangePassword')"
/>
</view>
</template>
......@@ -66,11 +67,11 @@ export default {
name: 'ReceptionCenter',
eventCode: 'app_reception_center'
},
{
label: "订单",
icon: "scene",
name: 'Order'
}
// {
// label: "订单",
// icon: "scene",
// name: 'Order'
// }
]
return tabs
}
......
......@@ -10,10 +10,11 @@
<view class="filter-container">
<view :class="uiConfig.filterContainerClass">
<view class="filter-group">
<button-group
<button-group
:key="tabIndex"
:class="uiConfig.filterClass"
:selectList="uiConfig.filterList"
@chooseType="uiConfig.filterHandler"
:selectList="uiConfig.filterList"
@chooseType="uiConfig.filterHandler"
/>
</view>
</view>
......@@ -222,8 +223,9 @@ export default {
if (this.tabIndex == index) return
this.resetData()
this.tabIndex = index
// this.reviewFlag = 0
// 切换 tab 时重置筛选参数
this.orderFinishFlag = 0
this.uploadType = 0
this.loadData()
},
formatValue (val, k) {
......
......@@ -12,6 +12,7 @@
</view>
<view class="btn-box">
<view class="btn flex" @click="changeAccount">切换账号</view>
<view class="btn flex" @click="openChangePassword">修改密码</view>
<view class="btn flex logout" @click="logout">退出</view>
</view>
<view class="a" @click="jump('agreement')">《用户隐私协议》</view>
......@@ -94,50 +95,66 @@ export default {
close() {
this.$refs.popup.close()
},
changeAccount() {
uni.reLaunch({
url: '/pages/common/accountItems'
})
openChangePassword() {
this.$emit('openChangePassword')
},
async changeAccount() {
try {
uni.showLoading({
mask: true
})
// 调用 getStoreList 获取门店列表
const storeListRes = await uni.$api.loginApi.getStoreList()
if (!storeListRes || !storeListRes.data) {
throw '获取门店列表失败'
}
const stores = storeListRes.data.stores
if (!stores || stores.length === 0) {
throw '暂无门店信息,请联系管理员'
}
uni.hideLoading()
// 跳转至门店列表页面
uni.reLaunch({
url: `/pages/common/selectStore?stores=${encodeURIComponent(JSON.stringify(stores))}`
})
} catch (error) {
uni.hideLoading()
uni.showToast({
title: error?.message || error,
icon: 'none'
})
}
},
// 退出
logout() {
let _this = this
uni.showModal({
title: '温馨提示',
content: '是否退出当前账号?',
confirmColor: '#347BFF',
async success(res) {
success(res) {
if (res.confirm) {
// _this.$emit('stopAudio')
try {
uni.showLoading({
mask: true
// 清除 session 和本地存储
uni.$storage.rm("userInfo")
uni.$storage.rm("sessionId")
uni.$storage.rm("noSignInUuid")
uni.$storage.rm("beisenToken")
uni.$storage.rm("studyCenterPermission")
uni.$storage.rm("boutique_YQorderSetting")
// 跳转至登录页面
uni.reLaunch({
url: '/pages/common/login'
})
const {
code,
message
} = await uni.$api.userApi.logout(),
userInfo = uni.$storage.get("userInfo")
if (code == 0) {
uni.$storage.rm("userInfo");
uni.$storage.rm("sessionId");
uni.$storage.rm("noSignInUuid");
uni.$storage.rm("beisenToken");
uni.$storage.rm("studyCenterPermission");
uni.$storage.rm("boutique_YQorderSetting")
setTimeout(() => {
uni.hideLoading()
uni.reLaunch({
url: `/pages/common/login?mobile=${userInfo.phone}`,
});
}, 500)
} else throw message
} catch (error) {
uni.hideLoading()
uni.showToast({
title: error,
icon: "none",
});
title: '退出失败',
icon: "none"
})
}
}
}
......
<template>
<view class="container" @click="handleTouchStart">
<view :class="['home', { show: !activeDetailId && showHome }]">
<left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" ref="leftBox" @changeTab="changeTab" @stopAudio="stopAudio" @showReadCountTips="showReadCountTips" @closeTips="closeTips" />
<left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" ref="leftBox" @changeTab="changeTab" @stopAudio="stopAudio" @showReadCountTips="showReadCountTips" @closeTips="closeTips" @openChangePassword="handleOpenChangePassword" />
<view class="tips-box" :style="tipsObject.style" @click.stop="closeTips">{{ tipsObject.text }}</view>
<view class="right-side">
<home-slot v-if="tabIndex == 0" :tabIndex="tabIndex" :moduleList="moduleList" @start="start" @changeType="changeType" />
......@@ -34,6 +34,8 @@
只需修改 @message 绑定的方法名即可无侵入切换
-->
<web-view ref="uploaderWebview" src="/hybrid/html/index.html" @message="handleUploadMessageNew" :webview-styles="webviewStyles"></web-view>
<!-- 修改密码弹窗 -->
<change-password ref="changePasswordRef" />
<!-- <web-view
ref="studyWebview"
:src="jumpUrl"
......@@ -52,6 +54,7 @@ import LeftSide from './components/LeftSide.vue'
import Material from '@/components/MaterialIndex.vue'
import HomeSlot from './components/HomeSlot.vue'
import Order from './components/Order/index.vue'
import ChangePassword from './components/ChangePassword.vue'
// import UploadService from '@/utils/recordManager/UploadService.js'
import { FileUploadManager, UploadService } from '@/utils/recordManager'
......@@ -61,7 +64,7 @@ const TAB_COMPONENTS = {
}
export default {
mixins: [recorder, versionCheck],
components: { LeftSide, Material, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order },
components: { LeftSide, Material, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order, ChangePassword },
props: {
activeDetailId: [String, Number],
finishDoneText: String,
......@@ -202,6 +205,9 @@ export default {
},
handleTouchStart() {
uni.$emit('reset_timeout')
},
handleOpenChangePassword() {
this.$refs.changePasswordRef.open()
}
}
}
......
......@@ -6,11 +6,14 @@
</view>
<view :class="['list', { showList: !show }]">
<view class="title" @click="close">{{ folderName }}</view>
<view class="list-body">
<view class="list-body" :class="{ 'multi-column': data.length > 8 }">
<template v-for="(i, index) in data">
<view :class="['item', { active: i[idKey] == id }]" :key="index" @click="jump(i)" :style="{'--i': index}">
<template v-if="i.shortTitleUrl">
<image class="icon" :src="i.shortTitleUrl" mode="scaleToFill" />
<!-- <image class="icon" :src="i.shortTitleUrl" mode="scaleToFill" /> -->
<view class="icon">
<view class="sprite-icon icon-tool-pay"></view>
</view>
</template>
<template v-else>
<view class="icon">
......@@ -215,7 +218,18 @@ export default {
flex-direction: column;
align-items: center;
padding-bottom: toRpx(16);
/* 超过 8 个时换列展示 */
&.multi-column {
flex-wrap: wrap;
justify-content: flex-start;
width: toRpx(240);
.item {
width: toRpx(120);
}
}
/* 滚动条隐藏但可滚动 */
&::-webkit-scrollbar {
width: 0;
......@@ -235,40 +249,29 @@ export default {
padding-top: toRpx(20);
padding-bottom: toRpx(12);
position: relative;
/* 列表项快速复位 */
opacity: 0;
transform: translateY(5rpx); /* 减少位移距离,更紧凑 */
transform: translateY(5rpx);
transition: all 0.2s ease;
.icon {
width: toRpx(64);
width: toRpx(64);
height: toRpx(64);
margin-bottom: toRpx(8);
transition: transform 0.2s;
}
&:active {
.icon {
transform: scale(0.9);
}
}
/* 选中态指示器 */
&.active {
color: #2c66f7;
font-weight: 500;
&::after {
content: '';
position: absolute;
right: toRpx(10);
top: 50%;
width: toRpx(6);
height: toRpx(6);
background: #2c66f7;
border-radius: 50%;
}
}
}
}
......
......@@ -9,6 +9,7 @@
"eslint-plugin-prettier": "^5.1.3",
"glsk-toolkit": "1.0.4",
"hammerjs": "^2.0.8",
"jsencrypt": "^3.5.4",
"lodash": "^4.17.21",
"number-precision": "^1.6.0",
"pinyin.js": "^2.0.0",
......
......@@ -16,6 +16,12 @@
}
},
{
"path": "pages/common/selectStore",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "pages/equity/index",
"style": {
"navigationStyle": "custom",
......
# 登录流程说明
## 整体流程
```
登录页面 (login.vue) → 选择门店页面 (selectStore.vue) → 首页 (pages/equity/index)
```
## 任务拆分
### 1. 登录页面 - login.vue
**职责:** 用户输入账号密码,完成初步验证
**流程:**
1. 用户输入账号密码
2. 调用 `loginIn` 接口获取 `access_token` 和 `spCode`
3. 将 `access_token` 存入 `sessionId`(用于后续请求的 Authorization header)
4. 调用 `getStoreList()` 获取门店列表
5. 将登录信息和门店数据传递到选择门店页面
**关键代码位置:**
- 登录方法:`login()` 方法(约 140 行)
- API 调用:`uni.$api.loginApi.loginIn()`、`uni.$api.loginApi.getStoreList()`
**注意事项:**
- `loginIn` 返回的 `access_token` 需要立即存储到 `sessionId`,供后续请求使用
- `getStoreList()` 是 POST 请求,`spCode` 为可选参数
- 登录信息通过 `uni.setStorageSync('loginForm', ...)` 临时存储
- 跳转时传递 `stores` 数据通过 URL 参数
---
### 2. 选择门店页面 - selectStore.vue
**职责:** 展示门店列表,用户选择门店后完成登录
**流程:**
1. 从 URL 参数获取门店列表 `stores`
2. 从 storage 获取登录信息 `loginForm`
3. 用户选择门店(支持搜索过滤)
4. 调用 `confirmLoginStore` 接口确认门店
5. 存储 `confirmLoginStore` 返回的 `user` 对象到 `userInfo`
6. 清理临时登录信息
7. 跳转至首页
**关键代码位置:**
- 门店选择:`selectStore(item)` 方法
- 确认选择:`confirmSelect()` 方法(约 105 行)
- API 调用:`uni.$api.loginApi.confirmLoginStore()`
**注意事项:**
- 如果只有一个门店,自动选中并直接调用 `confirmLoginStore`
- `confirmLoginStore` 返回的 `res.data.user` 需要存储到 `userInfo` 缓存
- 登录成功后需要清理临时存储的 `loginForm`
- 搜索功能通过 `filteredStores` 计算属性实现,支持门店名称和商户号搜索
---
### 3. 首页跳转
**职责:** 登录成功后进入系统首页
**流程:**
1. `selectStore.vue` 中调用 `uni.reLaunch({ url: '/pages/equity/index' })`
2. 首页从 `uni.$storage.get('userInfo')` 获取用户信息
**注意事项:**
- 使用 `reLaunch` 而非 `redirectTo`,确保页面栈干净
- 首页依赖 `userInfo` 中的字段(如 `userName`、`userId` 等)
---
## 接口说明
### loginIn
- **作用:** 账号密码验证,获取临时凭证
- **返回:** `access_token`、`spCode`(在 `spInfo` 对象中)、`role`、`stores`
- **位置:** `api/module/loginApi.js:16-18`
### getStoreList
- **作用:** 获取门店列表
- **参数:** `spCode`(可选)
- **请求方式:** POST
- **返回:** `data.stores` 数组
- **位置:** `api/module/loginApi.js:19-21`
### confirmLoginStore
- **作用:** 确认选择的门店,完成登录
- **参数:** `username`、`password`(加密后)、`spCode`、`storeCode`
- **返回:** `token`、`user` 对象
- **位置:** `api/module/loginApi.js:22-24`
---
## 缓存说明
| 缓存键 | 存储内容 | 存储时机 | 清理时机 |
|--------|----------|----------|----------|
| `sessionId` | `access_token` / 最终 token | `loginIn` 后 / `confirmLoginStore` 后 | 退出登录时 |
| `loginForm` | 临时登录信息(username、password、spCode) | 跳转 selectStore 前 | `confirmLoginStore` 成功后 |
| `userInfo` | 用户信息对象 | `confirmLoginStore` 成功后 | 版本变更/退出登录时 |
---
## 常见问题
### 1. loading 不消失
- 检查每个接口调用后是否调用 `uni.hideLoading()`
- 跳转页面前需要先关闭 loading
### 2. userInfo 类型警告
- 确保存储到 `userInfo` 的是对象,不是字符串
- `confirmLoginStore` 返回的 `res.data.user` 直接存储即可
### 3. 门店选择后未跳转
- 检查 `confirmLoginStore` 是否成功返回
- 确认 `res.data.token` 是否存在
- 检查 `userInfo` 是否正确存储
### 4. 单门店自动跳转不生效
- 检查 `stores.length === 1` 判断
- 确认 `$nextTick` 或异步时机是否正确
<template>
<view class="layout">
<!-- 标题 -->
<view class="header">
<view class="title">选择门店</view>
</view>
<!-- 搜索框 -->
<view class="search-box">
<input
class="search-input"
type="text"
v-model="searchKeyword"
placeholder="请输入门店名称/商户号搜索"
placeholder-class="search-placeholder"
/>
<view class="search-icon">
<uni-icons type="search" size="18" color="#999"></uni-icons>
</view>
</view>
<!-- 门店列表 -->
<view class="store-list">
<view
v-for="(item, index) in filteredStores"
:key="item.id || index"
class="store-item"
:class="{ active: selectedStoreCode === item.storeCode }"
@click="selectStore(item)"
>
<view class="store-icon">
<view class="sprite-icon icon-store"></view>
</view>
<view class="store-info">
<view class="store-name">{{ item.storeName }}</view>
<view class="store-code">商户号:{{ item.spCode || item.storeCode }}</view>
</view>
<view class="selected-icon" v-if="selectedStoreCode === item.storeCode">
<uni-icons type="checkbox-filled" size="24" color="#2C66F7"></uni-icons>
</view>
</view>
</view>
</view>
</template>
<script type="text/ecmascript-6">
export default {
data () {
return {
stores: [],
selectedStoreIndex: -1,
selectedStoreCode: '',
loginForm: {},
searchKeyword: ''
};
},
computed: {
filteredStores () {
if (!this.searchKeyword) {
return this.stores;
}
const keyword = this.searchKeyword.toLowerCase();
return this.stores.filter(item => {
const name = (item.storeName || '').toLowerCase();
const code = (item.spCode || item.storeCode || '').toLowerCase();
return name.includes(keyword) || code.includes(keyword);
});
}
},
onLoad (options) {
// 从参数获取 stores
if (options.stores) {
this.stores = JSON.parse(decodeURIComponent(options.stores));
}
// 从 storage 获取登录信息
const loginForm = uni.getStorageSync('loginForm') || {};
this.loginForm = loginForm;
console.log('selectStore onLoad - stores:', this.stores);
console.log('selectStore onLoad - loginForm:', this.loginForm);
// 如果只有一个门店,直接选中并确认
if (this.stores.length === 1) {
this.selectedStoreCode = this.stores[0].storeCode;
this.confirmSelect();
}
},
methods: {
selectStore (item) {
this.selectedStoreCode = item.storeCode;
this.confirmSelect();
},
confirmSelect () {
if (!this.selectedStoreCode) {
uni.showToast({
title: '请选择门店',
icon: 'none'
});
return;
}
// 从 filteredStores 中找到选中的门店
const selectedStore = this.filteredStores.find(item => item.storeCode === this.selectedStoreCode);
const storeCode = selectedStore.storeCode;
uni.showLoading({
mask: true
});
// 调用 confirmLoginStore 确认门店
uni.$api.loginApi.confirmLoginStore({
username: this.loginForm.username,
password: this.loginForm.password,
spCode: this.loginForm.spCode,
storeCode
}).then(async res => {
if (!res || !res.data) {
return Promise.reject('确认门店失败');
}
const token = res.data.token || res.data.sessionId || res.data.access_token;
if (!token) return Promise.reject('登录失败:未获取到 token');
// 存储最终 token
uni.$storage.set('sessionId', token);
// 存储用户信息(从 confirmLoginStore 返回的 loginUser 对象)
const userInfo = res.data.loginUser || {};
uni.$storage.set('userInfo', userInfo);
// 如果勾选了 30 天免登,调用 saveLoginInfo 保存登录信息
if (this.loginForm.noSignIn) {
// 存储 noSignInUuid,用于 401 时恢复登录
uni.$storage.set('noSignInUuid', this.loginForm.username);
try {
await uni.$api.loginApi.saveLoginInfo({});
} catch (e) {
uni.$logger.local.error(`saveLoginInfo 失败:${e?.message || e}`);
}
}
// 清理临时登录信息
uni.removeStorageSync('loginForm');
uni.$logger.local.info(`${this.loginForm.username}登录成功`);
// 跳转至首页
uni.hideLoading();
uni.reLaunch({
url: '/pages/equity/index'
});
}).catch(error => {
uni.$logger.local.error(`确认门店失败:${error?.message || error}`);
uni.hideLoading();
uni.showToast({
title: error?.message || error || '确认失败',
icon: 'none'
});
});
}
}
};
</script>
<style lang="scss" scoped>
.layout {
min-height: 100vh;
background: linear-gradient(180deg, #F5F7FA 0%, #E8EEF7 100%);
padding: toRpx(40);
box-sizing: border-box;
}
/* 标题 */
.header {
padding: toRpx(40) 0 toRpx(30);
text-align: center;
.title {
font-size: toRpx(36);
font-weight: 600;
color: #333;
}
}
/* 搜索框 */
.search-box {
position: relative;
background: #fff;
border-radius: toRpx(56);
padding: toRpx(24) toRpx(32);
margin-bottom: toRpx(40);
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
.search-input {
width: 100%;
font-size: toRpx(28);
color: #333;
}
.search-placeholder {
color: #999;
}
.search-icon {
position: absolute;
right: toRpx(32);
top: 50%;
transform: translateY(-50%);
}
}
/* 门店列表 */
.store-list {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: toRpx(24);
padding-bottom: toRpx(40);
.store-item {
background: #fff;
border-radius: toRpx(24);
padding: toRpx(32);
display: flex;
align-items: center;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
transition: all 0.2s ease;
position: relative;
&.active {
border: 2rpx solid #2C66F7;
box-shadow: 0 4rpx 20rpx rgba(44, 102, 247, 0.15);
}
.store-icon {
background: linear-gradient(135deg, #E8EEF7 0%, #D0D9F5 100%);
border-radius: toRpx(16);
display: flex;
align-items: center;
justify-content: center;
margin-right: toRpx(20);
flex-shrink: 0;
.sprite-icon {
display: flex;
align-items: center;
justify-content: center;
}
}
.store-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
justify-content: center;
.store-name {
font-size: toRpx(28);
font-weight: 500;
color: #333;
margin-bottom: toRpx(8);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.store-code {
font-size: toRpx(22);
color: #999;
}
}
.selected-icon {
display: flex;
align-items: center;
}
}
}
</style>
......@@ -74,18 +74,23 @@ export default {
return false
},
async onLoad () {
const mockdata = await uni.$api.systemApi.getMockData(true)
// 调用接口获取业务类型列表,取第一个作为默认业务类型
const res = await uni.$api.commonApi.getPadBusinessTypeList()
const typeList = Array.isArray(res?.data) ? res.data : []
const firstType = typeList[0] || {}
// 存储业务类型信息
uni.$storage.set('typeItem', {
typeCode: mockdata?.typeCode || '',
typeName: mockdata?.typeName || ''
typeCode: firstType?.typeCode || '',
typeName: firstType?.typeName || ''
})
await Promise.all([
this.getHomeSource(mockdata?.typeCode),
this.getSource(mockdata?.typeCode)
this.getHomeSource(firstType?.typeCode),
this.getSource(firstType?.typeCode)
])
// 确保初始化时清空id,保证显示首页
// 确保初始化时清空 id,保证显示首页
this.id = ''
},
async onShow () {
......@@ -95,12 +100,12 @@ export default {
...mapMutations('audio', ['setReceptionStatus']),
...mapMutations('material', ['setMaterial']),
...mapActions(['clearCustomerInfo', 'clearHistory', 'clearReceptionTrack']),
init () {
if (this.requested && !this.id) this.homeRef?.updateApp()
},
// 查询素材(优化版:减少循环中的await)
// 查询素材(优化版:减少循环中的 await)
async getSource (typeCode) {
const first_res = await uni.$api.commonApi.getPadFolderList({
typeCode,
......@@ -110,28 +115,28 @@ export default {
if (!this.folderList.length) return this.resetLists()
// 并行请求所有文件夹内容
const folderPromises = this.folderList.map(folder =>
const folderPromises = this.folderList.map(folder =>
uni.$api.commonApi.getPadMaterialList({
folderCode: folder.folderCode,
typeCode: folder.typeCode,
status: 0
})
)
const results = await Promise.all(folderPromises)
// 找到第一个有数据的文件夹
const validResult = results.find(res => Array.isArray(res?.data) && res.data.length > 0)
if (!validResult) return this.resetLists()
this.processMaterials(validResult.data)
},
resetLists() {
this.moduleList = []
this.toolList = []
},
processMaterials(materials) {
this.moduleList = Object.freeze(materials.map(item => ({
...item,
......@@ -146,7 +151,7 @@ export default {
detailUrl: item.materialUrl
}
})))
this.toolList = Object.freeze(materials.map(item => ({
...item,
shortTitle: item.materialName,
......@@ -164,43 +169,43 @@ export default {
})
this.homeList = Object.freeze(Array.isArray(res?.data) ? res.data : [])
},
changeType () {
const typeItem = uni.$storage.get('typeItem')
const typeCode = typeItem?.typeCode || ''
this.getHomeSource(typeCode)
this.getSource(typeCode)
},
async start (item) {
if (!this.moduleList.length) return uni.showToast({
title: '该场景尚未配置素材,请联系总部人员',
icon: 'none'
})
const isPermision = await this.homeRef.isPermission()
if (this.recording || !isPermision) return
const material = this.moduleList[0]
this.setMaterial(material)
await this.homeRef.startAudio()
this.clearAllHistory()
this.id = +material.id
this.type = 'edit'
this.recording = true
},
toDetail (index) {
this.chooseItem = this.moduleList[index]
this.previewRef?.open()
},
cancel () {
this.previewRef?.close()
},
preview () {
let { id, title } = this.chooseItem
this.type = 'preview'
......@@ -208,7 +213,7 @@ export default {
uni.$logger.local.info(`预览${title}`)
this.cancel()
},
// 完成接待
done (e) {
this.finishRef?.close()
......@@ -221,7 +226,7 @@ export default {
this.clearAllHistory()
}, 1500)
},
back () {
const detailRef = this.$refs.detail
if (detailRef?.showPayPage) return (detailRef.showPayPage = false)
......@@ -229,7 +234,7 @@ export default {
if (this.type != 'preview') return this.finishRef?.open()
this.backHome()
},
backHome () {
if (this.recording) this.homeRef?.stopAudio(true)
this.finishRef?.close()
......@@ -238,24 +243,24 @@ export default {
this.clearAllHistory()
this.recording = false
},
nextStep () {
let { id } = this.moduleList[0]
this.type = 'preview'
this.id = id
},
clearAllHistory () {
this.clearCustomerInfo()
this.clearHistory()
this.clearReceptionTrack()
},
openStep () {
this.finishRef?.close()
this.$refs.detail?.open()
},
changeTab (index) {
// if (index == 0) this.init()
}
......
// Token 管理工具
const TokenKey = 'sessionId'
export function getToken() {
return uni.$storage.get(TokenKey)
}
export function setToken(token) {
return uni.$storage.set(TokenKey, token)
}
export function removeToken() {
return uni.$storage.set(TokenKey, '')
}
// RSA 加密
import JSEncrypt from 'jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
// 使用 glsx-scrm 的公钥
const publicKey =
'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='
const privateKey =
'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsHourNxaY\n' +
'7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
'UP8iWi1Qw0Y='
// 加密
export function encrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPublicKey(publicKey) // 设置公钥
return encryptor.encrypt(txt) // 对数据进行加密
}
// 解密
export function decrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPrivateKey(privateKey) // 设置私钥
return encryptor.decrypt(txt) // 对数据进行解密
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!