注册调整
This commit is contained in:
parent
0c0d5e55d5
commit
b53dc2dd4f
@ -4,9 +4,10 @@ VITE_APP_TITLE='uniapp-vue3-project'
|
||||
# 开发环境配置
|
||||
VITE_APP_ENV='development'
|
||||
|
||||
VITE_APP_ID='wx92e663dc11d0c0a8'
|
||||
|
||||
# 接口地址
|
||||
VITE_APP_BASE_API='https://apidev.lakeapp.cn/'
|
||||
#VITE_APP_BASE_API='https://api.lakeapp.cn/'
|
||||
|
||||
# 删除console
|
||||
VITE_DROP_CONSOLE=false
|
||||
|
@ -4,6 +4,8 @@ VITE_APP_TITLE='uniapp-vue3-project'
|
||||
# 生产环境配置
|
||||
VITE_APP_ENV='production'
|
||||
|
||||
VITE_APP_ID='wx67a750d0ceed4d88'
|
||||
|
||||
# 接口地址
|
||||
VITE_APP_BASE_API='https://api.lakeapp.cn/'
|
||||
|
||||
|
14
.env.test
14
.env.test
@ -1,11 +1,17 @@
|
||||
# 页面标题
|
||||
VITE_APP_TITLE='uniapp-vue3-project'
|
||||
|
||||
# 生产环境配置
|
||||
VITE_APP_ENV='production'
|
||||
# 开发环境配置
|
||||
VITE_APP_ENV='test'
|
||||
|
||||
VITE_APP_ID='wx92e663dc11d0c0a8'
|
||||
|
||||
# 接口地址
|
||||
VITE_APP_BASE_API='/'
|
||||
#VITE_APP_BASE_API='https://apidev.lakeapp.cn/'
|
||||
VITE_APP_BASE_API='https://api.lakeapp.cn/'
|
||||
|
||||
# 删除console
|
||||
VITE_DROP_CONSOLE=true
|
||||
VITE_DROP_CONSOLE=false
|
||||
|
||||
# 是否开启Mock
|
||||
VITE_USE_MOCK=true
|
||||
|
@ -14,7 +14,7 @@ const WX_DESC = envType == 'production' ? '正式环境' : '测试环境'
|
||||
(async () => {
|
||||
// @ts-ignore
|
||||
const manifest = path.resolve(__dirname, './src/manifest.json')
|
||||
console.log(manifest)
|
||||
|
||||
// @ts-ignore
|
||||
const manifestConfig = JSON.parse(fs.readFileSync(manifest).toString())
|
||||
const appId = manifestConfig['mp-weixin'].appid
|
||||
|
40
manifest.modify.ts
Normal file
40
manifest.modify.ts
Normal file
@ -0,0 +1,40 @@
|
||||
// @ts-ignore
|
||||
const fs = require('fs');
|
||||
// @ts-ignore
|
||||
const path = require('path');
|
||||
|
||||
const currentDir = path.dirname(__filename);
|
||||
const manifestPath = path.join(currentDir, 'src/manifest.json');
|
||||
|
||||
const VITE_APP_WX_APPID = process.env.NODE_ENV === 'production' ? 'wx67a750d0ceed4d88' : 'wx92e663dc11d0c0a8';
|
||||
fs.readFile(manifestPath, (err, data) => {
|
||||
if(err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
try {
|
||||
if(!VITE_APP_WX_APPID) {
|
||||
console.log('写入失败,没读到appid');
|
||||
return;
|
||||
}
|
||||
const _data = JSON.parse(data.toString());
|
||||
_data['mp-weixin'].appid = VITE_APP_WX_APPID;
|
||||
const newData = JSON.stringify(_data, null, 2);
|
||||
fs.writeFile(
|
||||
manifestPath,
|
||||
newData,
|
||||
{
|
||||
encoding: 'utf-8'
|
||||
},
|
||||
(err) => {
|
||||
if(err) {
|
||||
console.log('写入失败', err);
|
||||
} else {
|
||||
console.log('写入成功');
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (parseError) {
|
||||
console.error('解析 manifest.json 失败', parseError);
|
||||
}
|
||||
}
|
||||
});
|
26
package.json
26
package.json
@ -4,8 +4,10 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "uni -p mp-weixin",
|
||||
"build:test": "uni build --mode test -p mp-weixin",
|
||||
"build:prod": "uni build --mode production -p mp-weixin",
|
||||
"dev:test": "cross-env NODE_ENV=development node manifest.modify.ts && uni -p mp-weixin --mode development",
|
||||
"dev:prod": "cross-env NODE_ENV=production node manifest.modify.ts && uni -p mp-weixin --mode production",
|
||||
"build:test": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build --mode test",
|
||||
"build:prod": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build --mode production",
|
||||
"deploy:test": "uni build --mode test -p mp-weixin && node deploy.ts test",
|
||||
"deploy:prod": "uni build --mode production -p mp-weixin && node deploy.ts production",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
@ -15,10 +17,10 @@
|
||||
"postinstall": "simple-git-hooks"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-app-plus": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-components": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-app": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/uni-app-plus": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/uni-components": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-4010520240507001",
|
||||
"dayjs": "^1.11.10",
|
||||
"pinia": "2.0.36",
|
||||
"pinia-plugin-persistedstate": "^3.2.1",
|
||||
@ -29,11 +31,11 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "1.1.0",
|
||||
"@dcloudio/types": "^3.4.3",
|
||||
"@dcloudio/uni-automator": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
|
||||
"@dcloudio/uni-stacktracey": "3.0.0-4000820240401001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-4000820240401001",
|
||||
"@dcloudio/types": "^3.4.8",
|
||||
"@dcloudio/uni-automator": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/uni-stacktracey": "3.0.0-alpha-4010520240507001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4010520240507001",
|
||||
"@types/node": "^20.10.3",
|
||||
"@typescript-eslint/parser": "^6.13.1",
|
||||
"@uni-helper/uni-app-types": "^0.5.12",
|
||||
@ -59,7 +61,7 @@
|
||||
"unocss-applet": "^0.7.8",
|
||||
"unplugin-auto-import": "^0.16.7",
|
||||
"unplugin-vue-components": "^0.25.2",
|
||||
"vite": "^4.5.3",
|
||||
"vite": "^5.2.8",
|
||||
"vite-plugin-imagemin": "^0.6.1",
|
||||
"vue-tsc": "^1.8.24"
|
||||
},
|
||||
|
2415
pnpm-lock.yaml
2415
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
20
src/App.vue
20
src/App.vue
@ -12,7 +12,7 @@ export default {
|
||||
const env = miniProgram.envVersion;
|
||||
|
||||
//生产
|
||||
if(env === 'release' || env === 'trial') {
|
||||
if(env === 'release') {
|
||||
logger.info(`launch options ${env}: `, options);
|
||||
|
||||
async function getVersionStatus() {
|
||||
@ -42,13 +42,19 @@ export default {
|
||||
|
||||
//测试、开发 trial,develop
|
||||
else {
|
||||
// setCompanyId('1724629180555919361');
|
||||
// setRegisterStoreId('1725026299888406529');
|
||||
// setCompanyId('1471673498334113794');
|
||||
// setRegisterStoreId('1471673498413805570');
|
||||
//生产环境
|
||||
if(import.meta.env.VITE_APP_BASE_API.includes('api.lakeapp')) {
|
||||
setCompanyId('1150930317231112193');
|
||||
setRegisterStoreId('1150930317436633090');
|
||||
|
||||
setCompanyId('1150930317231112193');
|
||||
setRegisterStoreId('1150930317436633090');
|
||||
// setCompanyId('1471673498334113794');
|
||||
// setRegisterStoreId('1471673498413805570');
|
||||
}
|
||||
//测试
|
||||
else {
|
||||
setCompanyId('1724629180555919361');
|
||||
setRegisterStoreId('1725026299888406529');
|
||||
}
|
||||
}
|
||||
|
||||
if(options?.query) {
|
||||
|
@ -10,6 +10,7 @@ enum URL {
|
||||
login = '/wc/wechat/LoginByMa',
|
||||
loginByCode = '/wc/wechat/LoginByMaCode',
|
||||
register = '/wc/wechat/register',
|
||||
telephone = '/wc/wechat/telephone',
|
||||
uploadAvatar = '/wc/wechat/uploadImage',
|
||||
logout = '/user/logout',
|
||||
// profile = '/user/profile',
|
||||
@ -42,6 +43,8 @@ export const updateProfile = (data: any) => post<any>({ url: URL.updateProfile,
|
||||
export const login = (data: LoginParams) => post<LoginResult>({ url: URL.login, data });
|
||||
export const loginByCode = (code: string, companyId: string) => post<any>({ url: URL.loginByCode + `?code=${code}` });
|
||||
|
||||
export const getTelephone = (data: any) => post<any>({ url: URL.telephone, data });
|
||||
|
||||
export const register = (data: RegisterParams) => post<LoginResult>({ url: URL.register, data });
|
||||
|
||||
export const logout = () => post<any>({ url: URL.logout });
|
||||
|
@ -18,8 +18,7 @@
|
||||
"modules": {}
|
||||
},
|
||||
"mp-weixin": {
|
||||
// "appid": "wx92e663dc11d0c0a8",
|
||||
"appid": "wx67a750d0ceed4d88",
|
||||
"appid": "wx67a750d0ceed4d88",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
@ -41,4 +40,4 @@
|
||||
"base": "/uniapp-vue3-template/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
<script setup lang='ts'>
|
||||
import { useUserStore } from '@/store';
|
||||
import { assetsUrl } from '@/utils/assets';
|
||||
import { showToast } from '@/utils';
|
||||
import { getRegisterStoreId, showToast } from '@/utils';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const isAgreePrivacy = ref(false);
|
||||
@ -36,14 +36,24 @@ async function wechatLogin() {
|
||||
showToast('请先阅读并同意小程序隐私保护协议');
|
||||
return;
|
||||
}
|
||||
await uni.showLoading();
|
||||
const result = await userStore.login();
|
||||
uni.hideLoading();
|
||||
if(result) {
|
||||
await uni.reLaunch({ url: '/pages/home/index' });
|
||||
} else {
|
||||
await uni.navigateTo({ url: '/pages/common/register/index' });
|
||||
|
||||
if(!getRegisterStoreId()) {
|
||||
showToast('请从公众号消息窗口点击店名打开小程序');
|
||||
return;
|
||||
}
|
||||
|
||||
userStore.login().then(() => {
|
||||
uni.hideLoading();
|
||||
uni.reLaunch({ url: '/pages/home/index' });
|
||||
});
|
||||
// await uni.showLoading();
|
||||
// const result = await userStore.login();
|
||||
// uni.hideLoading();
|
||||
// if(result) {
|
||||
// await uni.reLaunch({ url: '/pages/home/index' });
|
||||
// } else {
|
||||
// await uni.navigateTo({ url: '/pages/common/register/index' });
|
||||
// }
|
||||
}
|
||||
|
||||
const bindCheck = () => {
|
||||
|
@ -1,182 +1,202 @@
|
||||
<template>
|
||||
<view class='content'>
|
||||
<image class='bg-image' :src='assetsUrl("bg_register.png")' />
|
||||
<image :src='assetsUrl("ic_register_gift_text.png")'
|
||||
style='align-self: center;position: relative;width: 356rpx;height: 124rpx;margin-top: 70rpx' />
|
||||
|
||||
<view class='card-view'>
|
||||
<view class='mobile-view c-flex-row' >
|
||||
<image :src='assetsUrl("ic_register_mobile.png")' />
|
||||
<input placeholder='请输入手机号' inputmode='number' maxLength='11' />
|
||||
</view>
|
||||
|
||||
<view class='captcha-view c-flex-row' style='display: none'>
|
||||
<view class='c-flex-row'>
|
||||
<image :src='assetsUrl("ic_register_captcha.png")' />
|
||||
<input placeholder='请输入验证码' inputmode='number' maxLength='6' />
|
||||
</view>
|
||||
<text @click.stop='startCountdown'>{{ countdown }}</text>
|
||||
</view>
|
||||
|
||||
<text class='btn_register' @click.stop='register'>注册领券</text>
|
||||
<view class='c-flex-column avatar-container'>
|
||||
<image class='avatar' :src='avatarUrl' />
|
||||
<button class='avatar-button' open-type='chooseAvatar' @chooseavatar='chooseAvatar' />
|
||||
</view>
|
||||
<view class='c-flex-row' style='margin-top: 60rpx'>
|
||||
<label class='row-title'>姓名</label>
|
||||
<input class='row-value' type='nickname' placeholder='请输入手机号' v-model='nickName' />
|
||||
</view>
|
||||
<view class='divider' />
|
||||
<view class='c-flex-row'>
|
||||
<label class='row-title'>手机号</label>
|
||||
<input class='row-value' placeholder='请输入手机号' type='text' v-model='telephone' />
|
||||
<button class='primary-button authorize-button' open-type='getPhoneNumber' @getphonenumber='getPhoneNumber'>
|
||||
获取手机号
|
||||
</button>
|
||||
</view>
|
||||
<view class='divider' />
|
||||
<view class='c-flex-row'>
|
||||
<label class='row-title'>生日</label>
|
||||
<picker mode='date' @change='changeDate'>
|
||||
<text class='row-value'>{{ dayjs(birthday).format('YYYY-MM-DD') || '请选择生日' }}</text>
|
||||
</picker>
|
||||
</view>
|
||||
<view class='divider' />
|
||||
<view class='c-flex-row'>
|
||||
<label class='row-title'>性别</label>
|
||||
<view class='c-flex-row' @click.stop='changeGender(0)'>
|
||||
<image class='gender-image'
|
||||
:src='assetsUrl(gender==="男"?"ic_checkbox_active.png":"ic_checkbox_normal.png")' />
|
||||
<text class='gender-text'>男</text>
|
||||
</view>
|
||||
<view class='c-flex-row' @click.stop='changeGender(1)'>
|
||||
<image class='gender-image'
|
||||
:src='assetsUrl(gender==="女"?"ic_checkbox_active.png":"ic_checkbox_normal.png")' />
|
||||
<text class='gender-text'>女</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view style='height: 100rpx' />
|
||||
<button class='primary-button submit-button' @click='save'>确定</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang='ts' setup>
|
||||
import { assetsUrl } from '@/utils/assets';
|
||||
import { ref } from 'vue';
|
||||
import { getTelephone } from '@/api/user';
|
||||
import { useUserStore } from '@/store';
|
||||
import { getRegisterCoupon } from '@/api/user';
|
||||
import { assetsUrl } from '@/utils/assets';
|
||||
import { getSessionKey, showToast } from '@/utils';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { companyConfigInfo } = storeToRefs(userStore);
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
|
||||
const countdown = ref('获取验证码');
|
||||
const couponBean = ref();
|
||||
const birthday = ref(userInfo.value.birthday);
|
||||
const nickName = ref(userInfo.value.nickName);
|
||||
const gender = ref(userInfo.value.gender);
|
||||
const telephone = ref(userInfo.value.telephone);
|
||||
const avatarUrl = ref(userInfo.value.image);
|
||||
|
||||
onLoad(async (e) => {
|
||||
couponBean.value = await getRegisterCoupon();
|
||||
});
|
||||
|
||||
const startCountdown = () => {
|
||||
if(countdown.value !== '获取验证码') {
|
||||
return;
|
||||
}
|
||||
let time = 120;
|
||||
let interval = setInterval(() => {
|
||||
time--;
|
||||
countdown.value = `${time}s 重新获取`;
|
||||
if(time == 0) {
|
||||
clearInterval(interval);
|
||||
countdown.value = '获取验证码';
|
||||
const chooseAvatar = (e: any) => {
|
||||
uni.showLoading();
|
||||
uni.uploadFile({
|
||||
url: import.meta.env.VITE_APP_BASE_API + '/wc/wechat/uploadImage',
|
||||
filePath: e.detail.avatarUrl,
|
||||
name: 'fileName',
|
||||
header: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
success: (res: any) => {
|
||||
avatarUrl.value = JSON.parse(res.data).data;
|
||||
},
|
||||
error: (err: any) => {
|
||||
showToast('上传失败');
|
||||
},
|
||||
complete() {
|
||||
uni.hideLoading();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
};
|
||||
|
||||
const register = () => {
|
||||
const getPhoneNumber = (e: any) => {
|
||||
if(e.detail.errMsg === 'getPhoneNumber:ok') {
|
||||
uni.login({
|
||||
success: res => {
|
||||
getTelephone({
|
||||
sessionKey: getSessionKey(),
|
||||
code: res.code,
|
||||
iv: e.detail.iv,
|
||||
encryptedData: e.detail.encryptedData
|
||||
}).then(response => {
|
||||
if(response.phoneNumber) {
|
||||
telephone.value = response.phoneNumber;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const changeDate = (e: any) => {
|
||||
birthday.value = e.detail.value;
|
||||
};
|
||||
|
||||
const changeGender = (index: number) => {
|
||||
gender.value = index === 0 ? '男' : '女';
|
||||
};
|
||||
|
||||
const save = async () => {
|
||||
await uni.showLoading();
|
||||
const registerForm = {
|
||||
image: avatarUrl.value,
|
||||
avatarUrl: avatarUrl.value,
|
||||
nickName: nickName.value,
|
||||
telephone: telephone.value,
|
||||
birthday: birthday.value,
|
||||
gender: gender.value
|
||||
};
|
||||
|
||||
getApp().globalData?.logger.info('register params: ', registerForm);
|
||||
const result = await userStore.register(registerForm);
|
||||
getApp().globalData?.logger.info('register params: ', registerForm);
|
||||
if(result) {
|
||||
showToast('注册成功');
|
||||
await uni.reLaunch({
|
||||
url: '/pages/home/index'
|
||||
});
|
||||
}
|
||||
uni.hideLoading();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
.content {
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.bg-image {
|
||||
position: fixed;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.card-view {
|
||||
background: #FFFFFF;
|
||||
border-radius: 10rpx;
|
||||
margin: 0 40rpx;
|
||||
padding: 50rpx;
|
||||
top: 150rpx;
|
||||
position: relative;
|
||||
|
||||
.mobile-view {
|
||||
border-radius: 10rpx;
|
||||
border: 1rpx solid #D8D8D8;
|
||||
padding-left: 28rpx;
|
||||
|
||||
image {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
}
|
||||
|
||||
input {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
font-size: 30rpx;
|
||||
color: #333333;
|
||||
margin-left: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.captcha-view {
|
||||
margin-top: 20rpx;
|
||||
|
||||
.c-flex-row {
|
||||
border-radius: 10rpx;
|
||||
border: 1rpx solid #D8D8D8;
|
||||
padding-left: 28rpx;
|
||||
flex: 1;
|
||||
|
||||
image {
|
||||
width: 33rpx;
|
||||
height: 26rpx;
|
||||
}
|
||||
|
||||
input {
|
||||
height: 80rpx;
|
||||
font-size: 30rpx;
|
||||
color: #333333;
|
||||
margin-left: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
text {
|
||||
display: flex;
|
||||
height: 80rpx;
|
||||
background: #FFD436;
|
||||
border-radius: 10rpx;
|
||||
margin-left: 12rpx;
|
||||
padding: 0 15rpx;
|
||||
font-size: 28rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
.btn_register {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 90rpx;
|
||||
background: #F53636;
|
||||
border-radius: 10rpx;
|
||||
font-weight: 400;
|
||||
font-size: 30rpx;
|
||||
color: #FFFFFF;
|
||||
margin-top: 46rpx;
|
||||
}
|
||||
display: flex;
|
||||
background: white;
|
||||
padding: 30rpx;
|
||||
|
||||
.divider {
|
||||
border-bottom-style: dashed;
|
||||
border-color: #E98585;
|
||||
border-width: 0.2rpx;
|
||||
margin-top: 34rpx
|
||||
margin: 30rpx 5rpx;
|
||||
}
|
||||
|
||||
.coupon {
|
||||
margin-top: 30rpx;
|
||||
.row-title {
|
||||
font-size: 30rpx;
|
||||
color: #666666;
|
||||
width: 150rpx;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
display: flex;
|
||||
font-size: 36rpx;
|
||||
color: #D95554;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
image {
|
||||
width: 13rpx;
|
||||
height: 24rpx;
|
||||
}
|
||||
|
||||
.expired-time {
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
margin-top: 2rpx;
|
||||
}
|
||||
.row-value {
|
||||
font-size: 30rpx;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar-container {
|
||||
align-items: center;
|
||||
margin-top: 20rpx;
|
||||
position: relative;
|
||||
|
||||
.avatar {
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
border-radius: 10rpx;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.avatar-button {
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
background-color: transparent;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.authorize-button {
|
||||
width: auto;
|
||||
font-size: 20rpx;
|
||||
min-width: auto;
|
||||
height: 50rpx;
|
||||
}
|
||||
|
||||
.gender-image {
|
||||
width: 37rpx;
|
||||
height: 37rpx;
|
||||
}
|
||||
|
||||
.gender-text {
|
||||
width: 80rpx;
|
||||
color: #333333;
|
||||
font-size: 30rpx;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
.submit-button {
|
||||
display: flex;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
@ -139,7 +139,7 @@ onShow(async () => {
|
||||
|
||||
const switchCompany = () => {
|
||||
fetchCompanyList((companyList: any[], userList: any[]) => {
|
||||
companyDialogRef.value.show(getCompanyId(),(index: number) => {
|
||||
companyDialogRef.value.show(getCompanyId(), (index: number) => {
|
||||
userStore.setUserInfo(userList[index]);
|
||||
userStore.setCompanyInfo(companyList[index]);
|
||||
});
|
||||
@ -155,8 +155,11 @@ const fetchCompanyList = (fn: any = undefined) => {
|
||||
fn(companyList.value, userList.value);
|
||||
} else {
|
||||
let index = companyList.value.findIndex((res: { id: string }) => res.id === getCompanyId());
|
||||
|
||||
//未在当前公司下注册
|
||||
if(index < 0) {
|
||||
index = 0;
|
||||
goPath('/pages/common/register/index');
|
||||
return;
|
||||
}
|
||||
userStore.setUserInfo(userList.value[index]);
|
||||
userStore.setCompanyInfo(companyList.value[index]);
|
||||
|
@ -199,6 +199,7 @@ const showOfficialAccountDialog = () => {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.top-row {
|
||||
|
@ -48,7 +48,7 @@
|
||||
<view class='c-flex-row'>
|
||||
<text>生日</text>
|
||||
<picker mode='date' :disabled='(userInfo.birthday?.length||0)!=0' @change='changeDate'>
|
||||
<text>{{ params?.birthday || '请选择生日' }}</text>
|
||||
<text>{{ dayjs(params?.birthday).format('YYYY-MM-DD') || '请选择生日' }}</text>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import type { providerType, UserBean } from './types';
|
||||
import { getTerminal, getUserProfile, login, logout as userLogout, register } from '@/api/user/index';
|
||||
import { clearToken, getRegisterStoreId, setCompanyId, setToken } from '@/utils/auth';
|
||||
import type { LoginResult, RegisterParams, TerminalBean } from '@/api/user/types';
|
||||
import { clearToken, getCompanyId, getRegisterStoreId, setCompanyId, setSessionKey, setToken } from '@/utils/auth';
|
||||
import type { RegisterParams, TerminalBean } from '@/api/user/types';
|
||||
import { getCompanyInfo } from '@/api/company';
|
||||
|
||||
const useUserStore = defineStore('user', {
|
||||
@ -47,10 +47,6 @@ const useUserStore = defineStore('user', {
|
||||
},
|
||||
|
||||
getters: {
|
||||
// getUserInfo(state: UserBean): UserBean {
|
||||
// return { state };
|
||||
// }
|
||||
|
||||
getUserDiscount(): number {
|
||||
if(this.userInfo?.levelEntity?.discount > 0 && this.userInfo?.levelEntity?.discount < 10) {
|
||||
return this.userInfo?.levelEntity?.discount / 10;
|
||||
@ -66,108 +62,7 @@ const useUserStore = defineStore('user', {
|
||||
},
|
||||
|
||||
actions: {
|
||||
// 设置用户的信息
|
||||
async setUserInfo(partial: Partial<UserBean>) {
|
||||
this.userInfo = partial as UserBean;
|
||||
// this.userInfo.levelEntity?.discount = 79;
|
||||
// this.userInfo.salePrice = 'price_ext';
|
||||
if(this.userInfo) {
|
||||
this.userInfo.userDiscount = this.getUserDiscount;
|
||||
await setCompanyId(this.userInfo.companyId);
|
||||
} else {
|
||||
await clearToken();
|
||||
}
|
||||
await this.fetchTerminal();
|
||||
await this.fetchCompanyInfo();
|
||||
},
|
||||
|
||||
setCompanyInfo(partial: Partial<any>) {
|
||||
this.companyInfo = partial as any;
|
||||
},
|
||||
|
||||
setDeliveryAddress(partial: Partial<any>) {
|
||||
this.deliveryAddress = partial as any;
|
||||
},
|
||||
|
||||
// 重置用户信息
|
||||
resetInfo() {
|
||||
this.$reset();
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
async getProfile() {
|
||||
const result = await getUserProfile();
|
||||
await this.setUserInfo(result);
|
||||
},
|
||||
|
||||
async fetchCompanyInfo() {
|
||||
this.companyConfigInfo = await getCompanyInfo();
|
||||
},
|
||||
|
||||
async checkUserRegisterStatus() {
|
||||
const userBean = await this.login();
|
||||
return !!userBean;
|
||||
},
|
||||
|
||||
userRegister(registerForm: RegisterParams) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const result = await register(registerForm);
|
||||
resolve(result);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Logout
|
||||
async logout() {
|
||||
await userLogout();
|
||||
this.resetInfo();
|
||||
clearToken();
|
||||
},
|
||||
|
||||
async login() {
|
||||
return new Promise<UserBean>((resolve, reject) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (result: UniApp.LoginRes) => {
|
||||
if(result.code) {
|
||||
const wechatUserInfo = await uni.getUserInfo();
|
||||
const userInfo = {
|
||||
...wechatUserInfo.userInfo,
|
||||
encryptedData: wechatUserInfo?.encryptedData,
|
||||
rawData: JSON.parse(wechatUserInfo?.rawData),
|
||||
signature: wechatUserInfo?.signature,
|
||||
iv: wechatUserInfo.iv
|
||||
};
|
||||
getApp().globalData?.logger.info('login params: ', userInfo);
|
||||
const res = await login({
|
||||
code: result.code,
|
||||
userInfo: userInfo,
|
||||
storeId: getRegisterStoreId()
|
||||
// referrerUserId: '1727303781559697409'
|
||||
// referrerUserId: getReferrerUserId()
|
||||
});
|
||||
if(res.token) {
|
||||
setToken(res.token);
|
||||
}
|
||||
if(res.user) {
|
||||
await this.getProfile();
|
||||
resolve(res.user);
|
||||
} else {
|
||||
reject(res);
|
||||
}
|
||||
} else {
|
||||
reject(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 小程序授权登录
|
||||
authLogin(provider: providerType = 'weixin') {
|
||||
login(provider: providerType = 'weixin') {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
provider,
|
||||
@ -191,31 +86,33 @@ const useUserStore = defineStore('user', {
|
||||
});
|
||||
getApp().globalData?.logger.info('login result: ', res);
|
||||
|
||||
if(res.user == undefined || res.user.id === null) {
|
||||
const registerForm = {
|
||||
unionId: res.user?.unionId,
|
||||
openId: res.user?.openId,
|
||||
maOpenId: res.user?.maOpenId,
|
||||
image: res.user?.image,
|
||||
nickName: res.user?.nickName,
|
||||
telephone: res.user?.telephone,
|
||||
birthday: res.user?.birthday,
|
||||
companyId: res.user?.companyId,
|
||||
creatorId: res.user?.creatorId,
|
||||
gender: res.user?.gender,
|
||||
storeId: getRegisterStoreId()
|
||||
};
|
||||
getApp().globalData?.logger.info('register params: ', registerForm);
|
||||
const registerResult = await this.userRegister(registerForm);
|
||||
getApp().globalData?.logger.info('register result: ', registerResult);
|
||||
if(registerResult != null) {
|
||||
setToken(res.token);
|
||||
await this.setUserInfo(registerResult as LoginResult);
|
||||
}
|
||||
} else {
|
||||
setToken(res.token);
|
||||
await this.setUserInfo(res.user);
|
||||
}
|
||||
// if(res.user === undefined || res.user.id === null) {
|
||||
// const registerForm = {
|
||||
// unionId: res.user?.unionId,
|
||||
// openId: res.user?.openId,
|
||||
// maOpenId: res.user?.maOpenId,
|
||||
// image: res.user?.image,
|
||||
// nickName: res.user?.nickName,
|
||||
// telephone: res.user?.telephone,
|
||||
// birthday: res.user?.birthday,
|
||||
// companyId: res.user?.companyId,
|
||||
// creatorId: res.user?.creatorId,
|
||||
// gender: res.user?.gender,
|
||||
// storeId: getRegisterStoreId()
|
||||
// };
|
||||
// getApp().globalData?.logger.info('register params: ', registerForm);
|
||||
// const registerResult = await this.userRegister(registerForm);
|
||||
// getApp().globalData?.logger.info('register result: ', registerResult);
|
||||
// if(registerResult != null) {
|
||||
// setToken(res.token);
|
||||
// setSessionKey(res.sessionKey);
|
||||
// await this.setUserInfo(registerResult as LoginResult);
|
||||
// }
|
||||
// } else {
|
||||
setToken(res.token);
|
||||
setSessionKey(res.sessionKey);
|
||||
await this.setUserInfo(res.user);
|
||||
// }
|
||||
resolve(res);
|
||||
} else {
|
||||
getApp().globalData?.logger.error('login error: ', result.errMsg);
|
||||
@ -231,8 +128,80 @@ const useUserStore = defineStore('user', {
|
||||
});
|
||||
},
|
||||
|
||||
register(params: {
|
||||
image: string,
|
||||
avatarUrl: string,
|
||||
nickName: string,
|
||||
telephone: string,
|
||||
birthday: string,
|
||||
gender: string
|
||||
}) {
|
||||
const registerForm = {
|
||||
...params,
|
||||
unionId: this.userInfo.unionId,
|
||||
openId: this.userInfo.openId,
|
||||
maOpenId: this.userInfo.maOpenId,
|
||||
companyId: getCompanyId(),
|
||||
creatorId: this.userInfo.creatorId,
|
||||
storeId: getRegisterStoreId()
|
||||
} as RegisterParams;
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const result = await register(registerForm);
|
||||
resolve(result);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 设置用户的信息
|
||||
async setUserInfo(partial: Partial<UserBean>) {
|
||||
this.userInfo = partial as UserBean;
|
||||
// this.userInfo.levelEntity?.discount = 79;
|
||||
// this.userInfo.salePrice = 'price_ext';
|
||||
if(this.userInfo) {
|
||||
this.userInfo.userDiscount = this.getUserDiscount;
|
||||
await setCompanyId(this.userInfo.companyId);
|
||||
} else {
|
||||
await clearToken();
|
||||
}
|
||||
await this.fetchTerminal();
|
||||
await this.fetchCompanyInfo();
|
||||
},
|
||||
|
||||
setCompanyInfo(partial: Partial<any>) {
|
||||
this.companyInfo = partial as any;
|
||||
},
|
||||
|
||||
setDeliveryAddress(partial: Partial<any>) {
|
||||
this.deliveryAddress = partial as any;
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
async getProfile() {
|
||||
const result = await getUserProfile();
|
||||
await this.setUserInfo(result);
|
||||
},
|
||||
|
||||
async fetchCompanyInfo() {
|
||||
this.companyConfigInfo = await getCompanyInfo();
|
||||
},
|
||||
|
||||
async fetchTerminal() {
|
||||
this.terminalInfo = await getTerminal(this.userInfo?.companyId);
|
||||
},
|
||||
|
||||
// 重置用户信息
|
||||
resetInfo() {
|
||||
this.$reset();
|
||||
},
|
||||
|
||||
// Logout
|
||||
async logout() {
|
||||
await userLogout();
|
||||
this.resetInfo();
|
||||
clearToken();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
const TokenKey = 'accessToken';
|
||||
const SessionKey = 'sessionKey';
|
||||
const CompanyIdKey = 'companyId';
|
||||
const ReferrerUserIdKey = 'referrerUserId';
|
||||
const RegisterStoreIdKey = 'storeId';
|
||||
@ -17,6 +18,14 @@ function setToken(token: string) {
|
||||
uni.setStorageSync(TokenKey, token);
|
||||
}
|
||||
|
||||
function getSessionKey() {
|
||||
return uni.getStorageSync(SessionKey);
|
||||
}
|
||||
|
||||
function setSessionKey(sessionKey: string){
|
||||
uni.setStorageSync(SessionKey, sessionKey);
|
||||
}
|
||||
|
||||
function getCompanyId() {
|
||||
return uni.getStorageSync(CompanyIdKey);
|
||||
}
|
||||
@ -44,6 +53,7 @@ function getRegisterStoreId() {
|
||||
function clearToken() {
|
||||
uni.removeStorageSync(TokenKey);
|
||||
uni.removeStorageSync(CompanyIdKey);
|
||||
uni.removeStorageSync(SessionKey);
|
||||
}
|
||||
|
||||
export {
|
||||
@ -51,6 +61,8 @@ export {
|
||||
isLogin,
|
||||
getToken,
|
||||
setToken,
|
||||
getSessionKey,
|
||||
setSessionKey,
|
||||
getCompanyId,
|
||||
setCompanyId,
|
||||
getReferrerUserId,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { HttpError, HttpRequestConfig, HttpResponse } from 'uview-plus/libs/luch-request';
|
||||
import { showMessage } from './status';
|
||||
import { getCompanyId, getToken } from '@/utils/auth';
|
||||
import useUserStore from '@/store/modules/user';
|
||||
import { showMessage } from '@/utils/request/status';
|
||||
|
||||
// 是否正在刷新token的标记
|
||||
let isRefreshing: boolean = false;
|
||||
@ -66,7 +66,7 @@ function responseInterceptors() {
|
||||
if(!isRefreshing) {
|
||||
// 修改登录状态为true
|
||||
isRefreshing = true;
|
||||
await useUserStore().authLogin();
|
||||
await useUserStore().login();
|
||||
// 登录完成之后,开始执行队列请求
|
||||
requestQueue.forEach(cb => cb());
|
||||
// 重试完了清空这个队列
|
||||
@ -99,14 +99,15 @@ function responseInterceptors() {
|
||||
}
|
||||
},
|
||||
(response: HttpError) => {
|
||||
console.error('http error: ', response);
|
||||
/* 对响应错误做点什么 (statusCode !== 200)*/
|
||||
getApp().globalData?.logger.info('request error : ', response);
|
||||
getApp().globalData?.logger.error('request error : ', response);
|
||||
if(response.statusCode) {
|
||||
// 请求已发出,但是不在2xx的范围
|
||||
showMessage(response.statusCode);
|
||||
uni.$u.toast(showMessage(response.statusCode));
|
||||
return Promise.reject(response.data);
|
||||
}
|
||||
showMessage('网络连接异常,请稍后再试!');
|
||||
uni.$u.toast('网络连接异常,请稍后再试!');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user