feat: 协议接口对接
This commit is contained in:
@@ -1,45 +1,49 @@
|
|||||||
import { wxLogin, bindUserPhone, checkUserPhone } from "../request/api/LoginApi";
|
import {
|
||||||
|
wxLogin,
|
||||||
|
bindUserPhone,
|
||||||
|
checkUserPhone,
|
||||||
|
} from "../request/api/LoginApi";
|
||||||
import { getWeChatAuthCode } from "./AuthManager";
|
import { getWeChatAuthCode } from "./AuthManager";
|
||||||
|
|
||||||
const loginAuth = async () => {
|
const loginAuth = async () => {
|
||||||
try {
|
try {
|
||||||
const openIdCode = await getWeChatAuthCode();
|
const openIdCode = await getWeChatAuthCode();
|
||||||
console.log('获取到的微信授权code:', openIdCode);
|
console.log("获取到的微信授权code:", openIdCode);
|
||||||
const response = await wxLogin({
|
const response = await wxLogin({
|
||||||
openIdCode: [openIdCode],
|
openIdCode: [openIdCode],
|
||||||
grant_type: 'wechat',
|
grant_type: "wechat",
|
||||||
scope: 'server',
|
scope: "server",
|
||||||
clientId: '2'
|
clientId: "2",
|
||||||
});
|
});
|
||||||
console.log('获取到的微信授权response:', response);
|
console.log("获取到的微信授权response:", response);
|
||||||
|
|
||||||
if (response.access_token) {
|
if (response.access_token) {
|
||||||
uni.setStorageSync('token', response.access_token)
|
uni.setStorageSync("token", response.access_token);
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.message || '登录失败');
|
throw new Error(response.message || "登录失败");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const bindPhone = async (params) => {
|
const bindPhone = async (params) => {
|
||||||
try {
|
try {
|
||||||
const response = await bindUserPhone(params)
|
const response = await bindUserPhone(params);
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const checkPhone = async (phone) => {
|
const checkPhone = async (phone) => {
|
||||||
try {
|
try {
|
||||||
const response = await checkUserPhone(phone)
|
const response = await checkUserPhone(phone);
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export { loginAuth, bindPhone, checkPhone }
|
export { loginAuth, bindPhone, checkPhone };
|
||||||
|
|||||||
@@ -152,12 +152,46 @@ const handleConfirmOrder = async (orderData) => {
|
|||||||
const res = await orderPay(params);
|
const res = await orderPay(params);
|
||||||
console.log("确认订单---2:", res);
|
console.log("确认订单---2:", res);
|
||||||
|
|
||||||
// 仅作为示例,非真实参数信息。
|
// 检查接口返回数据
|
||||||
|
if (!res || !res.data) {
|
||||||
|
uni.showToast({
|
||||||
|
title: "订单创建失败,请重试",
|
||||||
|
icon: "none",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = res;
|
||||||
|
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
|
||||||
|
|
||||||
|
// 验证支付参数是否完整
|
||||||
|
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||||
|
console.error("支付参数不完整:", {
|
||||||
|
nonceStr: !!nonceStr,
|
||||||
|
packageVal: !!packageVal,
|
||||||
|
paySign: !!paySign,
|
||||||
|
signType: !!signType,
|
||||||
|
timeStamp: !!timeStamp,
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付参数错误,请重试",
|
||||||
|
icon: "none",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用微信支付
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: "wxpay",
|
provider: "wxpay",
|
||||||
...res.data,
|
timeStamp: String(timeStamp), // 确保为字符串类型
|
||||||
|
nonceStr: String(nonceStr),
|
||||||
|
package: String(packageVal), // 确保为字符串类型
|
||||||
|
signType: String(signType),
|
||||||
|
paySign: String(paySign),
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log("success:" + JSON.stringify(res));
|
console.log("支付成功:" + JSON.stringify(res));
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "支付成功",
|
title: "支付成功",
|
||||||
icon: "success",
|
icon: "success",
|
||||||
@@ -165,7 +199,12 @@ const handleConfirmOrder = async (orderData) => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
console.log("fail:" + JSON.stringify(err));
|
console.error("支付失败:" + JSON.stringify(err));
|
||||||
|
uni.showToast({
|
||||||
|
title: "支付失败,请重试",
|
||||||
|
icon: "none",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,15 +12,7 @@
|
|||||||
<!-- 弹窗内容 -->
|
<!-- 弹窗内容 -->
|
||||||
<view class="popup-content">
|
<view class="popup-content">
|
||||||
<view class="content-text">
|
<view class="content-text">
|
||||||
<text class="main-text">
|
<zero-markdown-view :markdown="agreement" />
|
||||||
您在使用朵花温泉服务前,请仔细阅读用户隐私条款及用户注册须知,当您点击同意,即表示您已经理解并同意该条款,该条款将构成对您具有法律约束力的文件。
|
|
||||||
</text>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<view class="notice-text">
|
|
||||||
<text>
|
|
||||||
请您注意:如果您不同意上述用户注册须知、隐私政策或其中任何约定,请您停止注册。如您阅读并点击同意即表示您已充分阅读理解并接受其全部内容,并表明您也同意朵花温泉可以依据以上隐私政策来处理您的个人信息。
|
|
||||||
</text>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -45,6 +37,10 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: "温馨提示",
|
default: "温馨提示",
|
||||||
},
|
},
|
||||||
|
agreement: {
|
||||||
|
type: String,
|
||||||
|
default: "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Events定义
|
// Events定义
|
||||||
|
|||||||
@@ -39,32 +39,20 @@
|
|||||||
|
|
||||||
// 弹窗内容
|
// 弹窗内容
|
||||||
.popup-content {
|
.popup-content {
|
||||||
padding: 20px;
|
padding: 12px;
|
||||||
|
max-height: 400px; // 设置最大高度
|
||||||
|
overflow-y: auto; // 启用垂直滚动
|
||||||
|
|
||||||
.content-text {
|
// 自定义滚动条样式
|
||||||
margin-bottom: 16px;
|
&::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
.main-text {
|
|
||||||
font-size: 14px;
|
|
||||||
color: #333;
|
|
||||||
line-height: 22px;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.notice-text {
|
|
||||||
text {
|
|
||||||
font-size: 13px;
|
|
||||||
color: #333;
|
|
||||||
line-height: 20px;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按钮区域
|
// 按钮区域
|
||||||
.button-area {
|
.button-area {
|
||||||
padding: 0 20px 20px 20px;
|
padding: 20px;
|
||||||
|
box-sizing: border-box;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -55,20 +55,33 @@
|
|||||||
</CheckBox>
|
</CheckBox>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<AgreePopup ref="agreePopup" :visible="visible" @close="visible = false" />
|
<AgreePopup
|
||||||
|
ref="agreePopup"
|
||||||
|
:visible="visible"
|
||||||
|
:agreement="computedAgreement"
|
||||||
|
@close="visible = false"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { ref, computed } from "vue";
|
||||||
import CheckBox from "@/components/CheckBox/index.vue";
|
|
||||||
import AgreePopup from "./components/AgreePopup/index.vue";
|
|
||||||
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
|
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
|
||||||
|
import {
|
||||||
|
getServiceAgreement,
|
||||||
|
getPrivacyAgreement,
|
||||||
|
} from "@/request/api/LoginApi";
|
||||||
import { goHome } from "@/hooks/useGoHome";
|
import { goHome } from "@/hooks/useGoHome";
|
||||||
import loginBg from "./images/bg.png";
|
import loginBg from "./images/bg.png";
|
||||||
|
import CheckBox from "@/components/CheckBox/index.vue";
|
||||||
|
import AgreePopup from "./components/AgreePopup/index.vue";
|
||||||
|
|
||||||
const isAgree = ref(false);
|
const isAgree = ref(false);
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
|
const serviceAgreement = ref("");
|
||||||
|
const privacyAgreement = ref("");
|
||||||
|
// 协议类型
|
||||||
|
const AgreeType = ref("service");
|
||||||
|
|
||||||
// 同意隐私协议并获取手机号
|
// 同意隐私协议并获取手机号
|
||||||
const handleAgreeAndGetPhone = () => {
|
const handleAgreeAndGetPhone = () => {
|
||||||
@@ -111,7 +124,33 @@ const onLogin = (e) => {
|
|||||||
// 处理同意协议点击事件
|
// 处理同意协议点击事件
|
||||||
const handleAgreeClick = (type) => {
|
const handleAgreeClick = (type) => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
|
AgreeType.value = type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 计算协议类型
|
||||||
|
const computedAgreement = computed(() => {
|
||||||
|
if (AgreeType.value === "service") {
|
||||||
|
return serviceAgreement.value;
|
||||||
|
} else {
|
||||||
|
return privacyAgreement.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取服务协议数据
|
||||||
|
const getServiceAgreementData = async () => {
|
||||||
|
const { data } = await getServiceAgreement();
|
||||||
|
serviceAgreement.value = data;
|
||||||
|
};
|
||||||
|
|
||||||
|
getServiceAgreementData();
|
||||||
|
|
||||||
|
// 获取隐私协议数据
|
||||||
|
const getPrivacyAgreementData = async () => {
|
||||||
|
const { data } = await getPrivacyAgreement();
|
||||||
|
privacyAgreement.value = data;
|
||||||
|
};
|
||||||
|
|
||||||
|
getPrivacyAgreementData();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -1,26 +1,42 @@
|
|||||||
import request from "../base/request";
|
import request from "../base/request";
|
||||||
|
|
||||||
const wxLogin = (args) => {
|
const wxLogin = (args) => {
|
||||||
const config = {
|
const config = {
|
||||||
header: {
|
header: {
|
||||||
'Authorization': 'Basic Y3VzdG9tOmN1c3RvbQ==', // 可在此动态设置 token
|
Authorization: "Basic Y3VzdG9tOmN1c3RvbQ==", // 可在此动态设置 token
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
uni.setStorageSync('token', '')
|
uni.setStorageSync("token", "");
|
||||||
|
|
||||||
return request.post('/auth/oauth2/token', args, config);
|
return request.post("/auth/oauth2/token", args, config);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 绑定用户手机号
|
// 绑定用户手机号
|
||||||
const bindUserPhone = (args) => {
|
const bindUserPhone = (args) => {
|
||||||
return request.post('/hotelBiz/user/bindUserPhone', args);
|
return request.post("/hotelBiz/user/bindUserPhone", args);
|
||||||
}
|
};
|
||||||
|
|
||||||
// 检测用户是否绑定手机号
|
// 检测用户是否绑定手机号
|
||||||
const checkUserPhone = (args) => {
|
const checkUserPhone = (args) => {
|
||||||
return request.get('/hotelBiz/user/checkUserHasBindPhone', args);
|
return request.get("/hotelBiz/user/checkUserHasBindPhone", args);
|
||||||
}
|
};
|
||||||
|
|
||||||
export { wxLogin, bindUserPhone, checkUserPhone }
|
// 获取服务协议
|
||||||
|
const getServiceAgreement = (args) => {
|
||||||
|
return request.get("/hotelBiz/mainScene/serviceAgreement", args);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取隐私协议
|
||||||
|
const getPrivacyAgreement = (args) => {
|
||||||
|
return request.get("/hotelBiz/mainScene/privacyPolicy", args);
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
wxLogin,
|
||||||
|
bindUserPhone,
|
||||||
|
checkUserPhone,
|
||||||
|
getServiceAgreement,
|
||||||
|
getPrivacyAgreement,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user