提交信息
Some checks are pending
deploy / deploy (push) Waiting to run

This commit is contained in:
sjeam 2025-07-22 17:09:25 +08:00
parent 013373d61f
commit 3b1e06937d
9 changed files with 859 additions and 862 deletions

View File

@ -318,10 +318,10 @@ be imported.
``` ```
此时升级微信开发者工具,或者安装`@babel/plugin-proposal-private-property-in-object`依赖即可解决问题。 此时升级微信开发者工具,或者安装`@babel/plugin-proposal-private-property-in-object`依赖即可解决问题。
### 捐赠 <!-- ### 捐赠
如果你觉得这个项目对你有帮助,你可以请作者喝饮料🍹 如果你觉得这个项目对你有帮助,你可以请作者喝饮料🍹
<p align='center'> <p align='center'>
<img alt="微信收款码" src="./src/static/images/pay.png" height="330" style="display:inline-block; height:330px;"> <img alt="微信收款码" src="./src/static/images/pay.png" height="330" style="display:inline-block; height:330px;">
</p> </p> -->

View File

@ -2,21 +2,23 @@
* *
*/ */
import type { CommonRes } from '@/api/common/types'; import type { CommonRes } from '@/api/common/types';
import type { LoginByCodeReq, LoginByCodeRes, LoginReq, LoginRes, ProfileReq, ProfileRes } from './types'; import type { LoginByCodeReq, LoginByCodeRes, LoginReq, LoginRes, ProfileRes } from './types';
import { get, post } from '@/utils/request'; import { get, post } from '@/utils/request';
/** 获取用户信息 */ /** 获取用户信息 */
export const profile = (params?: ProfileReq) => get<ProfileRes>('/user/profile', { params }); // export const profile = (params?: ProfileReq) => get<ProfileRes>('/user/profile', { params });
export const profile = (data: any) => get<ProfileRes>('/api/user', { data, custom: { toast: false } });
/** 登录 */ /** 登录 */
export const login = (data: LoginReq) => post<LoginRes>('/user/login', { data, custom: { auth: false } }); export const login = (data: LoginReq) => post<LoginRes>('/api/auth/login', { data, custom: { auth: false } });
// 账号登录
export const passwordLogin = (data: any) => post('/api/auth/login', { data, custom: { toast: false } });
/** 验证码登录 */ /** 验证码登录 */
export const loginByCode = (data: LoginByCodeReq) => post<LoginByCodeRes>('/user/loginByCode', { data }); export const loginByCode = (data: LoginByCodeReq) => post<LoginByCodeRes>('/user/loginByCode', { data });
/** 退出登录 */ /** 退出登录 */
export const logout = () => post<CommonRes>('/user/logout'); export const logout = () => post<CommonRes>('/api/logout');
export const goodsMenu = () => get<CommonRes>('/api/config'); export const goodsMenu = () => get<CommonRes>('/api/config');
// export const goodsMenu = (data:any) => get<CommonRes>('/api/config', { data, custom: { toast: false } }); // export const goodsMenu = (data:any) => get<CommonRes>('/api/config', { data, custom: { toast: false } });

View File

