Lufaneng 11 months ago
parent 2cdd13090a
commit f43fc7b4ca

@ -107,7 +107,6 @@
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { onShow } from "@dcloudio/uni-app"; import { onShow } from "@dcloudio/uni-app";
import { useAuthStore, useUserStore } from "@/store"; import { useAuthStore, useUserStore } from "@/store";
import { regions } from "/static/json/regions.js";
import HeaderCustom from "/components/HeaderCustom/HeaderCustom.vue"; import HeaderCustom from "/components/HeaderCustom/HeaderCustom.vue";
import RPC from "@/utils/request"; import RPC from "@/utils/request";

@ -85,6 +85,9 @@
</view> </view>
</view> </view>
</uv-popup> </uv-popup>
<a style="display: none;" ref="ToLoginRef" href="weixin://dl/business/?appid=wxc504638e03981812&path=pages/login/login?from=h5ToWechat">
打开小程序并登录
</a>
</view> </view>
</template> </template>
@ -133,9 +136,9 @@
trigger: ["blur", "change"], trigger: ["blur", "change"],
}, },
{ {
pattern: /^1[3-9]\d{9}$/, pattern: /^1[3-9]\d{9}$/,
message: "请输入正确的手机号", message: "请输入正确的手机号",
trigger: ["blur", "change"], trigger: ["blur", "change"],
}, },
], ],
code: { code: {
@ -145,6 +148,8 @@
}, },
}); });
const ToLoginRef = ref(null)
const tips = ref("获取验证码"); const tips = ref("获取验证码");
const codeChange = (text) => { const codeChange = (text) => {
tips.value = text; tips.value = text;
@ -209,6 +214,9 @@
if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) { if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
redirect = decodeURIComponent(options.redirect); redirect = decodeURIComponent(options.redirect);
} }
if(options.from && options.from === 'h5ToWechat') {
XcxLogin()
}
}); });
// //
@ -231,47 +239,60 @@
// #endif // #endif
}; };
const XcxLogin = () => {
uni.showLoading({
title: "登录中...",
});
uni.login({
success: function(loginRes) {
console.log('loginRes', loginRes);
RPC.post('/login/wechat_mini', {
js_code: loginRes.code
}).then(res => {
console.log('phonelogin', res)
authStore.setAccessToken(res.token)
userStore.setUserInfo(res.user)
if(!res.user.phone) {
uni.showToast({
title: "登录成功",
icon: "success",
});
uni.$uv.route({
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
url: redirect,
});
} else {
popup.value.open()
}
}).catch(() => {
uni.showToast({
title: "登录失败",
icon: "error",
});
})
},
fail: () => {
uni.hideLoading();
}
})
}
// //
const wechatLogin = () => { const wechatLogin = () => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// //
// uni.login({ XcxLogin()
// provider: "weixin", // popup.value.open();
// success: (loginRes) => {
// console.log(":", loginRes);
// //
// uni.getUserProfile({
// desc: "",
// success: (userRes) => {
// console.log(":", userRes);
// //
// showBindPhoneModal.value = true;
// },
// fail: (err) => {
// console.error(":", err);
// uni.showToast({
// title: "",
// icon: "none",
// });
// },
// });
// },
// fail: (err) => {
// console.error(":", err);
// uni.showToast({
// title: "",
// icon: "none",
// });
// },
// });
popup.value.open();
// #endif // #endif
// #ifdef H5 // #ifdef H5
// H5 // H5
if (typeof WeixinJSBridge !== "undefined") { if (typeof WeixinJSBridge !== "undefined") {
// 使JS-SDK // 使JS-SDK
wechatH5Login(); // wechatH5Login();
ToLoginRef.value.click()
} else { } else {
uni.showToast({ uni.showToast({
title: "请在微信中打开", title: "请在微信中打开",
@ -349,7 +370,7 @@
const wechatH5Login = () => { const wechatH5Login = () => {
// #ifdef H5 // #ifdef H5
// URL // URL
const appId = "YOUR_WECHAT_APP_ID"; // AppID const appId = "wxc504638e03981812"; // AppID
const redirectUri = encodeURIComponent( const redirectUri = encodeURIComponent(
window.location.origin + "/pages/login/login" window.location.origin + "/pages/login/login"
); // ); //
@ -390,32 +411,56 @@
// const result = await RPC.post('/api/wechat/h5-login', { // const result = await RPC.post('/api/wechat/h5-login', {
// code: code // code: code
// }); // });
RPC.post('/login/wechat_mini', {
js_code: loginRes.code
}).then(res => {
console.log('phonelogin', res)
authStore.setAccessToken(res.token)
userStore.setUserInfo(res.user)
if(!res.user.phone) {
uni.showToast({
title: "登录成功",
icon: "success",
});
uni.$uv.route({
type: isTabBarPath(redirect) ? "switchTab" : "redirectTo",
url: redirect,
});
} else {
popup.value.open()
}
}).catch(() => {
uni.showToast({
title: "登录失败",
icon: "error",
});
})
// //
setTimeout(() => { // setTimeout(() => {
uni.hideLoading(); // uni.hideLoading();
// // //
const userInfo = { // const userInfo = {
openid: "mock_openid_" + Date.now(), // openid: "mock_openid_" + Date.now(),
nickname: "微信用户", // nickname: "",
headimgurl: "/static/imgs/avatar.png", // headimgurl: "/static/imgs/avatar.png",
}; // };
console.log("微信H5登录成功用户信息:", userInfo); // console.log("H5:", userInfo);
// // //
popup.value.open(); // popup.value.open();
// URLcode // // URLcode
const url = new URL(window.location); // const url = new URL(window.location);
url.searchParams.delete("code"); // url.searchParams.delete("code");
url.searchParams.delete("state"); // url.searchParams.delete("state");
window.history.replaceState({}, // window.history.replaceState({},
document.title, // document.title,
url.pathname + url.search // url.pathname + url.search
); // );
}, 1500); // }, 1500);
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
console.error("微信H5登录失败:", error); console.error("微信H5登录失败:", error);
@ -559,11 +604,13 @@
onMounted(() => { onMounted(() => {
checkEnvironment(); checkEnvironment();
// #ifdef H5 // #ifdef MP-WEIXIN
// //
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code"); const code = urlParams.get("code");
if (code && showWechatLogin.value) { const from = urlParams.get("from");
console.log('from',from)
if (from && from === 'h5') {
handleWechatH5Callback(code); handleWechatH5Callback(code);
} }

@ -138,9 +138,6 @@
useAuthStore, useAuthStore,
useUserStore useUserStore
} from "@/store"; } from "@/store";
import {
regions
} from '/static/json/regions.js'
import HeaderCustom from '/components/HeaderCustom/HeaderCustom.vue' import HeaderCustom from '/components/HeaderCustom/HeaderCustom.vue'
import RPC from "@/utils/request"; import RPC from "@/utils/request";

@ -19,30 +19,30 @@
<view class="profile-item" @click="editUsername"> <view class="profile-item" @click="editUsername">
<view class="item-label">用户名</view> <view class="item-label">用户名</view>
<view class="item-content"> <view class="item-content">
<text class="item-value">{{ userInfo.username }}</text> <text class="item-value">{{ userStore.userInfo.username }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
<!-- 电话 -->
<!-- <view class="profile-item" @click="editPhone">
<view class="item-label">电话</view>
<view class="item-content">
<text class="item-value">{{ userInfo.phone }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view>
</view> -->
<!-- 邮箱 --> <!-- 邮箱 -->
<view class="profile-item" @click="editEmail"> <view class="profile-item" @click="editEmail">
<view class="item-label">邮箱</view> <view class="item-label">邮箱</view>
<view class="item-content"> <view class="item-content">
<text class="item-value">{{ userInfo.email }}</text> <text class="item-value">{{ userStore.userInfo.email }}</text>
<uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon> <uv-icon name="arrow-right" size="16" color="#ccc"></uv-icon>
</view> </view>
</view> </view>
<!-- 电话 -->
<view class="profile-item">
<view class="item-label">手机号</view>
<view class="item-content">
<text class="item-value">{{ userStore.userInfo.phone }}</text>
</view>
</view>
</view> </view>
<!-- 应用设置 --> <!-- 应用设置 -->
<view class="app-section"> <view class="app-section">
<!-- 缓存 --> <!-- 缓存 -->
@ -152,6 +152,7 @@
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { onShow } from "@dcloudio/uni-app"; import { onShow } from "@dcloudio/uni-app";
import { useAuthStore, useUserStore } from "@/store"; import { useAuthStore, useUserStore } from "@/store";
import RPC from "@/utils/request";
const authStore = useAuthStore(); const authStore = useAuthStore();
const userStore = useUserStore(); const userStore = useUserStore();
@ -219,21 +220,21 @@ const selectAvatarSource = (source) => {
// //
const editUsername = () => { const editUsername = () => {
editType.value = "username"; editType.value = "username";
editValue.value = userInfo.value.username; editValue.value = userStore.userInfo.username;
editPopup.value.open(); editPopup.value.open();
}; };
// //
const editPhone = () => { const editPhone = () => {
editType.value = "phone"; editType.value = "phone";
editValue.value = userInfo.value.phone; editValue.value = userStore.userInfo.phone;
editPopup.value.open(); editPopup.value.open();
}; };
// //
const editEmail = () => { const editEmail = () => {
editType.value = "email"; editType.value = "email";
editValue.value = userInfo.value.email; editValue.value = userStore.userInfo.email;
editPopup.value.open(); editPopup.value.open();
}; };
@ -267,49 +268,49 @@ const saveEdit = async () => {
}); });
return; return;
} }
if(editType.value === 'username') {
// RPC.post('/user/update',{id:userStore.userInfo.id,username:editValue.value}).then(() => {
if (editType.value === "phone" && !/^1[3-9]\d{9}$/.test(editValue.value)) { uni.showToast({
uni.showToast({ title: "保存成功",
title: "请输入正确的手机号", icon: "success",
icon: "none", });
}); userStore.setUserInfo({...userStore.userInfo,username:editValue.value})
return; closeEditModal()
})
} }
if(editType.value === 'email') {
if ( RPC.post('/user/update',{id:userStore.userInfo.id,email:editValue.value}).then(() => {
editType.value === "email" && uni.showToast({
!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(editValue.value) title: "保存成功",
) { icon: "success",
uni.showToast({ });
title: "请输入正确的邮箱地址", userStore.setUserInfo({...userStore.userInfo,email:editValue.value})
icon: "none", closeEditModal()
}); })
return;
} }
try { // try {
// API // // API
// await RPC.post('/api/user/update', { // // await RPC.post('/api/user/update', {
// [editType.value]: editValue.value // // [editType.value]: editValue.value
// }) // // })
// // //
userInfo.value[editType.value] = editValue.value; // userInfo.value[editType.value] = editValue.value;
uni.showToast({ // uni.showToast({
title: "保存成功", // title: "",
icon: "success", // icon: "success",
}); // });
closeEditModal(); // closeEditModal();
} catch (error) { // } catch (error) {
console.error("保存失败:", error); // console.error(":", error);
uni.showToast({ // uni.showToast({
title: "保存失败,请重试", // title: "",
icon: "none", // icon: "none",
}); // });
} // }
}; };
// //

@ -125,16 +125,16 @@ const downloadRecord = (record) => {
icon: "success", icon: "success",
}); });
// #endif // #endif
// #ifdef MP-WEIXIN
// #ifndef H5
// App使uni.downloadFile // App使uni.downloadFile
uni.downloadFile({ uni.downloadFile({
url: record.result_url, url: 'https://ksdt-1255846884.cos.ap-shanghai.myqcloud.com/lift-result/2025/09/24/d6180add4cd94875a1854a4febce8966.pdf',
success: (res) => { success: (res) => {
console.log(res); console.log(res);
if (res.statusCode === 200) { if (res.statusCode === 200) {
uni.saveFile({ uni.openDocument({
tempFilePath: res.tempFilePath, filePath: res.tempFilePath,
showMenu: true,
success: () => { success: () => {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({

@ -25,7 +25,7 @@
@click="selectAmount(item.value)" @click="selectAmount(item.value)"
> >
<view class="amount-value">¥{{ item.value }}</view> <view class="amount-value">¥{{ item.value }}</view>
<view v-if="item.bonus" class="amount-bonus">{{ item.bonus }}</view> <!-- <view v-if="item.bonus" class="amount-bonus">{{ item.bonus }}</view> -->
</view> </view>
</view> </view>
@ -116,7 +116,7 @@
<view class="bottom-section"> <view class="bottom-section">
<view class="recharge-info"> <view class="recharge-info">
<text class="recharge-text">充值金额¥{{ finalAmount }}</text> <text class="recharge-text">充值金额¥{{ finalAmount }}</text>
<text v-if="bonusAmount > 0" class="bonus-text">¥{{ bonusAmount }}</text> <!-- <text v-if="bonusAmount > 0" class="bonus-text">¥{{ bonusAmount }}</text> -->
</view> </view>
<uv-button <uv-button
type="primary" type="primary"
@ -152,10 +152,10 @@ const showAlipay = ref(true);
const rechargeAmounts = ref([ const rechargeAmounts = ref([
{ value: 10, bonus: 0 }, { value: 10, bonus: 0 },
{ value: 50, bonus: 0 }, { value: 50, bonus: 0 },
{ value: 100, bonus: 5 }, { value: 100, bonus: 0 },
{ value: 200, bonus: 15 }, { value: 200, bonus: 0 },
{ value: 500, bonus: 50 }, { value: 500, bonus: 0 },
{ value: 1000, bonus: 120 } { value: 1000, bonus: 0 }
]); ]);
// //

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save