Compare commits
16 Commits
68262d0519
...
master
Author | SHA1 | Date | |
---|---|---|---|
224db6202c | |||
dbd3800314 | |||
4545fbfab5 | |||
49af2cd078 | |||
bca9390042 | |||
bad6348393 | |||
c56ea0dd73 | |||
4d7f73aedf | |||
3945b36b0a | |||
4344adeb0b | |||
11a0637039 | |||
b53dc2dd4f | |||
0c0d5e55d5 | |||
b7461002dc | |||
e910a76437 | |||
85d52f5065 |
@@ -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/'
|
||||
VITE_APP_BASE_API='https://apidev.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('APPID 写入失败', err);
|
||||
} else {
|
||||
console.log(`APPID 写入成功 ${VITE_APP_WX_APPID}`);
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (parseError) {
|
||||
console.error('解析 manifest.json 失败', parseError);
|
||||
}
|
||||
}
|
||||
});
|
58
package.json
58
package.json
@@ -4,10 +4,12 @@
|
||||
"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",
|
||||
"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",
|
||||
"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": "cross-env NODE_ENV=test node manifest.modify.ts && uni build --mode test -p mp-weixin && node deploy.ts test",
|
||||
"deploy:prod": "cross-env NODE_ENV=production node manifest.modify.ts && uni build --mode production -p mp-weixin && node deploy.ts production",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"eslint": "eslint --fix",
|
||||
"stylelint": "stylelint \"src/**/*.(vue|scss|css)\" --fix",
|
||||
@@ -15,53 +17,53 @@
|
||||
"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",
|
||||
"uview-plus": "^3.1.38",
|
||||
"uview-plus": "^3.1.41",
|
||||
"vue": "3.4.21",
|
||||
"vue-i18n": "^9.9.0",
|
||||
"z-paging": "^2.6.2"
|
||||
"z-paging": "^2.6.3"
|
||||
},
|
||||
"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",
|
||||
"@types/node": "^20.8.10",
|
||||
"@typescript-eslint/parser": "^6.10.0",
|
||||
"@uni-helper/uni-app-types": "^0.5.9",
|
||||
"@unocss/eslint-plugin": "^0.57.2",
|
||||
"@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",
|
||||
"@unocss/eslint-plugin": "^0.57.7",
|
||||
"@vue/runtime-core": "^3.4.21",
|
||||
"@vue/tsconfig": "^0.4.0",
|
||||
"czg": "^1.7.1",
|
||||
"eslint": "^8.53.0",
|
||||
"lint-staged": "^15.0.2",
|
||||
"miniprogram-ci": "^1.9.8",
|
||||
"eslint": "^8.55.0",
|
||||
"lint-staged": "^15.2.0",
|
||||
"miniprogram-ci": "^1.9.10",
|
||||
"picocolors": "^1.0.0",
|
||||
"postcss-html": "^1.5.0",
|
||||
"postcss-scss": "^4.0.9",
|
||||
"sass": "^1.69.5",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"stylelint": "^15.11.0",
|
||||
"stylelint-config-recess-order": "^4.3.0",
|
||||
"stylelint-config-recess-order": "^4.4.0",
|
||||
"stylelint-config-standard": "^34.0.0",
|
||||
"stylelint-config-standard-vue": "^1.0.0",
|
||||
"stylelint-order": "^6.0.3",
|
||||
"typescript": "^5.2.2",
|
||||
"unocss": "^0.57.2",
|
||||
"unocss-applet": "^0.7.7",
|
||||
"typescript": "^5.3.2",
|
||||
"unocss": "^0.57.7",
|
||||
"unocss-applet": "^0.7.8",
|
||||
"unplugin-auto-import": "^0.16.7",
|
||||
"unplugin-vue-components": "^0.25.2",
|
||||
"vite": "^4.5.2",
|
||||
"vite": "^5.2.8",
|
||||
"vite-plugin-imagemin": "^0.6.1",
|
||||
"vue-tsc": "^1.8.22"
|
||||
"vue-tsc": "^1.8.24"
|
||||
},
|
||||
"lint-staged": {
|
||||
"src/**/*.{js,jsx,ts,tsx}": "eslint --fix",
|
||||
|
2799
pnpm-lock.yaml
generated
2799
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
51
src/App.vue
51
src/App.vue
@@ -1,19 +1,26 @@
|
||||
<script lang='ts'>
|
||||
import { mpUpdate, setCompanyId, setReferrerUserId, setRegisterStoreId } from '@/utils';
|
||||
import {
|
||||
getCompanyId,
|
||||
getRegisterStoreId,
|
||||
mpUpdate,
|
||||
setCompanyId,
|
||||
setReferrerUserId,
|
||||
setRegisterStoreId
|
||||
} from '@/utils';
|
||||
import { Logger } from '@/utils/common/logger';
|
||||
|
||||
const logger = new Logger();
|
||||
|
||||
export default {
|
||||
onLaunch: async (options: any) => {
|
||||
console.log('App Launch options ', options);
|
||||
|
||||
const miniProgram = uni.getAccountInfoSync().miniProgram;
|
||||
const env = miniProgram.envVersion;
|
||||
|
||||
console.log(`App Launch options ${env}: `, options);
|
||||
|
||||
//生产
|
||||
if(env === 'release' || env === 'trial') {
|
||||
logger.info(`launch options ${env}: `, options);
|
||||
if(env === 'release') {
|
||||
logger.info(`App Launch options ${env}: `, options);
|
||||
|
||||
async function getVersionStatus() {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -42,13 +49,20 @@ 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');
|
||||
// setRegisterStoreId('17250262998884000000');
|
||||
}
|
||||
}
|
||||
|
||||
if(options?.query) {
|
||||
@@ -93,7 +107,18 @@ export default {
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
//原先商品团购
|
||||
if(options?.path?.includes('ticketsBuy/ticketsBuy') && options?.query.couponsId) {
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: 'pages/common/groupbuy/detail?id=' + options?.query.couponsId
|
||||
});
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`App Launch options ${env}: { companyId: `, getCompanyId() + ', storeId: ' + getRegisterStoreId() + ' }');
|
||||
|
||||
// #ifdef MP
|
||||
mpUpdate();
|
||||
@@ -107,7 +132,9 @@ export default {
|
||||
},
|
||||
|
||||
globalData: {
|
||||
logger: logger
|
||||
logger: logger,
|
||||
companyId: getCompanyId(),
|
||||
storeId: getRegisterStoreId()
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -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 });
|
||||
|
@@ -31,6 +31,7 @@ export interface LoginResult {
|
||||
user: UserBean;
|
||||
userInfo: any;
|
||||
token: string;
|
||||
maOpenId: string;
|
||||
}
|
||||
|
||||
export interface IntegralBean {
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"name": "SUKE-MP",
|
||||
"appid": "",
|
||||
"description": "",
|
||||
"versionName": "3.0.1",
|
||||
"versionCode": "300",
|
||||
"versionName": "3.0.2",
|
||||
"versionCode": "302",
|
||||
"transformPx": false,
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
|
@@ -38,6 +38,12 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "肃客会员"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/coupons/ticketsBuy/ticketsBuy",
|
||||
"style": {
|
||||
"navigationBarTitleText": "团购详情"
|
||||
}
|
||||
}
|
||||
],
|
||||
"subPackages": [
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<view class='swiper-container'>
|
||||
<swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'>
|
||||
<swiper-item v-for='(item,index) in bannerList' :key='index'>
|
||||
<image :src='item||defaultImage' mode='aspectFill'/>
|
||||
<image :src='item||defaultImage' mode='aspectFill' />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view class='indicator'>
|
||||
@@ -174,12 +174,18 @@ onLoad(async (e: any) => {
|
||||
if(isLogin()) {
|
||||
await uni.showLoading();
|
||||
groupBuyBean.value = await getGroupBuyDetail(e.id);
|
||||
// setCompanyId('1512403904150138881');
|
||||
// groupBuyBean.value = await getGroupBuyDetail('1740922051118063618');
|
||||
if(groupBuyBean.value) {
|
||||
groupBuyBean.value.goods.price = groupBuyBean.value.price;
|
||||
bannerList.value = JSON.parse(groupBuyBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images);
|
||||
countdown();
|
||||
await fetchRecommendList();
|
||||
await fetchBuyRecordList();
|
||||
}
|
||||
uni.hideLoading();
|
||||
} else {
|
||||
goPath('/pages/common/login/index');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -189,13 +195,19 @@ onUnload(() => {
|
||||
}
|
||||
});
|
||||
|
||||
onShareAppMessage((e) => {
|
||||
return {
|
||||
title: groupBuyBean.value?.goods?.name || 'VIP顾客中心',
|
||||
path: `/pages/common/groupbuy/detail?id=${groupBuyBean.value?.id}&companyId=${getApp().globalData?.companyId}&storeId=${getApp().globalData?.storeId}`
|
||||
};
|
||||
});
|
||||
|
||||
const isNotStated = () => {
|
||||
return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now());
|
||||
};
|
||||
|
||||
const isPending = () => {
|
||||
return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now());
|
||||
;
|
||||
};
|
||||
|
||||
const isEnded = () => {
|
||||
|
@@ -36,8 +36,9 @@ function wechatLogin() {
|
||||
showToast('请先阅读并同意小程序隐私保护协议');
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showLoading();
|
||||
userStore.authLogin().then(() => {
|
||||
userStore.login().then(() => {
|
||||
uni.hideLoading();
|
||||
uni.reLaunch({ url: '/pages/home/index' });
|
||||
});
|
||||
|
@@ -1,228 +1,207 @@
|
||||
<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' style='display: none'>
|
||||
<image :src='assetsUrl("ic_register_mobile.png")' />
|
||||
<input placeholder='请输入手机号' inputmode='number' maxLength='11' />
|
||||
<view class='c-flex-column avatar-container'>
|
||||
<image class='avatar' :src='avatarUrl' />
|
||||
<button class='avatar-button' open-type='chooseAvatar' @chooseavatar='chooseAvatar' />
|
||||
</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' style='display: none' @click.stop='register'>注册领券</text>
|
||||
|
||||
<image :src='companyConfigInfo.regqrcode||defaultImage' :show-menu-by-longpress='true' mode='aspectFill'
|
||||
style='width: 439rpx;height: 439rpx;align-self: center' />
|
||||
<text style='font-size: 26rpx;
|
||||
margin-top: 10rpx;
|
||||
align-self: center;color: #666666;'>长按扫码注册
|
||||
</text>
|
||||
|
||||
<template v-if='couponBean&&couponBean.status==0'>
|
||||
<view class='divider' />
|
||||
<view class='coupon c-flex-column' @click.stop='goPath("/pages/mine/subs/coupon/index")'>
|
||||
<view class='c-flex-row'>
|
||||
<text class='coupon-name'>{{ couponBean.title }}</text>
|
||||
<image :src='assetsUrl("ic_arrow_right_gray.png")' />
|
||||
</view>
|
||||
<text class='expired-time'>
|
||||
有效期至{{ dayjs(Date.now()).add(couponBean.triggerEndDay, 'day').format('YYYY.MM.DD') }}
|
||||
</text>
|
||||
<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' />
|
||||
|
||||
<text style='font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;margin-top: 20rpx'>福利详情
|
||||
</text>
|
||||
<text style='font-size: 28rpx;
|
||||
color: #333333;margin-top: 14rpx'>1.优惠金额{{ couponBean.reduce }}元\n
|
||||
2.满{{ couponBean.threshold }}减{{ couponBean.reduce }}\n
|
||||
3.赠送{{ couponBean.publicNum }}张
|
||||
</text>
|
||||
</template>
|
||||
<template v-else>
|
||||
<text style='font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;margin-top: 20rpx'>
|
||||
微信扫一扫领取会员卡
|
||||
</text>
|
||||
<text style='font-size: 28rpx;
|
||||
color: #333333;margin-top: 14rpx'>
|
||||
1、及时接受消费小票\n
|
||||
2、随时查询消费记录\n
|
||||
3、及时接收优惠信息
|
||||
</text>
|
||||
</template>
|
||||
<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, defaultImage } from '@/utils/assets';
|
||||
import { ref } from 'vue';
|
||||
import { getTelephone } from '@/api/user';
|
||||
import { useUserStore } from '@/store';
|
||||
import { goPath } from '@/utils';
|
||||
import { getRegisterCoupon } from '@/api/user';
|
||||
import { assetsUrl } from '@/utils/assets';
|
||||
import { getRegisterStoreId, 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 || dayjs().format('YYYY-MM-DD'));
|
||||
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 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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const startCountdown = () => {
|
||||
if(countdown.value !== '获取验证码') {
|
||||
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 () => {
|
||||
if(!getRegisterStoreId()) {
|
||||
showToast('请从公众号消息窗口点击店名打开小程序');
|
||||
return;
|
||||
}
|
||||
let time = 120;
|
||||
let interval = setInterval(() => {
|
||||
time--;
|
||||
countdown.value = `${time}s 重新获取`;
|
||||
if(time == 0) {
|
||||
clearInterval(interval);
|
||||
countdown.value = '获取验证码';
|
||||
|
||||
await uni.showLoading();
|
||||
const registerForm = {
|
||||
image: avatarUrl.value,
|
||||
avatarUrl: avatarUrl.value,
|
||||
nickName: nickName.value,
|
||||
telephone: telephone.value,
|
||||
birthday: dayjs(birthday.value).isValid() ? dayjs(birthday.value).format('YYYY-MM-DD HH:mm:ss') : dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
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'
|
||||
});
|
||||
}
|
||||
}, 1000);
|
||||
uni.hideLoading();
|
||||
};
|
||||
|
||||
const register = () => {
|
||||
};
|
||||
|
||||
</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;
|
||||
}
|
||||
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;
|
||||
|
||||
.coupon-name {
|
||||
display: flex;
|
||||
font-size: 36rpx;
|
||||
color: #D95554;
|
||||
flex: 1;
|
||||
.row-title {
|
||||
font-size: 30rpx;
|
||||
color: #666666;
|
||||
width: 150rpx;
|
||||
}
|
||||
|
||||
image {
|
||||
width: 13rpx;
|
||||
height: 24rpx;
|
||||
}
|
||||
|
||||
.expired-time {
|
||||
font-size: 28rpx;
|
||||
.row-value {
|
||||
font-size: 30rpx;
|
||||
color: #333333;
|
||||
margin-top: 2rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.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>
|
||||
|
29
src/pages/coupons/ticketsBuy/ticketsBuy.vue
Normal file
29
src/pages/coupons/ticketsBuy/ticketsBuy.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<script lang='ts' setup>
|
||||
onLoad((options) => {
|
||||
getApp().logger?.info('ticketsBuy options: ', options);
|
||||
let couponId = options?.couponsId;
|
||||
if(options?.query && couponId == undefined) {
|
||||
const params = decodeURIComponent(options?.query);
|
||||
couponId = getQueryParam(params, 'couponsId');
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: `/pages/common/groupbuy/detail?id=${couponId}`
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
function getQueryParam(queryParams: string, key: string) {
|
||||
let regex = new RegExp('(?:[?&]|^)' + key + '=([^&]+)'),
|
||||
match = queryParams.match(regex);
|
||||
return match && match[1];
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang='scss' scoped>
|
||||
|
||||
</style>
|
@@ -72,7 +72,7 @@ import CompanyDialog from '@/components/company-dialog.vue';
|
||||
import { getCompanyList } from '@/api/company';
|
||||
import { useUserStore } from '@/store';
|
||||
import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets';
|
||||
import { getCompanyId, goPath, isLogin } from '@/utils';
|
||||
import { getOpenId, goPath, isLogin } from '@/utils';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { UserBean } from '@/store/modules/user/types';
|
||||
|
||||
@@ -86,6 +86,7 @@ const submenuList = [
|
||||
title: '注册有礼',
|
||||
icon: assetsUrl('ic_register_gift2.png'),
|
||||
path: '/pages/common/register/reward'
|
||||
// path: '/pages/coupons/ticketsBuy/ticketsBuy?couponsId=1797773484774432769'
|
||||
},
|
||||
{
|
||||
title: '团购秒杀',
|
||||
@@ -127,48 +128,86 @@ onLoad((e) => {
|
||||
onShow(async () => {
|
||||
if(isLogin()) {
|
||||
// userStore.getProfile();
|
||||
if(userInfo.value.maOpenId) {
|
||||
fetchCompanyList();
|
||||
} else {
|
||||
await userStore.getProfile();
|
||||
}
|
||||
} else {
|
||||
// setToken('42ae187265fb4688804fd294cbcf99f1')
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '您还未登录,请先登录',
|
||||
showCancel: true,
|
||||
success: (res) => {
|
||||
if(res.confirm) {
|
||||
goPath('/pages/common/login/index');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const switchCompany = () => {
|
||||
fetchCompanyList((companyList: any[], userList: any[]) => {
|
||||
companyDialogRef.value.show(getCompanyId(),(index: number) => {
|
||||
companyDialogRef.value.show(getApp().globalData?.companyId, (index: number) => {
|
||||
userStore.setUserInfo(userList[index]);
|
||||
userStore.setCompanyInfo(companyList[index]);
|
||||
|
||||
avatarModifyRemind();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function avatarModifyRemind() {
|
||||
setTimeout(() => {
|
||||
if(userInfo.value.image === defaultAvatar) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '为了提供更优质的个性化服务,请先修改头像',
|
||||
showCancel: true,
|
||||
success: (res) => {
|
||||
if(res.confirm) {
|
||||
goPath('/pages/mine/subs/profile/index');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
const fetchCompanyList = (fn: any = undefined) => {
|
||||
const maOpenId = userInfo.value?.maOpenId || (userList.value.filter((res: UserBean) => res?.maOpenId !== '')[0]?.maOpenId);
|
||||
const maOpenId = getOpenId() || userInfo.value?.maOpenId || (userList.value.filter((res: UserBean) => res?.maOpenId !== '')[0]?.maOpenId);
|
||||
getCompanyList(maOpenId).then(res => {
|
||||
companyList.value = res.map((res: { company: any }) => res.company);
|
||||
userList.value = res.map((res: { user: any }) => res.user);
|
||||
|
||||
if(companyList.value.length === 0) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '当前店铺还未注册,请先注册',
|
||||
showCancel: true,
|
||||
success: (res) => {
|
||||
if(res.confirm) {
|
||||
goPath('/pages/common/register/index');
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(fn != undefined && fn instanceof Function) {
|
||||
fn(companyList.value, userList.value);
|
||||
} else {
|
||||
let index = companyList.value.findIndex((res: { id: string }) => res.id === getCompanyId());
|
||||
let index = companyList.value.findIndex((res: { id: string }) => res.id === getApp().globalData?.companyId);
|
||||
//未在当前公司下注册
|
||||
if(index < 0) {
|
||||
if(!getApp()?.globalData?.storeId) {
|
||||
goPath('/pages/common/register/index');
|
||||
return;
|
||||
}
|
||||
index = 0;
|
||||
}
|
||||
|
||||
userStore.setUserInfo(userList.value[index]);
|
||||
userStore.setCompanyInfo(companyList.value[index]);
|
||||
avatarModifyRemind();
|
||||
}
|
||||
|
||||
// uni.showActionSheet({
|
||||
// itemList: companyList.map((res: { companyName: string }) => res.companyName),
|
||||
// success: (res) => {
|
||||
// userStore.setUserInfo(userList[res.tapIndex]);
|
||||
// userStore.setCompanyInfo(companyList[res.tapIndex]);
|
||||
// }
|
||||
// });
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -38,7 +38,7 @@ const coupons = ref<CouponBean[]>([]);
|
||||
|
||||
const fetchData = async (status: number) => {
|
||||
const { list } = await getCouponList({
|
||||
companyId: getCompanyId(),
|
||||
companyId: getApp()?.globalData?.companyId,
|
||||
memberId: userInfo.value?.id,
|
||||
status: status,
|
||||
pageNum: 1,
|
||||
|
@@ -147,6 +147,13 @@ onLoad(async (e: any) => {
|
||||
uni.hideLoading();
|
||||
});
|
||||
|
||||
onShareAppMessage((e) => {
|
||||
return {
|
||||
title: goodsBean.value?.name || 'VIP顾客中心',
|
||||
path: `/pages/common/groupbuy/detail?id=${goodsBean.value?.id}&companyId=${getApp().globalData?.companyId}&storeId=${getApp().globalData?.storeId}`
|
||||
};
|
||||
});
|
||||
|
||||
const getStockColorCount = computed(() => {
|
||||
const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName)))
|
||||
.map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!);
|
||||
|
@@ -49,7 +49,8 @@
|
||||
</text>
|
||||
<view class='bottom-sku-view c-flex-row'>
|
||||
<text>
|
||||
{{ item.checkedStock.colorName||'均色' }},{{ item.checkedStock.sizeName||'均码' }} x{{ item.checkedStock.count }}
|
||||
{{ item.checkedStock.colorName || '均色' }},{{ item.checkedStock.sizeName || '均码' }}
|
||||
x{{ item.checkedStock.count }}
|
||||
</text>
|
||||
<text>¥{{ item.price }}</text>
|
||||
</view>
|
||||
@@ -160,16 +161,16 @@ const buildSqbParams = computed(() => {
|
||||
client_sn: orderBean.value?.id || '',
|
||||
return_url: '/pages/common/payresult/index',
|
||||
total_amount: Number(((totalPrice.value || 0) * 100).toFixed(2)),
|
||||
terminal_sn: terminalInfo.value.terminalSn,
|
||||
subject: orderBean?.value?.orderGoods[0].name||'未知',
|
||||
terminal_sn: terminalInfo.value?.terminalSn,
|
||||
subject: orderBean?.value?.orderGoods[0].name || '未知',
|
||||
subject_img: orderBean?.value?.orderGoods[0].images || '',
|
||||
merchant_name: terminalInfo.value.companyName,
|
||||
merchant_name: terminalInfo.value?.companyName,
|
||||
notify_url: 'https://www.baidu.com'
|
||||
}, true);
|
||||
|
||||
return {
|
||||
...params,
|
||||
sign: hexMD5(parseParameter(params) + '&key=' + terminalInfo.value.terminalKey).toUpperCase()
|
||||
sign: hexMD5(parseParameter(params) + '&key=' + terminalInfo.value?.terminalKey).toUpperCase()
|
||||
};
|
||||
});
|
||||
|
||||
@@ -202,7 +203,10 @@ const navigateTo = (e: any) => {
|
||||
};
|
||||
|
||||
const createOrder = async () => {
|
||||
|
||||
if(!terminalInfo.value) {
|
||||
showToast('当前店铺未配置收款渠道,请联系商家');
|
||||
return;
|
||||
}
|
||||
//邮寄
|
||||
if(tabIndex.value == 1 && !deliveryAddress.value.addrid) {
|
||||
showToast('请选择收货地址');
|
||||
|
@@ -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 || Date.now()).format('YYYY-MM-DD') || '请选择生日' }}</text>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
@@ -80,7 +80,7 @@ const params = ref<{
|
||||
nickName: userInfo.value.nickName,
|
||||
telephone: userInfo.value.telephone,
|
||||
gender: userInfo.value.gender,
|
||||
birthday: userInfo.value.birthday
|
||||
birthday: userInfo.value.birthday|| dayjs().format('YYYY-MM-DD')
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
@@ -135,7 +135,7 @@ const save = async () => {
|
||||
|
||||
const result = await updateProfile({
|
||||
...params.value,
|
||||
birthday: dayjs(params.value.birthday).format('YYYY-MM-DD HH:mm:ss'),
|
||||
birthday: dayjs(birthday.value).isValid() ? dayjs(birthday.value).format('YYYY-MM-DD HH:mm:ss') : dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
birthdayType: 0
|
||||
});
|
||||
|
||||
|
@@ -12,11 +12,11 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
key: 'shoppingCartState',
|
||||
storage: {
|
||||
setItem(key, value) {
|
||||
uni.setStorageSync(key, value || []); // [!code warning]
|
||||
uni.setStorageSync(key, value); // [!code warning]
|
||||
uni.setStorageSync(`shoppingCart_${getCompanyId()}`, JSON.parse(value).shoppingCartList);
|
||||
},
|
||||
getItem(key) {
|
||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)) || []; // [!code warning]
|
||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)) || '';
|
||||
}
|
||||
},
|
||||
// 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
||||
@@ -33,12 +33,19 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
||||
},
|
||||
|
||||
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
|
||||
if(Array.isArray(state.shoppingCartList)) {
|
||||
return state.shoppingCartList?.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
save(partial: Partial<GoodsBean>) {
|
||||
if(!Array.isArray(this.shoppingCartList)) {
|
||||
this.shoppingCartList = [];
|
||||
}
|
||||
this.shoppingCartList.push(partial as GoodsBean);
|
||||
},
|
||||
|
||||
|
@@ -1,8 +1,16 @@
|
||||
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,
|
||||
setOpenId,
|
||||
setSessionKey,
|
||||
setToken
|
||||
} from '@/utils/auth';
|
||||
import type { RegisterParams, TerminalBean } from '@/api/user/types';
|
||||
import { getCompanyInfo } from '@/api/company';
|
||||
|
||||
const useUserStore = defineStore('user', {
|
||||
@@ -47,10 +55,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,68 +70,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();
|
||||
},
|
||||
|
||||
checkUserRegisterStatus() {
|
||||
|
||||
},
|
||||
|
||||
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();
|
||||
},
|
||||
|
||||
// 小程序授权登录
|
||||
authLogin(provider: providerType = 'weixin') {
|
||||
login(provider: providerType = 'weixin') {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
provider,
|
||||
@@ -150,32 +93,15 @@ const useUserStore = defineStore('user', {
|
||||
// referrerUserId: getReferrerUserId()
|
||||
});
|
||||
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);
|
||||
}
|
||||
setSessionKey(res.sessionKey);
|
||||
setOpenId(res.maOpenId);
|
||||
if(res.user) {
|
||||
this.setUserInfo(res.user);
|
||||
} else {
|
||||
setToken(res.token);
|
||||
await this.setUserInfo(res.user);
|
||||
this.setUserInfo(res.userInfo);
|
||||
}
|
||||
// }
|
||||
resolve(res);
|
||||
} else {
|
||||
getApp().globalData?.logger.error('login error: ', result.errMsg);
|
||||
@@ -191,8 +117,86 @@ 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);
|
||||
if(getApp().globalData){
|
||||
getApp().globalData.companyId = this.userInfo.companyId;
|
||||
}
|
||||
} else {
|
||||
await clearToken();
|
||||
}
|
||||
this.fetchTerminal();
|
||||
this.fetchCompanyInfo();
|
||||
},
|
||||
|
||||
setCompanyInfo(partial: Partial<any>) {
|
||||
this.companyInfo = partial as any;
|
||||
if(getApp()?.globalData) {
|
||||
getApp().globalData.companyId = this.companyInfo.id;
|
||||
}
|
||||
},
|
||||
|
||||
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,3 @@
|
||||
export const assetsUrl = (name: string) => `https://img.lakeapp.cn/wx/images/${name}`;
|
||||
export const defaultAvatar = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';
|
||||
|
||||
export const defaultImage = '/static/images/ic_noimage.svg';
|
||||
|
@@ -1,4 +1,6 @@
|
||||
const TokenKey = 'accessToken';
|
||||
const SessionKey = 'sessionKey';
|
||||
const OpenIdKey = 'openId';
|
||||
const CompanyIdKey = 'companyId';
|
||||
const ReferrerUserIdKey = 'referrerUserId';
|
||||
const RegisterStoreIdKey = 'storeId';
|
||||
@@ -17,12 +19,33 @@ function setToken(token: string) {
|
||||
uni.setStorageSync(TokenKey, token);
|
||||
}
|
||||
|
||||
function getSessionKey() {
|
||||
return uni.getStorageSync(SessionKey);
|
||||
}
|
||||
|
||||
function setSessionKey(sessionKey: string) {
|
||||
uni.setStorageSync(SessionKey, sessionKey);
|
||||
}
|
||||
|
||||
function getOpenId() {
|
||||
return uni.getStorageSync(OpenIdKey);
|
||||
}
|
||||
|
||||
function setOpenId(openId: string) {
|
||||
uni.setStorageSync(OpenIdKey, openId);
|
||||
}
|
||||
|
||||
function getCompanyId() {
|
||||
return uni.getStorageSync(CompanyIdKey);
|
||||
}
|
||||
|
||||
function setCompanyId(companyId: string) {
|
||||
if(companyId) {
|
||||
uni.setStorageSync(CompanyIdKey, companyId);
|
||||
if(getApp()?.globalData) {
|
||||
getApp().globalData.companyId = companyId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getReferrerUserId() {
|
||||
@@ -44,6 +67,7 @@ function getRegisterStoreId() {
|
||||
function clearToken() {
|
||||
uni.removeStorageSync(TokenKey);
|
||||
uni.removeStorageSync(CompanyIdKey);
|
||||
uni.removeStorageSync(SessionKey);
|
||||
}
|
||||
|
||||
export {
|
||||
@@ -51,6 +75,10 @@ export {
|
||||
isLogin,
|
||||
getToken,
|
||||
setToken,
|
||||
getSessionKey,
|
||||
setSessionKey,
|
||||
getOpenId,
|
||||
setOpenId,
|
||||
getCompanyId,
|
||||
setCompanyId,
|
||||
getReferrerUserId,
|
||||
|
@@ -13,18 +13,24 @@ export class Logger {
|
||||
info(key: string, value: any) {
|
||||
if(this.env === 'release' || this.env === 'trial') {
|
||||
this.logger.info(key, value);
|
||||
} else {
|
||||
console.info(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
warn(key: string, value: any) {
|
||||
if(this.env === 'release' || this.env === 'trial') {
|
||||
this.logger.warn(key, value);
|
||||
}else {
|
||||
console.warn(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
error(key: string, value: any) {
|
||||
if(this.env === 'release' || this.env === 'trial') {
|
||||
this.logger.error(key, value);
|
||||
}else {
|
||||
console.error(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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';
|
||||
import { useUserStore } from '@/store';
|
||||
|
||||
// 是否正在刷新token的标记
|
||||
let isRefreshing: boolean = false;
|
||||
@@ -53,7 +53,7 @@ function responseInterceptors() {
|
||||
return data;
|
||||
}
|
||||
|
||||
getApp().globalData?.logger.info('response: ', config);
|
||||
getApp().globalData?.logger.info('response: ', data);
|
||||
|
||||
// 请求成功则返回结果
|
||||
if(data.code === 200 || data?.retcode == 0) {
|
||||
@@ -61,12 +61,12 @@ function responseInterceptors() {
|
||||
}
|
||||
|
||||
// 登录状态失效,重新登录
|
||||
if(data.code === 401) {
|
||||
if(data.code === 4011 || data?.retcode === 4011) {
|
||||
// 是否在获取token中,防止重复获取
|
||||
if(!isRefreshing) {
|
||||
// 修改登录状态为true
|
||||
isRefreshing = true;
|
||||
await useUserStore().authLogin();
|
||||
await useUserStore().login();
|
||||
// 登录完成之后,开始执行队列请求
|
||||
requestQueue.forEach(cb => cb());
|
||||
// 重试完了清空这个队列
|
||||
@@ -99,12 +99,15 @@ function responseInterceptors() {
|
||||
}
|
||||
},
|
||||
(response: HttpError) => {
|
||||
console.error('http error: ', response);
|
||||
/* 对响应错误做点什么 (statusCode !== 200)*/
|
||||
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('网络连接异常,请稍后再试!');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ export const showMessage = (status: number | string): string => {
|
||||
message = 'HTTP版本不受支持(505)';
|
||||
break;
|
||||
default:
|
||||
message = `连接出错(${status})!`;
|
||||
message = `操作失败(${status})!`;
|
||||
}
|
||||
return `${message},请检查网络或联系管理员!`;
|
||||
};
|
||||
|
Reference in New Issue
Block a user