This commit is contained in:
weipengfei 2024-05-06 11:51:21 +08:00
parent b80a7eb45e
commit dcd225028c
13 changed files with 194 additions and 67 deletions

View File

@ -10,6 +10,16 @@ export const userLoginWeixinApi = (data)=>{
return request.post('/login/mnpLogin', data);
}
// 微信获取手机号
export const getMobileByMnpApi = (data)=>{
return request.post('/user/User/getMobileByMnp', data);
}
// 更新信息
export const loginUpdateUserApi = (data)=>{
return request.post('/login/updateUser', data);
}
// 添加地址
export const addressCreateApi = (data)=>{
return request.post('/user/address/create', data);

53
components/bindPhone.vue Normal file
View File

@ -0,0 +1,53 @@
<template>
<up-popup :show="show" round="10" @close="close" mode="center" :safeAreaInsetBottom="false">
<view class="m-modal-popup">
<view class="head-title-modal">绑定手机号</view>
<view class="content-modal">系统检测到您未绑定手机号, 为方便您继续使用, 请绑定手机号码</view>
<view class="btn-box-modal">
<view style="width: 130rpx;"><up-button @click="close" plain color="#999">取消绑定</up-button></view>
<view style="width: 350rpx;"><up-button @getphonenumber="change" open-type="getPhoneNumber" color="#20B128">立即绑定</up-button></view>
</view>
</view>
</up-popup>
</template>
<script setup>
const props = defineProps({
show: {
type: Boolean,
default: false
}
})
const emit = defineEmits(['close', 'change']);
const close = () => {
emit('close');
}
const change = (e)=>{
emit('change', e);
}
</script>
<style scoped lang="scss">
.m-modal-popup{
width: 500rpx;
padding: 40rpx;
.head-title-modal{
font-size: 32rpx;
text-align: center;
}
.content-modal{
font-size: 26rpx;
color: #999;
text-align: center;
padding: 40rpx 0;
}
.btn-box-modal{
display: flex;
justify-content: space-between;
}
}
</style>

View File

@ -16,8 +16,6 @@
<view class="btn">
<up-button @click="weixinLogin" color="#20B128" size="large"><up-icon
name="weixin-fill" color="#fff" size="28"></up-icon></up-button>
<!-- <up-button ref="phoneRef" open-type="getPhoneNumber" @click="getPhoneNumber" color="#20B128" size="large"><up-icon
name="weixin-fill" color="#fff" size="28"></up-icon></up-button> -->
</view>
<view class="btn">
<up-button color="#ECFFEE" @click="showWeixin=false" size="large"><text style="color: #20B128;">使用短信验证登录</text></up-button>
@ -62,16 +60,33 @@
</view>
</view>
</view>
<bindPhone :show="showBind" @close="showBind = false" @change="getPhoneNumber"/>
</view>
</template>
<script setup>
import { onBackPress } from "@dcloudio/uni-app"
import { ref } from "vue"
import { userLoginApi, userLoginWeixinApi } from "@/api/user.js";
import { userLoginApi, userLoginWeixinApi, getMobileByMnpApi } from "@/api/user.js";
import useUserStore from "@/store/user.js"
import bindPhone from "@/components/bindPhone.vue"
const navToIndex = ()=>{
if(!userStore.userInfo.supplier) uni.reLaunch({
url: '/pages/index/index'
})
else uni.$u.toast('功能开发中')
}
const userStore = useUserStore(); //使pinia
if(userStore.userInfo&&userStore.userInfo.mobile){
navToIndex();
}else {
userStore.setToken('');
userStore.setUserInfo({});
}
const showWeixin = ref(true); //
const isAgree = ref(false); //
@ -81,24 +96,19 @@
uni.showLoading({
title: '登录中'
})
// return console.log(phoneRef.value) ;
uni.login({
provider: 'weixin',
success: (res) => {
return console.log(res);
userLoginWeixinApi({
code: res.code
}).then(res=>{
userStore.setUserInfo(res.data);
userStore.setToken(res.data.token);
if(!res.data.mobile) {
return console.log("=====");
}
uni.hideLoading();
if(!res.data.supplier) uni.reLaunch({
url: '/pages/index/index'
})
else uni.$u.toast('功能开发中')
userStore.setToken(res.data.token);
userStore.setUserInfo(res.data);
if(!res.data.mobile) { //
return showBind.value = true;
}
navToIndex();
})
},
fail: (err) => {
@ -108,12 +118,22 @@
})
}
const phoneRef = ref(null)
const showBind = ref(false); //
const getPhoneNumber = (e) => {
console.log(e);
console.log("===", e);
if(e.detail?.errMsg=='getPhoneNumber:ok') {
getMobileByMnpApi({
code: e.detail.code
}).then(res=>{
navToIndex();
})
}
else {
console.log("用户拒绝授权");
return uni.$u.toast('您拒绝了授权');
}
}
const loginForm = ref({
phone: '15366662222',
code: ''

View File

@ -3,7 +3,7 @@
<view class="item-title" @click="navTo">
<view>{{datas.number}}</view>
<view v-if="datas.paid==0">
<text>待付款</text>
<text>待付款{{datas.paid}}</text>
</view>
<view v-else>
<text v-if="datas.status==0">待发货</text>

View File

@ -68,8 +68,9 @@
orderListApi({
...where.value,
status: status,
paid: paid
// paid: paid
}).then(res=>{
console.log(res.data);
orderList.value[type] = res.data.lists;
})
}

View File

@ -13,6 +13,14 @@ const useUserStore = defineStore("user", () => {
uni.setStorageSync('userInfo', data)
}
const token = ref(uni.getStorageSync('token')||'');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
// #ifdef H5
token.value = "a8670fe7f1014c0f5125f6ca0c3b9cb3"
userInfo.value = {
"nickname": "哈哈",
"id": 1,
@ -20,13 +28,7 @@ const useUserStore = defineStore("user", () => {
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/tFJnfhVKlAlIecticsOhjAu8CHa6ibZacWrcHHkiahu7f0dQlWYgwu1b0TPLSLlO1xCTa6KN1krqg3XSIo3vq6uCQ/132",
"token": "a8670fe7f1014c0f5125f6ca0c3b9cb3"
}
const token = ref(uni.getStorageSync('token')||'');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
token.value = "a8670fe7f1014c0f5125f6ca0c3b9cb3"
// #endif
return { userInfo, setUserInfo, token, setToken }
})

View File

@ -21,12 +21,27 @@ const _easycom_up_transition = () => "../../uni_modules/uview-plus/components/u-
const _easycom_up_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_code = () => "../../uni_modules/uview-plus/components/u-code/u-code.js";
if (!Math) {
(_easycom_up_navbar + _easycom_up_icon + _easycom_up_button + _easycom_up_transition + _easycom_up_input + _easycom_up_code)();
(_easycom_up_navbar + _easycom_up_icon + _easycom_up_button + _easycom_up_transition + _easycom_up_input + _easycom_up_code + bindPhone)();
}
const bindPhone = () => "../../components/bindPhone.js";
const _sfc_main = {
__name: "login",
setup(__props) {
store_user.useUserStore();
const navToIndex = () => {
if (!userStore.userInfo.supplier)
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
else
common_vendor.index.$u.toast("功能开发中");
};
const userStore = store_user.useUserStore();
if (userStore.userInfo && userStore.userInfo.mobile) {
navToIndex();
} else {
userStore.setToken("");
userStore.setUserInfo({});
}
const showWeixin = common_vendor.ref(true);
const isAgree = common_vendor.ref(false);
const weixinLogin = () => {
@ -38,7 +53,17 @@ const _sfc_main = {
common_vendor.index.login({
provider: "weixin",
success: (res) => {
return console.log(res);
api_user.userLoginWeixinApi({
code: res.code
}).then((res2) => {
common_vendor.index.hideLoading();
userStore.setToken(res2.data.token);
userStore.setUserInfo(res2.data);
if (!res2.data.mobile) {
return showBind.value = true;
}
navToIndex();
});
},
fail: (err) => {
console.log(err);
@ -46,7 +71,21 @@ const _sfc_main = {
}
});
};
common_vendor.ref(null);
const showBind = common_vendor.ref(false);
const getPhoneNumber = (e) => {
var _a;
console.log("===", e);
if (((_a = e.detail) == null ? void 0 : _a.errMsg) == "getPhoneNumber:ok") {
api_user.getMobileByMnpApi({
code: e.detail.code
}).then((res) => {
navToIndex();
});
} else {
console.log("用户拒绝授权");
return common_vendor.index.$u.toast("您拒绝了授权");
}
};
const loginForm = common_vendor.ref({
phone: "15366662222",
code: ""
@ -179,6 +218,12 @@ const _sfc_main = {
} : {
z: common_vendor.o(($event) => isAgree.value = false),
A: common_assets._imports_0
}, {
B: common_vendor.o(($event) => showBind.value = false),
C: common_vendor.o(getPhoneNumber),
D: common_vendor.p({
show: showBind.value
})
});
};
}

View File

@ -8,6 +8,7 @@
"up-button": "../../uni_modules/uview-plus/components/u-button/u-button",
"up-transition": "../../uni_modules/uview-plus/components/u-transition/u-transition",
"up-input": "../../uni_modules/uview-plus/components/u-input/u-input",
"up-code": "../../uni_modules/uview-plus/components/u-code/u-code"
"up-code": "../../uni_modules/uview-plus/components/u-code/u-code",
"bind-phone": "../../components/bindPhone"
}
}

View File

@ -1 +1 @@
<view><up-navbar wx:if="{{b}}" bindleftClick="{{a}}" u-i="23c3038c-0" bind:__l="__l" u-p="{{b}}"></up-navbar><view class="login-box"><image class="logo" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/35adb202404271727457954.png"></image><view class="tips">欢迎登录惠农批发</view><block wx:if="{{c}}"><up-transition wx:if="{{i}}" u-s="{{['d']}}" u-i="23c3038c-1" bind:__l="__l" u-p="{{i}}"><view class="btn"><up-button wx:if="{{f}}" u-s="{{['d']}}" bindclick="{{e}}" u-i="23c3038c-2,23c3038c-1" bind:__l="__l" u-p="{{f}}"><up-icon wx:if="{{d}}" u-i="23c3038c-3,23c3038c-2" bind:__l="__l" u-p="{{d}}"></up-icon>微信快捷登录</up-button></view><view class="btn"><up-button wx:if="{{h}}" u-s="{{['d']}}" bindclick="{{g}}" u-i="23c3038c-4,23c3038c-1" bind:__l="__l" u-p="{{h}}"><text style="color:#20B128">使用短信验证登录</text></up-button></view></up-transition></block><block wx:else><up-transition wx:if="{{v}}" u-s="{{['d']}}" u-i="23c3038c-5" bind:__l="__l" u-p="{{v}}"><view class="form"><view class="input"><up-input wx:if="{{k}}" u-s="{{['prefix']}}" u-i="23c3038c-6,23c3038c-5" bind:__l="__l" bindupdateModelValue="{{j}}" u-p="{{k}}"><image style="height:40rpx;width:40rpx;margin-top:6rpx" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/48491202404281006484208.png" slot="prefix"></image></up-input></view><view class="input"><up-input wx:if="{{r}}" u-s="{{['prefix','suffix']}}" u-i="23c3038c-7,23c3038c-5" bind:__l="__l" bindupdateModelValue="{{q}}" u-p="{{r}}"><image style="height:40rpx;width:40rpx;margin-top:6rpx" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/3a42f202404281007454918.png" slot="prefix"></image><view slot="suffix"><up-code wx:if="{{n}}" class="r" u-r="uCodeRef" bindchange="{{m}}" u-i="23c3038c-8,23c3038c-7" bind:__l="__l" u-p="{{n}}"></up-code><view style="color:#20B128" bindtap="{{p}}">{{o}}</view></view></up-input></view></view><view class="btn"><up-button wx:if="{{t}}" u-s="{{['d']}}" bindclick="{{s}}" u-i="23c3038c-9,23c3038c-5" bind:__l="__l" u-p="{{t}}">登录</up-button></view></up-transition></block><view class="agreement"><image wx:if="{{w}}" bindtap="{{x}}" src="{{y}}"></image><image wx:else bindtap="{{z}}" src="{{A}}"></image><view> 我已同意<text>《用户协议》</text>与<text>《隐私政策》</text></view></view></view></view>
<view><up-navbar wx:if="{{b}}" bindleftClick="{{a}}" u-i="23c3038c-0" bind:__l="__l" u-p="{{b}}"></up-navbar><view class="login-box"><image class="logo" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/35adb202404271727457954.png"></image><view class="tips">欢迎登录惠农批发</view><block wx:if="{{c}}"><up-transition wx:if="{{i}}" u-s="{{['d']}}" u-i="23c3038c-1" bind:__l="__l" u-p="{{i}}"><view class="btn"><up-button wx:if="{{f}}" u-s="{{['d']}}" bindclick="{{e}}" u-i="23c3038c-2,23c3038c-1" bind:__l="__l" u-p="{{f}}"><up-icon wx:if="{{d}}" u-i="23c3038c-3,23c3038c-2" bind:__l="__l" u-p="{{d}}"></up-icon>微信快捷登录</up-button></view><view class="btn"><up-button wx:if="{{h}}" u-s="{{['d']}}" bindclick="{{g}}" u-i="23c3038c-4,23c3038c-1" bind:__l="__l" u-p="{{h}}"><text style="color:#20B128">使用短信验证登录</text></up-button></view></up-transition></block><block wx:else><up-transition wx:if="{{v}}" u-s="{{['d']}}" u-i="23c3038c-5" bind:__l="__l" u-p="{{v}}"><view class="form"><view class="input"><up-input wx:if="{{k}}" u-s="{{['prefix']}}" u-i="23c3038c-6,23c3038c-5" bind:__l="__l" bindupdateModelValue="{{j}}" u-p="{{k}}"><image style="height:40rpx;width:40rpx;margin-top:6rpx" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/48491202404281006484208.png" slot="prefix"></image></up-input></view><view class="input"><up-input wx:if="{{r}}" u-s="{{['prefix','suffix']}}" u-i="23c3038c-7,23c3038c-5" bind:__l="__l" bindupdateModelValue="{{q}}" u-p="{{r}}"><image style="height:40rpx;width:40rpx;margin-top:6rpx" src="https://lihai001.oss-cn-chengdu.aliyuncs.com/def/3a42f202404281007454918.png" slot="prefix"></image><view slot="suffix"><up-code wx:if="{{n}}" class="r" u-r="uCodeRef" bindchange="{{m}}" u-i="23c3038c-8,23c3038c-7" bind:__l="__l" u-p="{{n}}"></up-code><view style="color:#20B128" bindtap="{{p}}">{{o}}</view></view></up-input></view></view><view class="btn"><up-button wx:if="{{t}}" u-s="{{['d']}}" bindclick="{{s}}" u-i="23c3038c-9,23c3038c-5" bind:__l="__l" u-p="{{t}}">登录</up-button></view></up-transition></block><view class="agreement"><image wx:if="{{w}}" bindtap="{{x}}" src="{{y}}"></image><image wx:else bindtap="{{z}}" src="{{A}}"></image><view> 我已同意<text>《用户协议》</text>与<text>《隐私政策》</text></view></view></view><bind-phone wx:if="{{D}}" bindclose="{{B}}" bindchange="{{C}}" u-i="23c3038c-10" bind:__l="__l" u-p="{{D}}"/></view>

View File

@ -34,67 +34,69 @@ const _sfc_main = {
return common_vendor.e({
a: common_vendor.t(__props.datas.number),
b: __props.datas.paid == 0
}, __props.datas.paid == 0 ? {} : common_vendor.e({
c: __props.datas.status == 0
}, __props.datas.paid == 0 ? {
c: common_vendor.t(__props.datas.paid)
} : common_vendor.e({
d: __props.datas.status == 0
}, __props.datas.status == 0 ? {} : {}, {
d: __props.datas.status == 1
e: __props.datas.status == 1
}, __props.datas.status == 1 ? {} : {}, {
e: __props.datas.status == 2 || __props.datas.status == 3
f: __props.datas.status == 2 || __props.datas.status == 3
}, __props.datas.status == 2 || __props.datas.status == 3 ? {} : {}), {
f: common_vendor.o(navTo),
g: common_vendor.f(__props.datas.goods_list, (item, index, i0) => {
g: common_vendor.o(navTo),
h: common_vendor.f(__props.datas.goods_list, (item, index, i0) => {
return {
a: item.imgs,
b: index
};
}),
h: common_vendor.p({
i: common_vendor.p({
name: "arrow-right-double",
color: "#20B128"
}),
i: common_vendor.t(__props.datas.goods_count),
j: common_vendor.t(__props.datas.total),
k: common_vendor.o(navTo),
l: __props.datas.paid = 0
j: common_vendor.t(__props.datas.goods_count),
k: common_vendor.t(__props.datas.total),
l: common_vendor.o(navTo),
m: __props.datas.paid = 0
}, (__props.datas.paid = 0) ? {
m: common_vendor.p({
n: common_vendor.p({
size: "small",
plain: true,
color: "#989898",
shape: "circle"
}),
n: common_vendor.p({
o: common_vendor.p({
size: "small",
plain: true,
color: "#20B128",
shape: "circle"
})
} : common_vendor.e({
o: __props.datas.status == 1
p: __props.datas.status == 1
}, __props.datas.status == 1 ? {
p: common_vendor.p({
q: common_vendor.p({
size: "small",
plain: true,
color: "#20B128",
shape: "circle"
})
} : {}, {
q: __props.datas.status == 2 || __props.datas.status == 3
r: __props.datas.status == 2 || __props.datas.status == 3
}, __props.datas.status == 2 || __props.datas.status == 3 ? {
r: common_vendor.p({
size: "small",
plain: true,
color: "#20B128",
shape: "circle"
})
} : {}, {
s: common_vendor.p({
size: "small",
plain: true,
color: "#20B128",
shape: "circle"
})
} : {}, {
t: common_vendor.p({
size: "small",
plain: true,
color: "#20B128",
shape: "circle"
}),
t: common_vendor.o(navTo)
v: common_vendor.o(navTo)
}));
};
}

View File

@ -1 +1 @@
<view class="shop-item"><view class="item-title" bindtap="{{f}}"><view>{{a}}</view><view wx:if="{{b}}"><text>待付款</text></view><view wx:else><text wx:if="{{c}}">待发货</text><text wx:if="{{d}}">待收货</text><text wx:if="{{e}}">已完成</text></view></view><view class="item-body" bindtap="{{k}}"><view class="body-content"><view style="display:flex;flex:1;flex-shrink:0"><view wx:for="{{g}}" wx:for-item="item" wx:key="b"><image class="image" src="{{item.a}}"></image></view></view><view style="display:flex;flex-direction:column;align-items:center;justify-content:center;width:100rpx"><up-icon wx:if="{{h}}" u-i="e1c5d592-0" bind:__l="__l" u-p="{{h}}"></up-icon></view></view><view class="all">共 {{i}} 件商品, 总金额 <text>¥{{j}}</text></view></view><view wx:if="{{l}}" class="item-btn"><view style="width:80px"><up-button wx:if="{{m}}" u-s="{{['d']}}" u-i="e1c5d592-1" bind:__l="__l" u-p="{{m}}">取消订单</up-button></view><view style="width:80px"><up-button wx:if="{{n}}" u-s="{{['d']}}" u-i="e1c5d592-2" bind:__l="__l" u-p="{{n}}">立即支付</up-button></view></view><view wx:else class="item-btn"><view wx:if="{{o}}" style="width:80px"><up-button wx:if="{{p}}" u-s="{{['d']}}" u-i="e1c5d592-3" bind:__l="__l" u-p="{{p}}">确认收货</up-button></view><view wx:if="{{q}}" style="width:80px"><up-button wx:if="{{r}}" u-s="{{['d']}}" u-i="e1c5d592-4" bind:__l="__l" u-p="{{r}}">再次购买</up-button></view><view bindtap="{{t}}" style="width:80px"><up-button wx:if="{{s}}" u-s="{{['d']}}" u-i="e1c5d592-5" bind:__l="__l" u-p="{{s}}">查看详情</up-button></view></view></view>
<view class="shop-item"><view class="item-title" bindtap="{{g}}"><view>{{a}}</view><view wx:if="{{b}}"><text>待付款{{c}}</text></view><view wx:else><text wx:if="{{d}}">待发货</text><text wx:if="{{e}}">待收货</text><text wx:if="{{f}}">已完成</text></view></view><view class="item-body" bindtap="{{l}}"><view class="body-content"><view style="display:flex;flex:1;flex-shrink:0"><view wx:for="{{h}}" wx:for-item="item" wx:key="b"><image class="image" src="{{item.a}}"></image></view></view><view style="display:flex;flex-direction:column;align-items:center;justify-content:center;width:100rpx"><up-icon wx:if="{{i}}" u-i="e1c5d592-0" bind:__l="__l" u-p="{{i}}"></up-icon></view></view><view class="all">共 {{j}} 件商品, 总金额 <text>¥{{k}}</text></view></view><view wx:if="{{m}}" class="item-btn"><view style="width:80px"><up-button wx:if="{{n}}" u-s="{{['d']}}" u-i="e1c5d592-1" bind:__l="__l" u-p="{{n}}">取消订单</up-button></view><view style="width:80px"><up-button wx:if="{{o}}" u-s="{{['d']}}" u-i="e1c5d592-2" bind:__l="__l" u-p="{{o}}">立即支付</up-button></view></view><view wx:else class="item-btn"><view wx:if="{{p}}" style="width:80px"><up-button wx:if="{{q}}" u-s="{{['d']}}" u-i="e1c5d592-3" bind:__l="__l" u-p="{{q}}">确认收货</up-button></view><view wx:if="{{r}}" style="width:80px"><up-button wx:if="{{s}}" u-s="{{['d']}}" u-i="e1c5d592-4" bind:__l="__l" u-p="{{s}}">再次购买</up-button></view><view bindtap="{{v}}" style="width:80px"><up-button wx:if="{{t}}" u-s="{{['d']}}" u-i="e1c5d592-5" bind:__l="__l" u-p="{{t}}">查看详情</up-button></view></view></view>

View File

@ -52,9 +52,10 @@ const _sfc_main = {
const getOrderList = (type = 0, status = "", paid = 1) => {
api_order.orderListApi({
...where.value,
status,
paid
status
// paid: paid
}).then((res) => {
console.log(res.data);
orderList.value[type] = res.data.lists;
});
};

View File

@ -6,19 +6,11 @@ const useUserStore = common_vendor.defineStore("user", () => {
userInfo.value = data;
common_vendor.index.setStorageSync("userInfo", data);
};
userInfo.value = {
"nickname": "哈哈",
"id": 1,
"mobile": "17685151643",
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/tFJnfhVKlAlIecticsOhjAu8CHa6ibZacWrcHHkiahu7f0dQlWYgwu1b0TPLSLlO1xCTa6KN1krqg3XSIo3vq6uCQ/132",
"token": "a8670fe7f1014c0f5125f6ca0c3b9cb3"
};
const token = common_vendor.ref(common_vendor.index.getStorageSync("token") || "");
const setToken = (data) => {
token.value = data;
common_vendor.index.setStorageSync("token", data);
};
token.value = "a8670fe7f1014c0f5125f6ca0c3b9cb3";
return { userInfo, setUserInfo, token, setToken };
});
exports.useUserStore = useUserStore;