风格统一样式修改

pull/34/head
落日晚风 2024-01-02 17:31:05 +08:00
commit dbeb6eea6b
26 changed files with 235 additions and 385 deletions

View File

@ -38,7 +38,7 @@
</view>
<view class="check-box ss-flex ss-col-center ss-p-l-10">
<view class="userInfo-money ss-m-r-10" v-if="item.value === 'wallet'">
余额: {{ fen2yuan(userInfo.money) }}
余额: {{ fen2yuan(userWallet.money) }}
</view>
<radio
:value="item.value"
@ -83,7 +83,7 @@
import PayChannelApi from '@/sheep/api/pay/channel';
import { getPayMethods } from '@/sheep/platform/pay';
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
//
const state = reactive({
@ -189,6 +189,8 @@
state.orderType = options.orderType;
}
setOrder(id);
//
sheep.$store('user').getWallet();
});
</script>

View File

@ -9,7 +9,7 @@
]">
<view class="">
<view class="num-title">当前余额</view>
<view class="wallet-num">{{ fen2yuan(userInfo.money) }}</view>
<view class="wallet-num">{{ fen2yuan(userWallet.balance) }}</view>
</view>
<button class="ss-reset-button log-btn" @tap="sheep.$router.go('/pages/pay/recharge-log')">
充值记录
@ -48,7 +48,7 @@
import { fen2yuan } from '@/sheep/hooks/useGoods';
import PayWalletApi from '@/sheep/api/pay/wallet';
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
const headerBg = sheep.$url.css('/static/img/shop/user/withdraw_bg.png');

View File

@ -52,7 +52,6 @@
/>
</uni-list>
</view>
<!-- TODO 芋艿统一的配置界面 -->
<view class="set-footer ss-flex-col ss-row-center ss-col-center">
<view class="agreement-box ss-flex ss-col-center ss-m-b-40">
<view class="ss-flex ss-col-center ss-m-b-10">
@ -99,6 +98,7 @@
<script setup>
import sheep from '@/sheep';
import { computed, reactive } from 'vue';
import AuthUtil from '@/sheep/api/member/auth';
const appInfo = computed(() => sheep.$store('app').info);
const isLogin = computed(() => sheep.$store('user').isLogin);
@ -123,10 +123,12 @@
if (!res.confirm) {
return;
}
const result = await sheep.$store('user').logout();
if (result) {
sheep.$router.go('/pages/index/user');
const { code } = await AuthUtil.logout();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
sheep.$router.go('/pages/index/user');
},
});
}
@ -140,10 +142,12 @@
if (!res.confirm) {
return;
}
const result = await sheep.$store('user').logout();
if (result) {
sheep.$router.go('/pages/index/user');
const { code } = await AuthUtil.logout();
if (code !== 0) {
return;
}
sheep.$store('user').logout();
sheep.$router.go('/pages/index/user');
},
});
}

View File

@ -13,7 +13,7 @@
/>
</view>
<view class="ss-flex ss-row-between ss-col-center ss-m-t-64">
<view class="money-num">{{ state.showMoney ? fen2yuan(userInfo.money) : '*****' }}</view>
<view class="money-num">{{ state.showMoney ? fen2yuan(userWallet.balance) : '*****' }}</view>
<button class="ss-reset-button topup-btn" @tap="sheep.$router.go('/pages/pay/recharge')">
充值
</button>
@ -122,7 +122,8 @@
value: '2',
},
];
const userInfo = computed(() => sheep.$store('user').userInfo);
const userWallet = computed(() => sheep.$store('user').userWallet);
//
const dateFilterText = computed(() => {
@ -167,6 +168,8 @@
state.date = [state.today, state.today];
getLogList();
getSummary();
//
sheep.$store('user').getWallet();
});
// tab

View File

