Compare commits
18 Commits
e910a76437
...
master
Author | SHA1 | Date | |
---|---|---|---|
224db6202c | |||
dbd3800314 | |||
4545fbfab5 | |||
49af2cd078 | |||
bca9390042 | |||
bad6348393 | |||
c56ea0dd73 | |||
4d7f73aedf | |||
3945b36b0a | |||
4344adeb0b | |||
11a0637039 | |||
b53dc2dd4f | |||
0c0d5e55d5 | |||
b7461002dc | |||
68262d0519 | |||
d757f99b5d | |||
915ff6b184 | |||
e92323a15b |
@@ -4,9 +4,10 @@ VITE_APP_TITLE='uniapp-vue3-project'
|
|||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
VITE_APP_ENV='development'
|
VITE_APP_ENV='development'
|
||||||
|
|
||||||
|
VITE_APP_ID='wx92e663dc11d0c0a8'
|
||||||
|
|
||||||
# 接口地址
|
# 接口地址
|
||||||
#VITE_APP_BASE_API='https://apidev.lakeapp.cn/'
|
VITE_APP_BASE_API='https://apidev.lakeapp.cn/'
|
||||||
VITE_APP_BASE_API='https://api.lakeapp.cn/'
|
|
||||||
|
|
||||||
# 删除console
|
# 删除console
|
||||||
VITE_DROP_CONSOLE=false
|
VITE_DROP_CONSOLE=false
|
||||||
|
@@ -4,8 +4,10 @@ VITE_APP_TITLE='uniapp-vue3-project'
|
|||||||
# 生产环境配置
|
# 生产环境配置
|
||||||
VITE_APP_ENV='production'
|
VITE_APP_ENV='production'
|
||||||
|
|
||||||
|
VITE_APP_ID='wx67a750d0ceed4d88'
|
||||||
|
|
||||||
# 接口地址
|
# 接口地址
|
||||||
VITE_APP_BASE_API='http://api.lakeapp.cn/'
|
VITE_APP_BASE_API='https://api.lakeapp.cn/'
|
||||||
|
|
||||||
# 删除console
|
# 删除console
|
||||||
VITE_DROP_CONSOLE=true
|
VITE_DROP_CONSOLE=true
|
||||||
|
14
.env.test
14
.env.test
@@ -1,11 +1,17 @@
|
|||||||
# 页面标题
|
# 页面标题
|
||||||
VITE_APP_TITLE='uniapp-vue3-project'
|
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
|
# 删除console
|
||||||
VITE_DROP_CONSOLE=true
|
VITE_DROP_CONSOLE=false
|
||||||
|
|
||||||
|
# 是否开启Mock
|
||||||
|
VITE_USE_MOCK=true
|
||||||
|
@@ -14,7 +14,7 @@ const WX_DESC = envType == 'production' ? '正式环境' : '测试环境'
|
|||||||
(async () => {
|
(async () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const manifest = path.resolve(__dirname, './src/manifest.json')
|
const manifest = path.resolve(__dirname, './src/manifest.json')
|
||||||
console.log(manifest)
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const manifestConfig = JSON.parse(fs.readFileSync(manifest).toString())
|
const manifestConfig = JSON.parse(fs.readFileSync(manifest).toString())
|
||||||
const appId = manifestConfig['mp-weixin'].appid
|
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",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "uni -p mp-weixin",
|
"dev": "uni -p mp-weixin",
|
||||||
"build:test": "uni build --mode test -p mp-weixin",
|
"dev:test": "cross-env NODE_ENV=development node manifest.modify.ts && uni -p mp-weixin --mode development",
|
||||||
"build:prod": "uni build --mode production -p mp-weixin",
|
"dev:prod": "cross-env NODE_ENV=production node manifest.modify.ts && uni -p mp-weixin --mode production",
|
||||||
"deploy:test": "uni build --mode test -p mp-weixin && node deploy.ts test",
|
"build:test": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build --mode test",
|
||||||
"deploy:prod": "uni build --mode production -p mp-weixin && node deploy.ts production",
|
"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",
|
"type-check": "vue-tsc --noEmit",
|
||||||
"eslint": "eslint --fix",
|
"eslint": "eslint --fix",
|
||||||
"stylelint": "stylelint \"src/**/*.(vue|scss|css)\" --fix",
|
"stylelint": "stylelint \"src/**/*.(vue|scss|css)\" --fix",
|
||||||
@@ -15,53 +17,53 @@
|
|||||||
"postinstall": "simple-git-hooks"
|
"postinstall": "simple-git-hooks"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dcloudio/uni-app": "3.0.0-4000820240401001",
|
"@dcloudio/uni-app": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/uni-app-plus": "3.0.0-4000820240401001",
|
"@dcloudio/uni-app-plus": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/uni-components": "3.0.0-4000820240401001",
|
"@dcloudio/uni-components": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/uni-mp-weixin": "3.0.0-4000820240401001",
|
"@dcloudio/uni-mp-weixin": "3.0.0-alpha-4010520240507001",
|
||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"pinia": "2.0.36",
|
"pinia": "2.0.36",
|
||||||
"pinia-plugin-persistedstate": "^3.2.1",
|
"pinia-plugin-persistedstate": "^3.2.1",
|
||||||
"uview-plus": "^3.1.38",
|
"uview-plus": "^3.1.41",
|
||||||
"vue": "3.4.21",
|
"vue": "3.4.21",
|
||||||
"vue-i18n": "^9.9.0",
|
"vue-i18n": "^9.9.0",
|
||||||
"z-paging": "^2.6.2"
|
"z-paging": "^2.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "1.1.0",
|
"@antfu/eslint-config": "1.1.0",
|
||||||
"@dcloudio/types": "^3.4.3",
|
"@dcloudio/types": "^3.4.8",
|
||||||
"@dcloudio/uni-automator": "3.0.0-4000820240401001",
|
"@dcloudio/uni-automator": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
|
"@dcloudio/uni-cli-shared": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/uni-stacktracey": "3.0.0-4000820240401001",
|
"@dcloudio/uni-stacktracey": "3.0.0-alpha-4010520240507001",
|
||||||
"@dcloudio/vite-plugin-uni": "3.0.0-4000820240401001",
|
"@dcloudio/vite-plugin-uni": "3.0.0-alpha-4010520240507001",
|
||||||
"@types/node": "^20.8.10",
|
"@types/node": "^20.10.3",
|
||||||
"@typescript-eslint/parser": "^6.10.0",
|
"@typescript-eslint/parser": "^6.13.1",
|
||||||
"@uni-helper/uni-app-types": "^0.5.9",
|
"@uni-helper/uni-app-types": "^0.5.12",
|
||||||
"@unocss/eslint-plugin": "^0.57.2",
|
"@unocss/eslint-plugin": "^0.57.7",
|
||||||
"@vue/runtime-core": "^3.4.21",
|
"@vue/runtime-core": "^3.4.21",
|
||||||
"@vue/tsconfig": "^0.4.0",
|
"@vue/tsconfig": "^0.4.0",
|
||||||
"czg": "^1.7.1",
|
"czg": "^1.7.1",
|
||||||
"eslint": "^8.53.0",
|
"eslint": "^8.55.0",
|
||||||
"lint-staged": "^15.0.2",
|
"lint-staged": "^15.2.0",
|
||||||
"miniprogram-ci": "^1.9.8",
|
"miniprogram-ci": "^1.9.10",
|
||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"postcss-html": "^1.5.0",
|
"postcss-html": "^1.5.0",
|
||||||
"postcss-scss": "^4.0.9",
|
"postcss-scss": "^4.0.9",
|
||||||
"sass": "^1.69.5",
|
"sass": "^1.69.5",
|
||||||
"simple-git-hooks": "^2.9.0",
|
"simple-git-hooks": "^2.9.0",
|
||||||
"stylelint": "^15.11.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": "^34.0.0",
|
||||||
"stylelint-config-standard-vue": "^1.0.0",
|
"stylelint-config-standard-vue": "^1.0.0",
|
||||||
"stylelint-order": "^6.0.3",
|
"stylelint-order": "^6.0.3",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.3.2",
|
||||||
"unocss": "^0.57.2",
|
"unocss": "^0.57.7",
|
||||||
"unocss-applet": "^0.7.7",
|
"unocss-applet": "^0.7.8",
|
||||||
"unplugin-auto-import": "^0.16.7",
|
"unplugin-auto-import": "^0.16.7",
|
||||||
"unplugin-vue-components": "^0.25.2",
|
"unplugin-vue-components": "^0.25.2",
|
||||||
"vite": "^4.5.2",
|
"vite": "^5.2.8",
|
||||||
"vite-plugin-imagemin": "^0.6.1",
|
"vite-plugin-imagemin": "^0.6.1",
|
||||||
"vue-tsc": "^1.8.22"
|
"vue-tsc": "^1.8.24"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"src/**/*.{js,jsx,ts,tsx}": "eslint --fix",
|
"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
56
src/App.vue
56
src/App.vue
@@ -1,19 +1,27 @@
|
|||||||
<script lang='ts'>
|
<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 logManager = uni.getRealtimeLogManager();
|
const logger = new Logger();
|
||||||
const logger = logManager.tag('suke-mp');
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLaunch: async (options: any) => {
|
onLaunch: async (options: any) => {
|
||||||
console.log('App Launch options ', options);
|
|
||||||
|
|
||||||
const miniProgram = uni.getAccountInfoSync().miniProgram;
|
const miniProgram = uni.getAccountInfoSync().miniProgram;
|
||||||
const env = miniProgram.envVersion;
|
const env = miniProgram.envVersion;
|
||||||
|
|
||||||
logger.info(`launch options ${env}: `, options);
|
console.log(`App Launch options ${env}: `, options);
|
||||||
|
|
||||||
//生产
|
//生产
|
||||||
if(env === 'release' || env === 'trial') {
|
if(env === 'release') {
|
||||||
|
logger.info(`App Launch options ${env}: `, options);
|
||||||
|
|
||||||
async function getVersionStatus() {
|
async function getVersionStatus() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.request({
|
uni.request({
|
||||||
@@ -41,13 +49,20 @@ export default {
|
|||||||
|
|
||||||
//测试、开发 trial,develop
|
//测试、开发 trial,develop
|
||||||
else {
|
else {
|
||||||
// setCompanyId('1724629180555919361');
|
//生产环境
|
||||||
// setRegisterStoreId('1725026299888406529');
|
if(import.meta.env.VITE_APP_BASE_API.includes('api.lakeapp')) {
|
||||||
// setCompanyId('1471673498334113794');
|
// setCompanyId('1150930317231112193');
|
||||||
// setRegisterStoreId('1471673498413805570');
|
// setRegisterStoreId('1150930317436633090');
|
||||||
|
|
||||||
setCompanyId('1150930317231112193');
|
setCompanyId('1471673498334113794');
|
||||||
setRegisterStoreId('1150930317436633090');
|
setRegisterStoreId('1471673498413805570');
|
||||||
|
}
|
||||||
|
//测试
|
||||||
|
else {
|
||||||
|
setCompanyId('1724629180555919361');
|
||||||
|
setRegisterStoreId('1725026299888406529');
|
||||||
|
// setRegisterStoreId('17250262998884000000');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options?.query) {
|
if(options?.query) {
|
||||||
@@ -92,8 +107,19 @@ export default {
|
|||||||
}, 500);
|
}, 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
|
// #ifdef MP
|
||||||
mpUpdate();
|
mpUpdate();
|
||||||
// #endif
|
// #endif
|
||||||
@@ -106,7 +132,9 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
globalData: {
|
globalData: {
|
||||||
logger: logger
|
logger: logger,
|
||||||
|
companyId: getCompanyId(),
|
||||||
|
storeId: getRegisterStoreId()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ enum URL {
|
|||||||
login = '/wc/wechat/LoginByMa',
|
login = '/wc/wechat/LoginByMa',
|
||||||
loginByCode = '/wc/wechat/LoginByMaCode',
|
loginByCode = '/wc/wechat/LoginByMaCode',
|
||||||
register = '/wc/wechat/register',
|
register = '/wc/wechat/register',
|
||||||
|
telephone = '/wc/wechat/telephone',
|
||||||
uploadAvatar = '/wc/wechat/uploadImage',
|
uploadAvatar = '/wc/wechat/uploadImage',
|
||||||
logout = '/user/logout',
|
logout = '/user/logout',
|
||||||
// profile = '/user/profile',
|
// 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 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 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 register = (data: RegisterParams) => post<LoginResult>({ url: URL.register, data });
|
||||||
|
|
||||||
export const logout = () => post<any>({ url: URL.logout });
|
export const logout = () => post<any>({ url: URL.logout });
|
||||||
|
@@ -31,6 +31,7 @@ export interface LoginResult {
|
|||||||
user: UserBean;
|
user: UserBean;
|
||||||
userInfo: any;
|
userInfo: any;
|
||||||
token: string;
|
token: string;
|
||||||
|
maOpenId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IntegralBean {
|
export interface IntegralBean {
|
||||||
|
@@ -2,8 +2,8 @@
|
|||||||
"name": "SUKE-MP",
|
"name": "SUKE-MP",
|
||||||
"appid": "",
|
"appid": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"versionName": "3.0.1",
|
"versionName": "3.0.2",
|
||||||
"versionCode": "300",
|
"versionCode": "302",
|
||||||
"transformPx": false,
|
"transformPx": false,
|
||||||
"app-plus": {
|
"app-plus": {
|
||||||
"usingComponents": true,
|
"usingComponents": true,
|
||||||
@@ -18,13 +18,11 @@
|
|||||||
"modules": {}
|
"modules": {}
|
||||||
},
|
},
|
||||||
"mp-weixin": {
|
"mp-weixin": {
|
||||||
// "appid": "wx92e663dc11d0c0a8",
|
"appid": "wx67a750d0ceed4d88",
|
||||||
"appid": "wx67a750d0ceed4d88",
|
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false
|
"urlCheck": false
|
||||||
},
|
},
|
||||||
"usingComponents": true,
|
"usingComponents": true,
|
||||||
|
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"sqb-pay": {
|
"sqb-pay": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
|
@@ -38,6 +38,12 @@
|
|||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "肃客会员"
|
"navigationBarTitleText": "肃客会员"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/coupons/ticketsBuy/ticketsBuy",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "团购详情"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"subPackages": [
|
"subPackages": [
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<view class='swiper-container'>
|
<view class='swiper-container'>
|
||||||
<swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'>
|
<swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'>
|
||||||
<swiper-item v-for='(item,index) in bannerList' :key='index'>
|
<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-item>
|
||||||
</swiper>
|
</swiper>
|
||||||
<view class='indicator'>
|
<view class='indicator'>
|
||||||
@@ -174,12 +174,18 @@ onLoad(async (e: any) => {
|
|||||||
if(isLogin()) {
|
if(isLogin()) {
|
||||||
await uni.showLoading();
|
await uni.showLoading();
|
||||||
groupBuyBean.value = await getGroupBuyDetail(e.id);
|
groupBuyBean.value = await getGroupBuyDetail(e.id);
|
||||||
groupBuyBean.value.goods.price = groupBuyBean.value.price;
|
// setCompanyId('1512403904150138881');
|
||||||
bannerList.value = JSON.parse(groupBuyBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images);
|
// groupBuyBean.value = await getGroupBuyDetail('1740922051118063618');
|
||||||
countdown();
|
if(groupBuyBean.value) {
|
||||||
await fetchRecommendList();
|
groupBuyBean.value.goods.price = groupBuyBean.value.price;
|
||||||
await fetchBuyRecordList();
|
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();
|
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 = () => {
|
const isNotStated = () => {
|
||||||
return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now());
|
return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now());
|
||||||
};
|
};
|
||||||
|
|
||||||
const isPending = () => {
|
const isPending = () => {
|
||||||
return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now());
|
return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now());
|
||||||
;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isEnded = () => {
|
const isEnded = () => {
|
||||||
|
@@ -36,8 +36,9 @@ function wechatLogin() {
|
|||||||
showToast('请先阅读并同意小程序隐私保护协议');
|
showToast('请先阅读并同意小程序隐私保护协议');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showLoading();
|
uni.showLoading();
|
||||||
userStore.authLogin().then(() => {
|
userStore.login().then(() => {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.reLaunch({ url: '/pages/home/index' });
|
uni.reLaunch({ url: '/pages/home/index' });
|
||||||
});
|
});
|
||||||
|
@@ -1,228 +1,207 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class='content'>
|
<view class='content'>
|
||||||
<image class='bg-image' :src='assetsUrl("bg_register.png")' />
|
<view class='c-flex-column avatar-container'>
|
||||||
|
<image class='avatar' :src='avatarUrl' />
|
||||||
<image :src='assetsUrl("ic_register_gift_text.png")'
|
<button class='avatar-button' open-type='chooseAvatar' @chooseavatar='chooseAvatar' />
|
||||||
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>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
<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>
|
</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>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang='ts' setup>
|
<script lang='ts' setup>
|
||||||
import { assetsUrl, defaultImage } from '@/utils/assets';
|
import { ref } from 'vue';
|
||||||
|
import { getTelephone } from '@/api/user';
|
||||||
import { useUserStore } from '@/store';
|
import { useUserStore } from '@/store';
|
||||||
import { goPath } from '@/utils';
|
import { assetsUrl } from '@/utils/assets';
|
||||||
import { getRegisterCoupon } from '@/api/user';
|
import { getRegisterStoreId, getSessionKey, showToast } from '@/utils';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { companyConfigInfo } = storeToRefs(userStore);
|
const { userInfo } = storeToRefs(userStore);
|
||||||
|
|
||||||
const countdown = ref('获取验证码');
|
const birthday = ref(userInfo.value.birthday || dayjs().format('YYYY-MM-DD'));
|
||||||
const couponBean = ref();
|
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) => {
|
const chooseAvatar = (e: any) => {
|
||||||
couponBean.value = await getRegisterCoupon();
|
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 = () => {
|
const getPhoneNumber = (e: any) => {
|
||||||
if(countdown.value !== '获取验证码') {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let time = 120;
|
|
||||||
let interval = setInterval(() => {
|
|
||||||
time--;
|
|
||||||
countdown.value = `${time}s 重新获取`;
|
|
||||||
if(time == 0) {
|
|
||||||
clearInterval(interval);
|
|
||||||
countdown.value = '获取验证码';
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
const register = () => {
|
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'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
uni.hideLoading();
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang='scss' scoped>
|
<style lang='scss' scoped>
|
||||||
.content {
|
.content {
|
||||||
position: relative;
|
display: flex;
|
||||||
height: 100vh;
|
background: white;
|
||||||
}
|
padding: 30rpx;
|
||||||
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
border-bottom-style: dashed;
|
margin: 30rpx 5rpx;
|
||||||
border-color: #E98585;
|
|
||||||
border-width: 0.2rpx;
|
|
||||||
margin-top: 34rpx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.coupon {
|
.row-title {
|
||||||
margin-top: 30rpx;
|
font-size: 30rpx;
|
||||||
|
color: #666666;
|
||||||
|
width: 150rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.coupon-name {
|
.row-value {
|
||||||
display: flex;
|
font-size: 30rpx;
|
||||||
font-size: 36rpx;
|
color: #333333;
|
||||||
color: #D95554;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
image {
|
|
||||||
width: 13rpx;
|
|
||||||
height: 24rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.expired-time {
|
|
||||||
font-size: 28rpx;
|
|
||||||
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>
|
</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 { getCompanyList } from '@/api/company';
|
||||||
import { useUserStore } from '@/store';
|
import { useUserStore } from '@/store';
|
||||||
import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets';
|
import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets';
|
||||||
import { getCompanyId, goPath, isLogin } from '@/utils';
|
import { getOpenId, goPath, isLogin } from '@/utils';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { UserBean } from '@/store/modules/user/types';
|
import { UserBean } from '@/store/modules/user/types';
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ const submenuList = [
|
|||||||
title: '注册有礼',
|
title: '注册有礼',
|
||||||
icon: assetsUrl('ic_register_gift2.png'),
|
icon: assetsUrl('ic_register_gift2.png'),
|
||||||
path: '/pages/common/register/reward'
|
path: '/pages/common/register/reward'
|
||||||
|
// path: '/pages/coupons/ticketsBuy/ticketsBuy?couponsId=1797773484774432769'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '团购秒杀',
|
title: '团购秒杀',
|
||||||
@@ -127,48 +128,86 @@ onLoad((e) => {
|
|||||||
onShow(async () => {
|
onShow(async () => {
|
||||||
if(isLogin()) {
|
if(isLogin()) {
|
||||||
// userStore.getProfile();
|
// userStore.getProfile();
|
||||||
if(userInfo.value.maOpenId) {
|
fetchCompanyList();
|
||||||
fetchCompanyList();
|
|
||||||
} else {
|
|
||||||
await userStore.getProfile();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// setToken('42ae187265fb4688804fd294cbcf99f1')
|
// setToken('42ae187265fb4688804fd294cbcf99f1')
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '您还未登录,请先登录',
|
||||||
|
showCancel: true,
|
||||||
|
success: (res) => {
|
||||||
|
if(res.confirm) {
|
||||||
|
goPath('/pages/common/login/index');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const switchCompany = () => {
|
const switchCompany = () => {
|
||||||
fetchCompanyList((companyList: any[], userList: any[]) => {
|
fetchCompanyList((companyList: any[], userList: any[]) => {
|
||||||
companyDialogRef.value.show(getCompanyId(),(index: number) => {
|
companyDialogRef.value.show(getApp().globalData?.companyId, (index: number) => {
|
||||||
userStore.setUserInfo(userList[index]);
|
userStore.setUserInfo(userList[index]);
|
||||||
userStore.setCompanyInfo(companyList[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 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 => {
|
getCompanyList(maOpenId).then(res => {
|
||||||
companyList.value = res.map((res: { company: any }) => res.company);
|
companyList.value = res.map((res: { company: any }) => res.company);
|
||||||
userList.value = res.map((res: { user: any }) => res.user);
|
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) {
|
if(fn != undefined && fn instanceof Function) {
|
||||||
fn(companyList.value, userList.value);
|
fn(companyList.value, userList.value);
|
||||||
} else {
|
} 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(index < 0) {
|
||||||
|
if(!getApp()?.globalData?.storeId) {
|
||||||
|
goPath('/pages/common/register/index');
|
||||||
|
return;
|
||||||
|
}
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
userStore.setUserInfo(userList.value[index]);
|
userStore.setUserInfo(userList.value[index]);
|
||||||
userStore.setCompanyInfo(companyList.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 fetchData = async (status: number) => {
|
||||||
const { list } = await getCouponList({
|
const { list } = await getCouponList({
|
||||||
companyId: getCompanyId(),
|
companyId: getApp()?.globalData?.companyId,
|
||||||
memberId: userInfo.value?.id,
|
memberId: userInfo.value?.id,
|
||||||
status: status,
|
status: status,
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
|
@@ -147,6 +147,13 @@ onLoad(async (e: any) => {
|
|||||||
uni.hideLoading();
|
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 getStockColorCount = computed(() => {
|
||||||
const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName)))
|
const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName)))
|
||||||
.map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!);
|
.map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!);
|
||||||
|
@@ -49,7 +49,8 @@
|
|||||||
</text>
|
</text>
|
||||||
<view class='bottom-sku-view c-flex-row'>
|
<view class='bottom-sku-view c-flex-row'>
|
||||||
<text>
|
<text>
|
||||||
{{ item.checkedStock.colorName||'均色' }},{{ item.checkedStock.sizeName||'均码' }} x{{ item.checkedStock.count }}
|
{{ item.checkedStock.colorName || '均色' }},{{ item.checkedStock.sizeName || '均码' }}
|
||||||
|
x{{ item.checkedStock.count }}
|
||||||
</text>
|
</text>
|
||||||
<text>¥{{ item.price }}</text>
|
<text>¥{{ item.price }}</text>
|
||||||
</view>
|
</view>
|
||||||
@@ -160,16 +161,16 @@ const buildSqbParams = computed(() => {
|
|||||||
client_sn: orderBean.value?.id || '',
|
client_sn: orderBean.value?.id || '',
|
||||||
return_url: '/pages/common/payresult/index',
|
return_url: '/pages/common/payresult/index',
|
||||||
total_amount: Number(((totalPrice.value || 0) * 100).toFixed(2)),
|
total_amount: Number(((totalPrice.value || 0) * 100).toFixed(2)),
|
||||||
terminal_sn: terminalInfo.value.terminalSn,
|
terminal_sn: terminalInfo.value?.terminalSn,
|
||||||
subject: orderBean?.value?.orderGoods[0].name||'未知',
|
subject: orderBean?.value?.orderGoods[0].name || '未知',
|
||||||
subject_img: orderBean?.value?.orderGoods[0].images || '',
|
subject_img: orderBean?.value?.orderGoods[0].images || '',
|
||||||
merchant_name: terminalInfo.value.companyName,
|
merchant_name: terminalInfo.value?.companyName,
|
||||||
notify_url: 'https://www.baidu.com'
|
notify_url: 'https://www.baidu.com'
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...params,
|
...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 () => {
|
const createOrder = async () => {
|
||||||
|
if(!terminalInfo.value) {
|
||||||
|
showToast('当前店铺未配置收款渠道,请联系商家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
//邮寄
|
//邮寄
|
||||||
if(tabIndex.value == 1 && !deliveryAddress.value.addrid) {
|
if(tabIndex.value == 1 && !deliveryAddress.value.addrid) {
|
||||||
showToast('请选择收货地址');
|
showToast('请选择收货地址');
|
||||||
|
@@ -199,6 +199,7 @@ const showOfficialAccountDialog = () => {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
border-radius: 8rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.top-row {
|
.top-row {
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
<view class='c-flex-row'>
|
<view class='c-flex-row'>
|
||||||
<text>生日</text>
|
<text>生日</text>
|
||||||
<picker mode='date' :disabled='(userInfo.birthday?.length||0)!=0' @change='changeDate'>
|
<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>
|
</picker>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -80,7 +80,7 @@ const params = ref<{
|
|||||||
nickName: userInfo.value.nickName,
|
nickName: userInfo.value.nickName,
|
||||||
telephone: userInfo.value.telephone,
|
telephone: userInfo.value.telephone,
|
||||||
gender: userInfo.value.gender,
|
gender: userInfo.value.gender,
|
||||||
birthday: userInfo.value.birthday
|
birthday: userInfo.value.birthday|| dayjs().format('YYYY-MM-DD')
|
||||||
});
|
});
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
@@ -135,7 +135,7 @@ const save = async () => {
|
|||||||
|
|
||||||
const result = await updateProfile({
|
const result = await updateProfile({
|
||||||
...params.value,
|
...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
|
birthdayType: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -12,11 +12,11 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
|||||||
key: 'shoppingCartState',
|
key: 'shoppingCartState',
|
||||||
storage: {
|
storage: {
|
||||||
setItem(key, value) {
|
setItem(key, value) {
|
||||||
uni.setStorageSync(key, value || []); // [!code warning]
|
uni.setStorageSync(key, value); // [!code warning]
|
||||||
uni.setStorageSync(`shoppingCart_${getCompanyId()}`, JSON.parse(value).shoppingCartList);
|
uni.setStorageSync(`shoppingCart_${getCompanyId()}`, JSON.parse(value).shoppingCartList);
|
||||||
},
|
},
|
||||||
getItem(key) {
|
getItem(key) {
|
||||||
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)) || []; // [!code warning]
|
return uni.getStorageSync(uni.getStorageSync(`shoppingCart_${getCompanyId()}`)) || '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
// 部分持久化状态的点符号路径数组,[]意味着没有状态被持久化(默认为undefined,持久化整个状态)
|
||||||
@@ -33,12 +33,19 @@ const useShoppingCartStore = defineStore('shoppingCart', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
|
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
|
||||||
return state.shoppingCartList?.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId);
|
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: {
|
actions: {
|
||||||
save(partial: Partial<GoodsBean>) {
|
save(partial: Partial<GoodsBean>) {
|
||||||
|
if(!Array.isArray(this.shoppingCartList)) {
|
||||||
|
this.shoppingCartList = [];
|
||||||
|
}
|
||||||
this.shoppingCartList.push(partial as GoodsBean);
|
this.shoppingCartList.push(partial as GoodsBean);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -1,8 +1,16 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import type { providerType, UserBean } from './types';
|
import type { providerType, UserBean } from './types';
|
||||||
import { getTerminal, getUserProfile, login, logout as userLogout, register } from '@/api/user/index';
|
import { getTerminal, getUserProfile, login, logout as userLogout, register } from '@/api/user/index';
|
||||||
import { clearToken, getRegisterStoreId, setCompanyId, setToken } from '@/utils/auth';
|
import {
|
||||||
import type { LoginResult, RegisterParams, TerminalBean } from '@/api/user/types';
|
clearToken,
|
||||||
|
getCompanyId,
|
||||||
|
getRegisterStoreId,
|
||||||
|
setCompanyId,
|
||||||
|
setOpenId,
|
||||||
|
setSessionKey,
|
||||||
|
setToken
|
||||||
|
} from '@/utils/auth';
|
||||||
|
import type { RegisterParams, TerminalBean } from '@/api/user/types';
|
||||||
import { getCompanyInfo } from '@/api/company';
|
import { getCompanyInfo } from '@/api/company';
|
||||||
|
|
||||||
const useUserStore = defineStore('user', {
|
const useUserStore = defineStore('user', {
|
||||||
@@ -47,10 +55,6 @@ const useUserStore = defineStore('user', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
// getUserInfo(state: UserBean): UserBean {
|
|
||||||
// return { state };
|
|
||||||
// }
|
|
||||||
|
|
||||||
getUserDiscount(): number {
|
getUserDiscount(): number {
|
||||||
if(this.userInfo?.levelEntity?.discount > 0 && this.userInfo?.levelEntity?.discount < 10) {
|
if(this.userInfo?.levelEntity?.discount > 0 && this.userInfo?.levelEntity?.discount < 10) {
|
||||||
return this.userInfo?.levelEntity?.discount / 10;
|
return this.userInfo?.levelEntity?.discount / 10;
|
||||||
@@ -66,68 +70,7 @@ const useUserStore = defineStore('user', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
// 设置用户的信息
|
login(provider: providerType = 'weixin') {
|
||||||
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') {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
uni.login({
|
uni.login({
|
||||||
provider,
|
provider,
|
||||||
@@ -150,47 +93,110 @@ const useUserStore = defineStore('user', {
|
|||||||
// referrerUserId: getReferrerUserId()
|
// referrerUserId: getReferrerUserId()
|
||||||
});
|
});
|
||||||
getApp().globalData?.logger.info('login result: ', res);
|
getApp().globalData?.logger.info('login result: ', res);
|
||||||
|
setToken(res.token);
|
||||||
if(res.user == undefined || res.user.id === null) {
|
setSessionKey(res.sessionKey);
|
||||||
const registerForm = {
|
setOpenId(res.maOpenId);
|
||||||
unionId: res.user?.unionId,
|
if(res.user) {
|
||||||
openId: res.user?.openId,
|
this.setUserInfo(res.user);
|
||||||
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 {
|
} else {
|
||||||
setToken(res.token);
|
this.setUserInfo(res.userInfo);
|
||||||
await this.setUserInfo(res.user);
|
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
resolve(res);
|
resolve(res);
|
||||||
} else {
|
} else {
|
||||||
|
getApp().globalData?.logger.error('login error: ', result.errMsg);
|
||||||
reject(new Error(result.errMsg));
|
reject(new Error(result.errMsg));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: (err: any) => {
|
fail: (err: any) => {
|
||||||
console.error(`login error: ${err}`);
|
console.error(`login error: ${err}`);
|
||||||
|
getApp().globalData?.logger.error('login error: ', err);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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() {
|
async fetchTerminal() {
|
||||||
this.terminalInfo = await getTerminal(this.userInfo?.companyId);
|
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 assetsUrl = (name: string) => `https://img.lakeapp.cn/wx/images/${name}`;
|
||||||
export const defaultAvatar = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';
|
export const defaultAvatar = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';
|
||||||
|
|
||||||
export const defaultImage = '/static/images/ic_noimage.svg';
|
export const defaultImage = '/static/images/ic_noimage.svg';
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
const TokenKey = 'accessToken';
|
const TokenKey = 'accessToken';
|
||||||
|
const SessionKey = 'sessionKey';
|
||||||
|
const OpenIdKey = 'openId';
|
||||||
const CompanyIdKey = 'companyId';
|
const CompanyIdKey = 'companyId';
|
||||||
const ReferrerUserIdKey = 'referrerUserId';
|
const ReferrerUserIdKey = 'referrerUserId';
|
||||||
const RegisterStoreIdKey = 'storeId';
|
const RegisterStoreIdKey = 'storeId';
|
||||||
@@ -17,12 +19,33 @@ function setToken(token: string) {
|
|||||||
uni.setStorageSync(TokenKey, token);
|
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() {
|
function getCompanyId() {
|
||||||
return uni.getStorageSync(CompanyIdKey);
|
return uni.getStorageSync(CompanyIdKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCompanyId(companyId: string) {
|
function setCompanyId(companyId: string) {
|
||||||
uni.setStorageSync(CompanyIdKey, companyId);
|
if(companyId) {
|
||||||
|
uni.setStorageSync(CompanyIdKey, companyId);
|
||||||
|
if(getApp()?.globalData) {
|
||||||
|
getApp().globalData.companyId = companyId;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReferrerUserId() {
|
function getReferrerUserId() {
|
||||||
@@ -44,6 +67,7 @@ function getRegisterStoreId() {
|
|||||||
function clearToken() {
|
function clearToken() {
|
||||||
uni.removeStorageSync(TokenKey);
|
uni.removeStorageSync(TokenKey);
|
||||||
uni.removeStorageSync(CompanyIdKey);
|
uni.removeStorageSync(CompanyIdKey);
|
||||||
|
uni.removeStorageSync(SessionKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -51,6 +75,10 @@ export {
|
|||||||
isLogin,
|
isLogin,
|
||||||
getToken,
|
getToken,
|
||||||
setToken,
|
setToken,
|
||||||
|
getSessionKey,
|
||||||
|
setSessionKey,
|
||||||
|
getOpenId,
|
||||||
|
setOpenId,
|
||||||
getCompanyId,
|
getCompanyId,
|
||||||
setCompanyId,
|
setCompanyId,
|
||||||
getReferrerUserId,
|
getReferrerUserId,
|
||||||
|
36
src/utils/common/logger.ts
Normal file
36
src/utils/common/logger.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import RealtimeTagLogManager = UniNamespace.RealtimeTagLogManager;
|
||||||
|
|
||||||
|
export class Logger {
|
||||||
|
|
||||||
|
private env = uni.getAccountInfoSync().miniProgram.envVersion;
|
||||||
|
private readonly logger: RealtimeTagLogManager;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
const logManager = uni.getRealtimeLogManager();
|
||||||
|
this.logger = logManager.tag('suke-mp');
|
||||||
|
}
|
||||||
|
|
||||||
|
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 type { HttpError, HttpRequestConfig, HttpResponse } from 'uview-plus/libs/luch-request';
|
||||||
import { showMessage } from './status';
|
|
||||||
import { getCompanyId, getToken } from '@/utils/auth';
|
import { getCompanyId, getToken } from '@/utils/auth';
|
||||||
import useUserStore from '@/store/modules/user';
|
import { showMessage } from '@/utils/request/status';
|
||||||
|
import { useUserStore } from '@/store';
|
||||||
|
|
||||||
// 是否正在刷新token的标记
|
// 是否正在刷新token的标记
|
||||||
let isRefreshing: boolean = false;
|
let isRefreshing: boolean = false;
|
||||||
@@ -26,6 +26,7 @@ function requestInterceptors() {
|
|||||||
|
|
||||||
// config.header.contentType = "x-www-form-urlencoded"
|
// config.header.contentType = "x-www-form-urlencoded"
|
||||||
}
|
}
|
||||||
|
getApp().globalData?.logger.info('request: ', config);
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
(
|
(
|
||||||
@@ -52,18 +53,20 @@ function responseInterceptors() {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getApp().globalData?.logger.info('response: ', data);
|
||||||
|
|
||||||
// 请求成功则返回结果
|
// 请求成功则返回结果
|
||||||
if(data.code === 200 || data?.retcode == 0) {
|
if(data.code === 200 || data?.retcode == 0) {
|
||||||
return data || {};
|
return data || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 登录状态失效,重新登录
|
// 登录状态失效,重新登录
|
||||||
if(data.code === 401) {
|
if(data.code === 4011 || data?.retcode === 4011) {
|
||||||
// 是否在获取token中,防止重复获取
|
// 是否在获取token中,防止重复获取
|
||||||
if(!isRefreshing) {
|
if(!isRefreshing) {
|
||||||
// 修改登录状态为true
|
// 修改登录状态为true
|
||||||
isRefreshing = true;
|
isRefreshing = true;
|
||||||
await useUserStore().authLogin();
|
await useUserStore().login();
|
||||||
// 登录完成之后,开始执行队列请求
|
// 登录完成之后,开始执行队列请求
|
||||||
requestQueue.forEach(cb => cb());
|
requestQueue.forEach(cb => cb());
|
||||||
// 重试完了清空这个队列
|
// 重试完了清空这个队列
|
||||||
@@ -96,12 +99,15 @@ function responseInterceptors() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
(response: HttpError) => {
|
(response: HttpError) => {
|
||||||
|
console.error('http error: ', response);
|
||||||
|
/* 对响应错误做点什么 (statusCode !== 200)*/
|
||||||
|
getApp().globalData?.logger.error('request error : ', response);
|
||||||
if(response.statusCode) {
|
if(response.statusCode) {
|
||||||
// 请求已发出,但是不在2xx的范围
|
// 请求已发出,但是不在2xx的范围
|
||||||
showMessage(response.statusCode);
|
uni.$u.toast(showMessage(response.statusCode));
|
||||||
return Promise.reject(response.data);
|
return Promise.reject(response.data);
|
||||||
}
|
}
|
||||||
showMessage('网络连接异常,请稍后再试!');
|
uni.$u.toast('网络连接异常,请稍后再试!');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ export const showMessage = (status: number | string): string => {
|
|||||||
message = 'HTTP版本不受支持(505)';
|
message = 'HTTP版本不受支持(505)';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message = `连接出错(${status})!`;
|
message = `操作失败(${status})!`;
|
||||||
}
|
}
|
||||||
return `${message},请检查网络或联系管理员!`;
|
return `${message},请检查网络或联系管理员!`;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user