@ -7,12 +7,16 @@ export interface ProfileRes {
user_name?: string; user_name?: string;
avatar?: string; avatar?: string;
token?: string; token?: string;
user?: any;
} }
export interface LoginReq { export interface LoginReq {
phone: string; phone: string;
code: string; code: string;
} }
export interface LoginReqPassword {
account: string;
password: string;
}
export interface LoginRes { export interface LoginRes {
token: string; token: string;

View File

@ -1,12 +1,15 @@
<style> <style>
.ellipsis { .ellipsis {
white-space: nowrap;
/* 防止文字换行 */
overflow: hidden;
/* 隐藏超出部分的文字 */
text-overflow: ellipsis;
/* 在末尾显示省略号 */ /* 在末尾显示省略号 */
width: 420rpx; width: 420rpx;
/* 防止文字换行 */
overflow: hidden;
/* 隐藏超出部分的文字 */
text-overflow: ellipsis;
white-space: nowrap;
/* 确保元素有宽度 */ /* 确保元素有宽度 */
} }
</style> </style>
@ -15,9 +18,11 @@
<up-navbar class=" " :autoBack="true" style="font-weight: bold;" leftIcon="arrow-left" title="提交订单" <up-navbar class=" " :autoBack="true" style="font-weight: bold;" leftIcon="arrow-left" title="提交订单"
titleColor="#303133" bgColor="#FFFFFFFF" titleWidth="600rpx" height="80rpx" leftIconSize="40rpx" titleColor="#303133" bgColor="#FFFFFFFF" titleWidth="600rpx" height="80rpx" leftIconSize="40rpx"
leftIconColor="#303133" :safeAreaInsetTop="true" :placeholder="true" :fixed="true"></up-navbar> leftIconColor="#303133" :safeAreaInsetTop="true" :placeholder="true" :fixed="true"></up-navbar>
<view class="address_box"> <view class="address_box">
<view class=" pt-2 pb-2 ps-2 pe-2" style=""> <view class=" pt-2 pb-2 ps-2 pe-2" style="">
<text class="ellipsis" style="margin: 0rpx 0rpx 0rpx 40rpx;text-align:left;display: inline-block;width: calc(100% - 100rpx);" >江阳区学校2016工作室放假咯解fafsf方法 <span>18181941463</span> </text> <text class="ellipsis"
style="display: inline-block;width: calc(100% - 100rpx);margin: 0rpx 0rpx 0rpx 40rpx;text-align:left;">江阳区学校2016工作室放假咯解fafsf方法
<span>18181941463</span> </text>
</view> </view>
<view class="flex box-border flex-row pb-2 ps-2 pe-2" style="" @click="getopenLocation"> <view class="flex box-border flex-row pb-2 ps-2 pe-2" style="" @click="getopenLocation">
<up-text class="" size="26rpx" :text="'四川省泸州市江阳区龙马大道海吉星农贸市场32号附一号2楼307号'" :flex1="true" align="left" <up-text class="" size="26rpx" :text="'四川省泸州市江阳区龙马大道海吉星农贸市场32号附一号2楼307号'" :flex1="true" align="left"
@ -27,14 +32,14 @@
<u-icon slot="right" name="arrow-right"></u-icon> <u-icon slot="right" name="arrow-right"></u-icon>
</view> </view>
<view class="flex box-border flex-row pb-2 ps-2 pe-2" style=""> <view class="flex box-border flex-row pb-2 ps-2 pe-2" style="">
<up-text class="" size="26rpx" color="#59CB56" <up-text class="" size="26rpx" color="#59CB56" :text="'配送时间 7月17日(周三) 19:00-21:00 送达'" :flex1="true"
:text="'配送时间 7月17日(周三) 19:00-21:00 送达'" :flex1="true" align="left" prefixIcon="clock" wordWrap="normal" align="left" prefixIcon="clock" wordWrap="normal" :show="true"
:show="true" iconStyle="font-size:32rpx;color:#59CB56;margin-right:10rpx;" lines="1" decoration="none"> iconStyle="font-size:32rpx;color:#59CB56;margin-right:10rpx;" lines="1" decoration="none">
</up-text> </up-text>
<u-icon slot="right" name="arrow-right"></u-icon> <u-icon slot="right" name="arrow-right"></u-icon>
</view> </view>
</view> </view>
<z-paging ref="pagingRefSC" v-model="matchedItems_sc" @query="changeSC('')" style="bottom: 110rpx;top:300rpx" <z-paging ref="pagingRefSC" v-model="matchedItems_sc" @query="changeSC('')" style="top:300rpx;bottom: 110rpx"
class="fv-page flex-col px-2"> class="fv-page flex-col px-2">
<view v-for="(item, index) in matchedItems_sc" :key="index"> <view v-for="(item, index) in matchedItems_sc" :key="index">
<u-cell> <u-cell>
@ -47,9 +52,10 @@
<template #title> <template #title>
<view class="h-60 flex"> <view class="h-60 flex">
<text class=" ellipsis" style="font-size: 24rpx;font-weight: bold;">营养{{ item.name <text class=" ellipsis" style="font-size: 24rpx;font-weight: bold;">营养{{ item.name
}}</text> }}</text>
<up-text style="margin-right: 10rpx;" class="text-black" size="24rpx" :text="item.num + item.unit_name" :flex1="true" <up-text style="margin-right: 10rpx;" class="text-black" size="24rpx"
suffixIcon="" align="right" wordWrap="normal" :show="true" type="#59CB56" :text="item.num + item.unit_name" :flex1="true" suffixIcon="" align="right"
wordWrap="normal" :show="true" type="#59CB56"
iconStyle="font-size: 36rpx;font-weight: bold;" decoration="none"> iconStyle="font-size: 36rpx;font-weight: bold;" decoration="none">
</up-text> </up-text>
</view> </view>
@ -76,234 +82,130 @@
</template> </template>
<!-- 食谱清单 --> <script lang="ts">
<script setup lang="ts"> import { CommonApi } from '@/api';
// const { openLocation } = useLocation();
import { useLocation } from '@/hooks';
import { defineComponent } from 'vue';
import { useShare,useLocation } from '@/hooks'; const { openLocation } = useLocation();
const {openLocation } = useLocation();
//
function getopenLocation(){
openLocation(32.05, 32.05);
}
import {
ref,
reactive,
} from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { func } from "@/uni_modules/uview-plus/libs/function/test";
// export default defineComponent({
onLoad((options) => { data () {
// loadData(); return {
}); aloneChecked: false, //
checkboxValueNum: 0, //
checkboxValue: [],
propShow: false,
currentTab: 0, // tab
menu_list: [{ name: '食谱清单' }, { name: '食菜配置' }],
totalNum: 0,
keyword_sc: '',
goods_info: {},
menuIndex: 0,
matchedItems_sc: [],
goods_list_info:
{
total_num: 1,
info: [
{
id: 1,
name: '猪肉',
label: '青椒肉丝',
image: ' ',
disabled: true,
num: 88,
unit_name: 'g',
default_num: 88,
},
{
id: 2,
name: '毛豆',
label: '青椒肉丝',
image: 'https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png',
disabled: false,
num: 100,
unit_name: 'ml',
default_num: 100,
},
{
id: 3,
name: '食用油',
label: '青椒肉丝',
image: 'https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png',
disabled: false,
num: 100,
unit_name: 'g',
default_num: 100,
},
{
id: 4,
name: '豆瓣酱',
label: '青椒肉丝',
image: 'https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png',
disabled: false,
num: 100,
unit_name: 'ml',
default_num: 100,
},
],
},
};
},
created () {
//
this.goodList();
},
methods: {
goodList () {
CommonApi.goodsMenu({ key: 123 }).catch((res) => {
if (res.status === 200) {
// this.goods_list_info = res.data;
console.log(res);
}
else {
uni.$u.toast(res.message);
}
});
},
onShow(() => { }); changeSC () {
console.log('请求食谱数据');
try {
const goods_list = [ //
{ const regex = new RegExp(this.keyword_sc, 'i');
id: 1, // goods_list 使 filter matchedItems_sp.value
name: "大份芒果芒果", this.matchedItems_sc = this.goods_list_info.info.filter(item => regex.test(item.name));
label: "描述信息", // console.log(matchedItems_sp.value);
image: " ",
disabled: true,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 2,
name: "新鲜西瓜不甜不要钱,随便吃哦,华友很多方式JFK了就爱上基金大幅方法是飞机离开房间发士大夫十分恐惧撒发范德萨发生",
label: "描述信息,新鲜西瓜不甜不要钱,随便吃哦,华友很多方式JFK了就爱上基金大幅方法是飞机",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 3,
name: "大份芒果芒果",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 4,
name: "新鲜西瓜不甜不要钱,随便吃哦",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 5,
name: "大份芒果芒果",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 6,
name: "新鲜西瓜不甜不要钱,随便吃哦",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 7,
name: "大份芒果芒果",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 8,
name: "新鲜西瓜不甜不要钱,随便吃哦",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 9,
name: "大份芒果芒果",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
{
id: 10,
name: "新鲜西瓜不甜不要钱,随便吃哦",
label: "描述信息",
image: "https://s3.bmp.ovh/imgs/2024/12/16/35bc6d28ab1c8bc7.png",
disabled: false,
num: 100,
unit_name: "个",
default_num: 100,
},
];
// const menu_list =[{'name':'','icon':'photo'},{'name':'','icon':'photo'}]
const menu_list = [{ name: "食谱清单" }, { name: "食菜配置" }];
const listLoading = ref(false);
const dataPage = ref({
page: 0,
limit: 10,
total: 0,
});
//
const keyword_sp = ref("");
const keyword_sc = ref("");
//
const pagingRefSP = ref<InstanceType<typeof zPaging> | null>(null);
const pagingRefSC = ref<InstanceType<typeof zPaging> | null>(null);
function changeSC (e) {
// console.log(e);
try {
//
const regex = new RegExp(e, "i");
// goods_list 使 filter matchedItems_sp.value
matchedItems_sc.value = goods_list.filter((item) => regex.test(item.name));
} catch (error) {
console.error("匹配过程中发生错误:", error);
matchedItems_sc.value = []; // matchedItems
}
// console.log(matchedItems_sc.value);
pagingRefSC.value?.complete([]);
pagingRefSC.value?.complete(matchedItems_sc.value);
}
function changeSP (e) {
// console.log(e);
try {
//
const regex = new RegExp(e, "i");
// goods_list 使 filter matchedItems_sp.value
matchedItems_sp.value = goods_list.filter((item) => regex.test(item.name));
// console.log(matchedItems_sp.value);
} catch (error) {
console.error("匹配过程中发生错误:", error);
matchedItems_sp.value = []; // matchedItems
}
pagingRefSP.value?.complete([]);
pagingRefSP.value?.complete(matchedItems_sp.value);
}
// checkbox
const checkboxValueNum = ref(0);
const checkboxValue = reactive([]);
const matchedItems_sp = reactive(goods_list);
const matchedItems_sc = reactive(goods_list);
const aloneChecked = ref(false);
function checkboxChange (e) {
checkboxValue.length = 0;
e.forEach((item) => {
if (!checkboxValue.includes(item)) {
checkboxValue.push(item);
}
});
console.log(checkboxValue);
checkboxValueNum.value = checkboxValue.length;
}
function handleAllCheckChange (e) {
checkboxValue.length = 0;
if (e) {
// matchedItems_sp id checkboxValue
matchedItems_sp.forEach((item) => {
if (!checkboxValue.includes(item.id)) {
checkboxValue.push(item.id);
} }
}); catch (error) {
} console.error('匹配过程中发生错误:', error);
console.log(e); this.matchedItems_sc = []; // matchedItems
console.log(checkboxValue); }
checkboxValueNum.value = checkboxValue.length; this.$refs.pagingRefSC.complete();
} this.$refs.pagingRefSC.complete(this.matchedItems_sc);
// // },
// const loadData = (refresh = false) => {
// listLoading.value = true;
// //
// listLoading.value = false;
// };
const currentTab1 = ref(0);
// tab
function changeTab (e) {
console.log(e);
}
//
function handleClick (value) {
console.log(value);
uni.navigateTo({
url: `/pages/common/goods/detail?id=${value.name}`
});
}
//
function handleSubmit () {
// uni.navigateTo({
// url: `/pages/common/goods/order`
// });
console.log('提交订单');
}
//
handleClick (value) {
console.log(value);
uni.navigateTo({
url: `/pages/common/goods/detail?id=${value.name}`,
});
},
//
handleSubmit () {
uni.navigateTo({
url: `/pages/common/goods/order`,
});
},
//
getopenLocation () {
openLocation(32.05, 32.05);
}
},
</script> });
</script>

View File

@ -4,22 +4,32 @@
<view class="title"> <view class="title">
欢迎登录 欢迎登录
</view> </view>
<input v-model="tel" class="u-border-bottom" type="number" placeholder="请输入手机号"> <!-- <input v-model="account" class="u-border-bottom" type="number" placeholder="请输入手机号"> -->
<view class="u-border-bottom my-40rpx flex"> <u--input v-model="account" placeholder="请输入手机号" type="number" />
<input v-model="code" class="flex-1" type="number" placeholder="请输入验证码"> <view v-if="loginType" class="u-border-bottom my-40rpx flex">
<!-- <input v-model="code" class="flex-1" type="number" placeholder="请输入验证码"> -->
<u--input v-model="code" placeholder="请输入验证码" type="number" />
<view> <view>
<u-code ref="uCodeRef" @change="codeChange" /> <u-code ref="uCodeRef" @change="codeChange" />
<u-button :text="tips" type="success" size="mini" @click="getCode" /> <u-button :text="tips" type="success" size="mini" @click="getCode" />
</view> </view>
</view> </view>
<view v-if="!loginType" class="u-border-bottom my-40rpx flex">
<u--input v-model="password" placeholder="请输密码" type="password" />
<!-- <input v-model="password" class="flex-1" type="password" placeholder="请输密码"> -->
</view>
<button class="login-btn" :style="[inputStyle]" @tap="submit"> <button class="login-btn" :style="[inputStyle]" @tap="submit">
登录 <text class="i-mdi-login" /> 登录 <text class="i-mdi-login" />
</button> </button>
<view class="alternative"> <view class="alternative">
<view class="password"> <view v-if="loginType" class="password" @click="changLoginType(0)">
密码登录 密码登录
</view> </view>
<view v-if="!loginType" class="password" @click="changLoginType(1)">
验证码登录
</view>
<view class="issue flex items-center"> <view class="issue flex items-center">
遇到问题 <text class="i-mdi-help" /> 遇到问题 <text class="i-mdi-help" />
</view> </view>
@ -52,20 +62,24 @@
<script setup lang="ts"> <script setup lang="ts">
import type { CSSProperties } from 'vue'; import type { CSSProperties } from 'vue';
import { HOME_PATH, isTabBarPath, LOGIN_PATH, removeQueryString } from '@/router'; import { HOME_PATH, isTabBarPath, LOGIN_PATH, removeQueryString } from '@/router';
import { setToken } from '@/utils/auth'; import { useUserStore } from '@/store';
import { setToken ,getToken , isLogin } from '@/utils/auth';
import uCode from 'uview-plus/components/u-code/u-code.vue'; import uCode from 'uview-plus/components/u-code/u-code.vue';
// import { useUserStore } from '@/store';
// const userStore = useUserStore(); const userStore = useUserStore();
const tel = ref<string>('18502811111');
const loginType = ref(0);
const account = ref<string>('18181941463');
const code = ref<string>('1234'); const code = ref<string>('1234');
const password = ref<string>('123456');
const tips = ref<string>(); const tips = ref<string>();
const uCodeRef = ref<InstanceType<typeof uCode> | null>(null); const uCodeRef = ref<InstanceType<typeof uCode> | null>(null);
let redirect = HOME_PATH; let redirect = HOME_PATH;
const inputStyle = computed<CSSProperties>(() => { const inputStyle = computed<CSSProperties>(() => {
const style = {} as CSSProperties; const style = {} as CSSProperties;
if (tel.value && code.value) { if (account.value && code.value) {
style.color = '#fff'; style.color = '#fff';
style.backgroundColor = uni.$u.color.warning; style.backgroundColor = uni.$u.color.warning;
} }
@ -76,6 +90,10 @@ function codeChange(text: string) {
tips.value = text; tips.value = text;
} }
function changLoginType(text: number) {
loginType.value = text;
}
function getCode() { function getCode() {
if (uCodeRef.value?.canGetCode) { if (uCodeRef.value?.canGetCode) {
// //
@ -94,26 +112,56 @@ function getCode() {
} }
} }
async function submit() { async function submit() {
if (!uni.$u.test.mobile(Number(tel.value))) { if (!uni.$u.test.mobile(Number(account.value))) {
uni.$u.toast('请输入正确的手机号'); uni.$u.toast('请输入正确的手机号');
return; return;
} }
if (!code.value) { if (loginType.value === 0) {
uni.$u.toast('请输入验证码'); if (!password.value) {
return; uni.$u.toast('请输入密码');
} return;
// }
// const res = await userStore.login({ phone: tel.value, code: code.value }).catch(() => { await userStore.passwordLogin({ account: account.value, password: password.value }).catch((res) => {
// uni.$u.toast(''); console.log(res);
// }); if (res.status === 200) {
// if (!res) return; setToken(res.data.token);
setToken('1234567890'); uni.$u.toast('登录成功');
setTimeout(() => { }
uni.$u.route({ else {
type: isTabBarPath(redirect) ? 'switchTab' : 'redirectTo', uni.$u.toast(`登录失败,${res.message}`);
url: redirect, }
}); });
}, 800); }
else {
if (!code.value) {
uni.$u.toast('请输入验证码');
return;
}
await userStore.login({ account: account.value, code: password.value }).catch(() => {
if (res.status === 200) {
setToken(res.data.token);
uni.$u.toast('登录成功');
}
else {
uni.$u.toast(`登录失败,${res.message}`);
}
});
}
if(isLogin()){
await userStore.info()
setTimeout(() => {
uni.$u.route({
type: isTabBarPath(redirect) ? 'switchTab' : 'redirectTo',
url: redirect,
});
}, 800);
}else{
uni.$u.toast('登录失败,请重新登录 ');
setToken('');
}
// setToken('1234567890');
} }
onLoad((options: any) => { onLoad((options: any) => {
@ -123,6 +171,13 @@ onLoad((options: any) => {
}); });
</script> </script>
<style>
html,
body {
height: 0;
}
</style>
<style lang="scss" scoped> <style lang="scss" scoped>
.login-form-wrap { .login-form-wrap {
@apply mt-80rpx mx-auto mb-0 w-600rpx; @apply mt-80rpx mx-auto mb-0 w-600rpx;

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,15 @@
<style>
.detail_box {
border: 1rpx solid #dfdfdf;
border-radius: 20rpx;
margin: 20rpx;
background-color: #ffffff;
}
html, body {
height: 0px;
}
</style>
<template> <template>
<view class="page-wrap p-2"> <view class="page-wrap p-2">
<view class="flex detail_box p-4 bg-white"> <view class="detail-box flex bg-white p-4">
<view class="mr-10rpx"> <view class="mr-10rpx">
<u-avatar src="/static/images/logo.png" size="70" /> <u-avatar :src="userStore.user.avatar " size="70" />
</view> </view>
<view class="flex-1"> <view class="flex-1">
<view class="pb-20rpx font-size-36rpx"> <view class="pb-20rpx font-size-36rpx">
uni-app {{ userStore.user.nickname }}
</view> </view>
<view class="u-tips-color font-size-28rpx" @click="toCopy"> <view class="u-tips-color font-size-28rpx" @click="toCopy">
微信号:uni-app {{ userStore.user.phone }}
</view> </view>
</view> </view>
<view class="ml-10rpx p-10rpx"> <view class="ml-10rpx p-10rpx">
@ -31,49 +20,88 @@ html, body {
</view> </view>
</view> </view>
<view class="detail_box bg-white"> <view class="detail-box bg-white">
<u-cell icon="" title="昵称" is-link rightIcon="lock" value="小花猫" :border="false" size="large" <u-cell
customStyle="padding:20rpx;font-size:28rpx" /> icon="" title="昵称" is-link right-icon="lock" :value="userStore.user.nickname" :border="false" size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<u-cell icon="" title="ID" is-link rightIcon="lock" value="26" :border="false" size="large" <u-cell
customStyle="padding:20rpx;font-size:28rpx" /> icon="" title="ID" is-link right-icon="lock" :value="userStore.user.uid" :border="false" size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<u-cell icon="" title="手机号" is-link rightIcon="lock" value="18181941463" :border="false" size="large" <u-cell
customStyle="padding:20rpx;font-size:28rpx" /> icon="" title="手机号" is-link right-icon="lock" :value="userStore.user.phone" :border="false" size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
<u-cell icon="order" title="订单详情" is-link value="" :border="false" size="large" <u-cell
customStyle="padding:20rpx;font-size:28rpx" /> icon="order" title="订单详情" is-link value="" :border="false" size="large"
custom-style="padding:20rpx;font-size:28rpx"
/>
</view> </view>
<view class="p-2 bg-white"> <view class="bg-white p-2">
<u-button class="p-2" size="large" text="退出登录" type="primary" color="#59CB56" shape="circle" <u-button
custom-style="width:100%;" @click="loginOut"> class="p-2" size="large" text="退出登录" type="primary" color="#59CB56" shape="circle"
</u-button> custom-style="width:100%;" @click="loginOut"
/>
</view> </view>
</view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { HOME_PATH, isTabBarPath, LOGIN_PATH, removeQueryString } from '@/router'; import { useClipboard, useModal, usePermission } from '@/hooks';
import { useClipboard, usePermission } from '@/hooks';
import { HOME_PATH, isTabBarPath } from '@/router';
import { useUserStore } from '@/store';
import { setToken } from '@/utils/auth'; import { setToken } from '@/utils/auth';
// import { useUserStore } from '@/store';
// const userStore = useUserStore(); const { showModal } = useModal();
let redirect = HOME_PATH; const { setClipboardData, getClipboardData } = useClipboard();
async function loginOut() {
const userStore = useUserStore();
const redirect = HOME_PATH;
console.log('userStore', userStore);
console.log('userStore', userStore.user_name);
// import { CommonApi, UserApi } from "@/api";
// profile
//
const toCopy = async () => {
await setClipboardData({ data: '1234567890' });
const data = await getClipboardData();
console.log('[ data ] >', data);
};
function loginOut() {
showModal('success', {
title: '提示',
content: '确定退出登录?',
showCancel: true,
confirmText: '确定',
cancelText: '取消',
success: (res) => {
if (res.confirm) {
// 退
loginOuts();
}
},
});
}
// userStore.info()
async function loginOuts() {
// 退 // 退
// const res = await userStore.logout().catch(() => { await userStore.logout().catch(() => {
// uni.$u.toast('退'); setToken('');
// }); setTimeout(() => {
// if (!res) return; uni.$u.route({
setToken(''); type: isTabBarPath(redirect) ? 'switchTab' : 'redirectTo',
setTimeout(() => { url: redirect,
uni.$u.route({ });
type: isTabBarPath(redirect) ? 'switchTab' : 'redirectTo', }, 800);
url: redirect, });
});
}, 800);
} }
// tabbaruni.switchTabonShow // tabbaruni.switchTabonShow
onShow(async () => { onShow(async () => {
@ -81,3 +109,17 @@ onShow(async () => {
console.log(hasPermission ? '已登录' : '未登录,拦截跳转'); console.log(hasPermission ? '已登录' : '未登录,拦截跳转');
}); });
</script> </script>
<style scoped>
.detail-box {
margin: 20rpx;
background-color: #fff;
border: 1rpx solid #dfdfdf;
border-radius: 20rpx;
}
html,
body {
height: 0;
}
</style>

View File

@ -1,4 +1,4 @@
import type { LoginReq } from '@/api/user/types'; import type { LoginReq, LoginReqPassword } from '@/api/user/types';
import type { providerType, UserState } from './types'; import type { providerType, UserState } from './types';
import { UserApi } from '@/api'; import { UserApi } from '@/api';
import { clearToken, setToken } from '@/utils/auth'; import { clearToken, setToken } from '@/utils/auth';
@ -9,8 +9,9 @@ const useUserStore = defineStore('user', {
state: (): UserState => ({ state: (): UserState => ({
user_id: '0', user_id: '0',
user_name: '游客登录', user_name: '游客登录',
avatar: '', avatar: 'https://test.shop.lihaink.cn/static/f.png',
token: '', token: '',
user: {},
}), }),
getters: { getters: {
userInfo(state: UserState): UserState { userInfo(state: UserState): UserState {
@ -27,9 +28,12 @@ const useUserStore = defineStore('user', {
this.$reset(); this.$reset();
}, },
// 获取用户信息 // 获取用户信息
async info() { info() {
const result = await UserApi.profile(); UserApi.profile().catch((res) => {
this.setInfo(result); console.log('登录信息',res.data);
// reject(error);
this.setInfo({ user: res.data });
});
}, },
// 异步登录并存储token // 异步登录并存储token
login(loginForm: LoginReq) { login(loginForm: LoginReq) {
@ -45,6 +49,20 @@ const useUserStore = defineStore('user', {
}); });
}); });
}, },
passwordLogin(loginForm: LoginReqPassword) {
return new Promise((resolve, reject) => {
UserApi.passwordLogin(loginForm).then((res) => {
const token = res.token;
if (token) {
setToken(token);
}
resolve(res);
}).catch((error) => {
reject(error);
});
});
},
// Logout // Logout
async logout() { async logout() {
await UserApi.logout(); await UserApi.logout();

View File

@ -4,6 +4,7 @@ export interface UserState {
user_name?: string; user_name?: string;
avatar?: string; avatar?: string;
token?: string; token?: string;
user?: any;
} }
export type providerType = export type providerType =