@ -1,18 +1,6 @@
import request from '@/sheep/request';
export default {
// 系统初始化
init: (templateId) =>
request({
url: 'init',
params: {
templateId,
},
custom: {
showError: false,
showLoading: false,
},
}),
// 自定义页面
page: (id) =>
request({

View File

@ -1,10 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
faq: () =>
request({
url: 'data/faq',
method: 'GET',
}),
};

View File

@ -1,14 +0,0 @@
import request2 from '@/sheep/request2';
export default {
decorate: () =>
request2({
url: 'promotion/decorate/list?page=1',
method: 'GET',
}),
spids: () =>
request2({
url: 'product/spu/page?recommendType=best&pageNo=1&pageSize=10',
method: 'GET',
}),
};

View File

@ -1,6 +1,19 @@
import request from '@/sheep/request';
const AuthUtil = {
// 使用手机 + 密码登录
login: (data) => {
return request({
url: '/app-api/member/auth/login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登录中',
successMsg: '登录成功',
},
});
},
// 使用手机 + 验证码登录
smsLogin: (data) => {
return request({

View File

@ -1,6 +1,17 @@
import request from '@/sheep/request';
const UserApi = {
// 获得基本信息
getUserInfo: () => {
return request({
url: '/app-api/member/user/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 修改基本信息
updateUser: (data) => {
return request({

View File

@ -1,16 +1,6 @@
import request from '@/sheep/request';
export default {
// 预支付
prepay: (data) =>
request({
url: 'pay/prepay',
method: 'POST',
data,
custom: {
loadingMsg: '支付中',
},
}),
// 发起提现
withdraw: {
list: (params) =>

View File

@ -1,6 +1,17 @@
import request from '@/sheep/request';
const PayWalletApi = {
// 获取钱包
getPayWallet() {
return request({
url: '/app-api/pay/wallet/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 获得钱包流水分页
getWalletTransactionPage: (params) => {
const queryString = Object.keys(params)

View File

@ -57,6 +57,17 @@ const CouponApi = {
params: { id },
});
},
// 获得未使用的优惠劵数量
getUnusedCouponCount: () => {
return request({
url: '/app-api/promotion/coupon/get-unused-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
}
};
export default CouponApi;

View File

@ -1,4 +1,3 @@
import request2 from '@/sheep/request2';
import request from '@/sheep/request';
const OrderApi = {
@ -26,14 +25,14 @@ const OrderApi = {
const queryString = Object.keys(data2)
.map((key) => key + '=' + data2[key])
.join('&');
return request2({
return request({
url: `trade/order/settlement?${queryString}`,
method: 'GET',
});
},
// 创建订单
createOrder: (data) => {
return request2({
return request({
url: `trade/order/create`,
method: 'POST',
data,
@ -41,7 +40,7 @@ const OrderApi = {
},
// 获得订单
getOrder: (id) => {
return request2({
return request({
url: `trade/order/get-detail`,
method: 'GET',
params: {
@ -62,7 +61,7 @@ const OrderApi = {
},
// 确认收货
receiveOrder: (id) => {
return request2({
return request({
url: `/app-api/trade/order/receive`,
method: 'PUT',
params: {
@ -72,7 +71,7 @@ const OrderApi = {
},
// 取消订单
cancelOrder: (id) => {
return request2({
return request({
url: `/app-api/trade/order/cancel`,
method: 'DELETE',
params: {
@ -82,7 +81,7 @@ const OrderApi = {
},
// 删除订单
deleteOrder: (id) => {
return request2({
return request({
url: `/app-api/trade/order/delete`,
method: 'DELETE',
params: {
@ -90,9 +89,20 @@ const OrderApi = {
},
});
},
// 获得交易订单数量
getOrderCount: () => {
return request({
url: '/app-api/trade/order/get-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
});
},
// 创建单个评论
createOrderItemComment: (data) => {
return request2({
return request({
url: `/app-api/trade/order/item/create-comment`,
method: 'POST',
data,

View File

@ -3,100 +3,8 @@ import request2 from '@/sheep/request2';
import $platform from '@/sheep/platform';
export default {
getUnused: () =>
request2({
url: 'promotion/coupon/get-unused-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
profile: () =>
request2({
url: 'member/user/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
balance: () =>
request2({
url: '/app-api/pay/wallet/get',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
// 账号登录
accountLogin: (data) =>
request({
url: '/user/api/user/accountLogin',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登录中',
},
}),
// 短信登录
smsLogin: (data) =>
request({
url: '/user/api/user/smsLogin',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登录中',
},
}),
// 短信注册
smsRegister: (data) =>
request({
url: '/user/api/user/smsRegister',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '正在注册',
},
}),
// 绑定、更换手机号
changeMobile: (data) =>
request({
url: '/user/api/user/changeMobile',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '验证中',
},
}),
// 更新小程序信息
updateMpUserInfo: (data) =>
request({
url: '/user/api/user/updateMpUserInfo',
method: 'POST',
data,
}),
// 第三方授权信息
thirdOauthInfo: () =>
request({
url: '/user/api/user/thirdOauth',
method: 'GET',
params: {
provider: $platform.provider,
platform: $platform.platform,
},
custom: {
showLoading: false,
},
}),
// 添加分享记录
addShareLog: (data) =>
@ -116,30 +24,8 @@ export default {
params,
}),
},
// 账号登出
logout: (data) =>
request({
url: '/user/api/user/logout',
method: 'POST',
data,
}),
// 账号注销
logoff: (data) =>
request({
url: '/user/api/user/logoff',
method: 'POST',
data,
}),
address: {
// default: () =>
// request({
// url: 'user/address/default',
// method: 'GET',
// custom: {
// showError: false,
// },
// }),
default: () =>
request2({
url: 'member/address/get-default',
@ -278,33 +164,5 @@ export default {
auth: true,
},
}),
},
//数量接口
// data: () =>
// request({
// url: 'user/user/data',
// method: 'GET',
// custom: {
// showLoading: false,
// auth: true,
// },
// }),
data: () =>
request2({
url: 'trade/order/get-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
data2: () =>
request2({
url: 'trade/after-sale/get-applying-count',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
}
};

View File

@ -21,8 +21,8 @@
labelWidth="140"
labelAlign="center"
>
<uni-forms-item name="account" label="账号">
<uni-easyinput placeholder="请输入账号" v-model="state.model.account" :inputBorder="false">
<uni-forms-item name="mobile" label="账号">
<uni-easyinput placeholder="请输入账号" v-model="state.model.mobile" :inputBorder="false">
<template v-slot:right>
<button class="ss-reset-button forgot-btn" @tap="showAuthModal('resetPassword')">
忘记密码
@ -48,10 +48,11 @@
</template>
<script setup>
import { computed, watch, ref, reactive, unref } from 'vue';
import { ref, reactive, unref } from 'vue';
import sheep from '@/sheep';
import { account, password } from '@/sheep/validate/form';
import { mobile, password } from '@/sheep/validate/form';
import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
import AuthUtil from '@/sheep/api/member/auth';
const accountLoginRef = ref(null);
@ -63,19 +64,20 @@
default: false,
},
});
//
const state = reactive({
model: {
account: '', //
mobile: '', //
password: '', //
},
rules: {
account,
mobile,
password,
},
});
// 1.
//
async function accountLoginSubmit() {
//
const validate = await unref(accountLoginRef)
@ -93,12 +95,10 @@
}
//
sheep.$api.user.accountLogin(state.model).then((res) => {
if (res.error === 0) {
// sheep.$store('user').getInfo();
closeAuthModal();
}
});
const { code, data } = await AuthUtil.login(state.model);
if (code === 0) {
closeAuthModal();
}
}
</script>

View File

@ -9,11 +9,11 @@
>
<uni-badge
class="uni-badge-left-margin"
:text="numData.order_num[item.type]"
:text="numData.orderCount[item.count]"
absolute="rightTop"
size="small"
>
<image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit"></image>
<image class="item-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit" />
</uni-badge>
<view class="menu-title ss-m-t-28">{{ item.title }}</view>
</view>
@ -34,6 +34,7 @@
icon: '/static/img/shop/order/no_pay.png',
path: '/pages/order/list',
type: 'unpaid',
count: 'unpaidCount',
},
{
title: '待收货',
@ -41,6 +42,7 @@
icon: '/static/img/shop/order/no_take.png',
path: '/pages/order/list',
type: 'noget',
count: 'deliveredCount',
},
{
title: '待评价',
@ -48,6 +50,7 @@
icon: '/static/img/shop/order/no_comment.png',
path: '/pages/order/list',
type: 'nocomment',
count: 'uncommentedCount',
},
{
title: '售后单',
@ -55,6 +58,7 @@
icon: '/static/img/shop/order/change_order.png',
path: '/pages/order/aftersale/list',
type: 'aftersale',
count: 'afterSaleCount',
},
{
title: '全部订单',
@ -65,7 +69,6 @@
];
const numData = computed(() => sheep.$store('user').numData);
console.log('更换后的yuda订单数量',numData)
</script>
<style lang="scss" scoped>

View File

@ -23,18 +23,17 @@
</view>
</view>
<!-- TODO @芋艿用户接入 -->
<!-- 提示绑定手机号 先隐藏 yudao 需要再修改 -->
<!-- <view
<view
class="bind-mobile-box ss-flex ss-row-between ss-col-center"
v-if="isLogin && !userInfo.verification?.mobile"
v-if="isLogin && !userInfo.mobile"
>
<view class="ss-flex">
<text class="cicon-mobile-o"></text>
<text class="cicon-mobile-o" />
<view class="mobile-title ss-m-l-20"> 点击绑定手机号确保账户安全 </view>
</view>
<button class="ss-reset-button bind-btn" @tap="onBind"></button>
</view> -->
</view>
</view>
</template>

View File

@ -4,7 +4,7 @@
<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/money')">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text ss-line-1">{{ fen2yuan(userInfo.money) || '0.00' }}</view>
<view class="value-text ss-line-1">{{ fen2yuan(userWallet.balance) || '0.00' }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">账户余额</view>
@ -12,7 +12,7 @@
<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/score')">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text">{{ userInfo.point || '0.00' }}</view>
<view class="value-text">{{ userInfo.point || 0 }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">积分</view>
@ -23,15 +23,14 @@
})
">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text">{{ numData.coupons_num || '0.00' }}</view>
<view class="value-text">{{ numData.unusedCouponCount }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">优惠券</view>
</view>
<view class="menu-item ss-flex-col ss-row-center ss-col-center menu-wallet"
@tap="sheep.$router.go('/pages/user/wallet/money')">
<image class="item-icon" :src="sheep.$url.static('/static/img/shop/user/wallet_icon.png')" mode="aspectFit">
</image>
@tap="sheep.$router.go('/pages/user/wallet/money')">
<image class="item-icon" :src="sheep.$url.static('/static/img/shop/user/wallet_icon.png')" mode="aspectFit" />
<view class="menu-title ss-m-t-30">我的钱包</view>
</view>
</view>
@ -41,13 +40,11 @@
/**
* 装修组件 - 订单菜单组
*/
import {
computed,
ref
} from 'vue';
import { computed } from 'vue';
import sheep from '@/sheep';
import { fen2yuan } from '../../hooks/useGoods';
const userWallet = computed(() => sheep.$store('user').userWallet);
const userInfo = computed(() => sheep.$store('user').userInfo);
const numData = computed(() => sheep.$store('user').numData);
</script>

View File

@ -94,8 +94,7 @@ http.interceptors.request.use(
if (config.url.indexOf('/app-api/') !== -1) {
config.header['Accept'] = '*/*'
config.header['tenant-id'] = '1';
config.header['terminal'] = '20';
config.header['Authorization'] = 'Bearer test247';
config.header['terminal'] = '20';
}
return config;
},
@ -109,14 +108,10 @@ http.interceptors.request.use(
*/
http.interceptors.response.use(
(response) => {
// 自动设置登陆令牌
if (response.header.authorization || response.header.Authorization) {
$store('user').setToken(response.header.authorization || response.header.Authorization);
}
// TODO 芋艿:如果是登录的 API则自动设置 token
if (response.data?.data?.accessToken) {
$store('user').setToken(response.data.data.accessToken);
}
// 约定:如果是 /auth/ 下的 URL 地址,并且返回了 accessToken 说明是登录相关的接口,则自动设置登陆令牌
if (response.config.url.indexOf('/member/auth/') >= 0 && response.data?.data?.accessToken) {
$store('user').setToken(response.data.data.accessToken);
}
response.config.custom.showLoading && closeLoading();
if (response.data.error !== 0 && response.data.code !== 0) {

View File

@ -152,7 +152,7 @@ http.interceptors.response.use(
} else {
errorMessage = '请先登录';
}
userStore.logout(true);
userStore.logout();
showAuthModal();
break;
case 403:

View File

@ -58,10 +58,10 @@ const _go = (
}
// 页面登录拦截
// if (nextRoute.meta?.auth && !$store('user').isLogin) {
// showAuthModal();
// return;
// }
if (nextRoute.meta?.auth && !$store('user').isLogin) {
showAuthModal();
return;
}
url = page;
if (!isEmpty(query)) {

View File

@ -50,7 +50,7 @@ const app = defineStore({
actions: {
// 获取Shopro应用配置和模板
async init(templateId = null) {
//检查网络
// 检查网络
const networkStatus = await $platform.checkNetwork();
if (!networkStatus) {
$router.error('NetworkError');
@ -58,19 +58,36 @@ const app = defineStore({
// 加载装修配置
await adaptTemplate(this.template, templateId)
const res = await appApi.init(templateId);
if (res.error === 0) {
this.info = res.data.app;
this.platform = res.data.platform;
// TODO 芋艿:未接入
// this.template = res.data.template;
// this.has_wechat_trade_managed = res.data.has_wechat_trade_managed;
// if (!res.data.template) {
// $router.error('TemplateError');
// }
// TODO 芋艿:未接入
// this.chat = res.data.chat;
// TODO 芋艿:未来支持管理后台可配;对应 https://api.shopro.sheepjs.com/shop/api/init
if (true) {
this.info = {
name: '芋道商城',
logo: 'https://static.iocoder.cn/ruoyi-vue-pro-logo.png',
version: '1.1.13',
copyright: '全部开源,个人与企业可 100% 免费使用',
copytime: 'Copyright© 2018-2024',
cdnurl: 'https://file.sheepjs.com', // 云存储域名
filesystem: 'qcloud', // 云存储平台
};
this.platform = {
share: {
methods: [ "poster", "link" ],
linkAddress: "https://shopro.sheepjs.com/#/",
posterInfo: {
"user_bg": "/static/img/shop/config/user-poster-bg.png",
"goods_bg": "/static/img/shop/config/goods-poster-bg.png",
"groupon_bg": "/static/img/shop/config/groupon-poster-bg.png"
}
},
bind_mobile: 0
};
this.chat = {
chat_domain: "https://api.shopro.sheepjs.com/chat",
room_id: "admin"
}
this.has_wechat_trade_managed = 0;
// 加载主题
const sysStore = sys();

View File

@ -85,9 +85,12 @@ const cart = defineStore({
}
},
// 清空购物车
async emptyList() {
await this.delete(this.list.map((item) => item.id));
// 清空购物车。注意,仅用于用户退出时,重置数据
emptyList() {
this.list = [];
this.selectedIds = [];
this.isAllSelected = true;
this.totalPriceSelected = 0;
},
},
persist: {

View File

@ -3,14 +3,13 @@ import { defineStore } from 'pinia';
const modal = defineStore({
id: 'modal',
state: () => ({
auth: '', // 授权弹框 accountLogin|smsLogin|smsRegister|resetPassword|changeMobile|changePassword|changeUsername
auth: '', // 授权弹框 accountLogin|smsLogin|resetPassword|changeMobile|changePassword|changeUsername
share: false, // 分享弹框
menu: false, // 快捷菜单弹框
advHistory: [], // 广告弹框记录
lastTimer: {
// 短信验证码计时器,为了防止刷新请求做了持久化
smsLogin: 0,
smsRegister: 0,
changeMobile: 0,
resetPassword: 0,
changePassword: 0,

View File

@ -15,6 +15,10 @@ import {
} from '@/sheep/hooks/useModal';
import AuthUtil from '@/sheep/api/member/auth';
import BrokerageApi from '@/sheep/api/trade/brokerage';
import UserApi from '@/sheep/api/member/user';
import PayWalletApi from '@/sheep/api/pay/wallet';
import OrderApi from '@/sheep/api/trade/order';
import CouponApi from '@/sheep/api/promotion/coupon';
// 默认用户信息
const defaultUserInfo = {
@ -22,20 +26,24 @@ const defaultUserInfo = {
nickname: '', // 昵称
gender: 0, // 性别
mobile: '', // 手机号
money: '--', // 余额
score: '--', // 积分 TODO 芋艿:改成 point
verification: {}, // 认证字段
point: 0, // 积分
};
// 默认钱包信息
const defaultUserWallet = {
balance: 0, // 余额
}
// 默认订单、优惠券等其他资产信息
const defaultNumData = {
coupons_num: '--',
order_num: {
aftersale: 0,
nocomment: 0,
noget: 0,
nosend: 0,
unpaid: 0,
unusedCouponCount: 0,
orderCount: {
allCount: 0,
unpaidCount: 0,
undeliveredCount: 0,
deliveredCount: 0,
uncommentedCount: 0,
afterSaleCount: 0,
},
};
@ -43,55 +51,44 @@ const user = defineStore({
id: 'user',
state: () => ({
userInfo: clone(defaultUserInfo), // 用户信息
userWallet: clone(defaultUserWallet), // 用户钱包信息
isLogin: !!uni.getStorageSync('token'), // 登录状态
numData: cloneDeep(defaultNumData), // 用户其他数据
lastUpdateTime: 0, // 上次更新时间
}),
actions: {
// 获取个人信息
// TODO 芋艿:整理下;
// 获取用户信息
async getInfo() {
const {
code,
data
} = await userApi.profile();
// 为了兼容 获取用户余额 可能还会用到其他参数
// 优惠券数量,积分数量 应该在这里
const {
code: code2,
data: data2
} = await userApi.balance();
if (code !== 0 || code2 != 0) return;
data.money = data2.balance;
this.userInfo = data;
// console.log(data2, '信息')
const { code, data } = await UserApi.getUserInfo();
if (code !== 0) {
return;
}
this.userInfo = data;
return Promise.resolve(data);
},
// 获得用户钱包
async getWallet() {
const { code, data } = await PayWalletApi.getPayWallet();
if (code !== 0) {
return;
}
this.userWallet = data;
},
// 获取订单、优惠券等其他资产信息
// TODO 芋艿:整理下;
async getNumData() {
const {
code,
data
} = await userApi.data();
const data2 = await userApi.data2();
let data3 = await userApi.getUnused();
// console.log(data3.data, '优惠券')
if (code === 0 && data2.code === 0) {
// console.log('订单数据', data);
this.numData = {
coupons_num: data3.data,
order_num: {
noget: data.deliveredCount,
unpaid: data.unpaidCount,
nocomment: data.uncommentedCount,
aftersale: data2.data
}
};
}
getNumData() {
OrderApi.getOrderCount().then(res => {
if (res.code === 0) {
this.numData.orderCount = res.data;
}
});
CouponApi.getUnusedCouponCount().then(res => {
if (res.code === 0) {
this.numData.unusedCouponCount = res.data;
}
});
},
// 添加分享记录
@ -103,8 +100,8 @@ const user = defineStore({
if (error === 0) uni.removeStorageSync('shareLog');
},
// 设置token
// TODO 芋艿:整理下;
// 设置 token
// TODO 芋艿:后续要支持访问令牌的刷新!!!
setToken(token = '') {
if (token === '') {
this.isLogin = false;
@ -117,42 +114,52 @@ const user = defineStore({
return this.isLogin;
},
// 更新用户相关信息 (手动限流 5秒之内不刷新)
// TODO 芋艿:整理下;
// 更新用户相关信息 (手动限流5 秒之内不刷新)
async updateUserData() {
if (!this.isLogin) {
this.resetUserData();
return;
}
// 防抖5 秒之内不刷新
const nowTime = new Date().getTime();
if (this.lastUpdateTime + 5000 > nowTime) return;
if (this.lastUpdateTime + 5000 > nowTime) {
return;
}
this.lastUpdateTime = nowTime;
// 获取最新信息
await this.getInfo();
this.getWallet();
this.getNumData();
this.lastUpdateTime = nowTime;
return this.userInfo;
},
// 重置用户默认数据
// TODO 芋艿:整理下;
resetUserData() {
// 清空 token
this.setToken();
// 清空用户相关的缓存
this.userInfo = clone(defaultUserInfo);
this.userWallet = clone(defaultUserWallet);
this.numData = cloneDeep(defaultNumData);
this.agentInfo = {};
// 清空购物车的缓存
cart().emptyList();
},
// 登录后
// 登录后,加载各种信息
// TODO 芋艿:整理下;
async loginAfter() {
await this.updateUserData();
// 加载购物车
cart().getList();
// 登录后设置全局分享参数
$share.getShareInfo();
// 提醒绑定手机号
// if (app().platform.bind_mobile && !this.userInfo.verification?.mobile) {
// showAuthModal('changeMobile');
// }
if (app().platform.bind_mobile && !this.userInfo.mobile) {
showAuthModal('changeMobile');
}
// 添加分享记录
// TODO 芋艿:整理下;
@ -164,21 +171,11 @@ const user = defineStore({
}
},
// 登出
// TODO 芋艿:整理下;
async logout(force = false) {
if (!force) {
const { code } = AuthUtil.logout();
if (code === 0) {
this.resetUserData();
}
}
if (force) {
this.resetUserData();
}
// 登出系统
async logout() {
this.resetUserData();
return !this.isLogin;
},
}
},
persist: {
enabled: true,

View File

@ -22,24 +22,6 @@ export const mobile = {
],
};
// 账户
export const account = {
rules: [
{
required: true,
errorMessage: '请输入账号',
},
{
validateFunction: function (rule, value, data, callback) {
if (value.length < 5) {
callback('账号长度不能小于5位');
}
return true;
},
},
],
};
// 密码
export const password = {
rules: [
@ -58,24 +40,6 @@ export const password = {
],
};
// 昵称
export const username = {
rules: [
{
required: true,
errorMessage: '请输入用户名',
},
{
validateFunction: function (rule, value, data, callback) {
if (value.length < 5) {
callback('用户名长度不能小于5位');
}
return true;
},
},
],
};
// 短信验证码
export const code = {
rules: [
@ -195,7 +159,6 @@ export default {
realName,
password,
code,
account,
taxNo,
taxName,
};