Compare commits
19 Commits
b2ad6403c1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 09452bf600 | |||
| c20563ecf5 | |||
| 172bae663b | |||
| 9632f5c065 | |||
| 3f803b662a | |||
| 84b77b3fe6 | |||
| 92f981769f | |||
| f69225dbff | |||
| f422dbaa00 | |||
| 14fee13568 | |||
| ed62f3fbbc | |||
|
|
8f79f5aecf | ||
|
|
c2c4f323dc | ||
|
|
de412aed9c | ||
|
|
de272b1160 | ||
|
|
47d1c5ab6f | ||
|
|
1028e20d42 | ||
|
|
48932e3851 | ||
|
|
9749e20971 |
@@ -1,7 +1 @@
|
||||
NODE_ENV = development
|
||||
|
||||
# 测试
|
||||
VITE_BASE_URL = https://onefeel.brother7.cn/ingress
|
||||
|
||||
# 测试
|
||||
VITE_WSS_URL = wss://onefeel.brother7.cn/ingress/agent/ws/chat
|
||||
|
||||
@@ -1,7 +1 @@
|
||||
NODE_ENV = production
|
||||
|
||||
# 生产
|
||||
VITE_BASE_URL = https://biz.nianxx.cn
|
||||
|
||||
# 生产
|
||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
||||
@@ -1,7 +1 @@
|
||||
NODE_ENV = staging
|
||||
|
||||
# 生产
|
||||
VITE_BASE_URL = https://biz.nianxx.cn
|
||||
|
||||
# 生产
|
||||
VITE_WSS_URL = wss://biz.nianxx.cn/agent/ws/chat
|
||||
NODE_ENV = staging
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"zhinian": {
|
||||
"clientId": "2",
|
||||
"clientId": "6",
|
||||
"appId": "wx5e79df5996572539",
|
||||
"name": "智念",
|
||||
"placeholder": "快告诉智念您在想什么~",
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<script setup>
|
||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
||||
import { getEvnUrl } from "@/request/api/config";
|
||||
import { refreshToken } from "@/hooks/useGoLogin";
|
||||
|
||||
onLaunch(async () => {
|
||||
console.log("App Launch");
|
||||
onLaunch(() => {
|
||||
getEvnUrl({ versionValue: "1.0.1" });
|
||||
refreshToken();
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view v-if="!isCallSuccess" class="order-content border-box p-12">
|
||||
<view v-if="!isCallSuccess" class="border-box p-12">
|
||||
<view
|
||||
class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12"
|
||||
>
|
||||
@@ -27,7 +27,11 @@
|
||||
class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12"
|
||||
>
|
||||
<text class="font-500 line-height-22 mr-20">联系电话</text>
|
||||
<input placeholder="请填写联系电话" v-model="contactPhone" />
|
||||
<input
|
||||
placeholder="请填写联系电话"
|
||||
v-model="contactPhone"
|
||||
@input="handleContactPhoneInput"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view
|
||||
@@ -115,19 +119,56 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick } from "vue";
|
||||
import { ref, computed, onMounted, nextTick, defineProps, watch } from "vue";
|
||||
import { SCROLL_TO_BOTTOM } from "@/constant/constant";
|
||||
import { createWorkOrder } from "@/request/api/WorkOrderApi";
|
||||
import { updateImageFile } from "@/request/api/UpdateFile";
|
||||
import { zniconsMap } from "@/static/fonts/znicons.js";
|
||||
|
||||
const props = defineProps({
|
||||
toolCall: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
});
|
||||
const workOrderTypeId = ref("");
|
||||
const roomId = ref("");
|
||||
const contactPhone = ref("");
|
||||
const contactText = ref("");
|
||||
const contentImgUrl = ref("");
|
||||
const isCallSuccess = ref(false); // 呼叫成功状态
|
||||
const workOrderId = ref(0); // 工单ID
|
||||
const toolResult = computed(() => {
|
||||
if (props.toolCall?.toolResult) {
|
||||
return JSON.parse(props.toolCall?.toolResult);
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
// 原始手机号(未脱敏)
|
||||
const originalPhone = ref("");
|
||||
// 展示与输入绑定的手机号(初始为脱敏)
|
||||
const contactPhone = ref("");
|
||||
// 是否用户已编辑过手机号(一旦编辑则不再脱敏)
|
||||
const hasEditedPhone = ref(false);
|
||||
// 需求信息描述:使用可写的 ref,并从工具结果初始化
|
||||
const contactText = ref("");
|
||||
|
||||
// 手机号脱敏:138****1234(仅对11位数字进行处理)
|
||||
const maskPhone = (phone) => {
|
||||
if (!phone) return "";
|
||||
return String(phone).replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
|
||||
};
|
||||
|
||||
// 监听工具返回结果,初始化原始与脱敏显示
|
||||
watch(
|
||||
toolResult,
|
||||
(val) => {
|
||||
originalPhone.value = val?.userPhone || "";
|
||||
hasEditedPhone.value = false;
|
||||
contactPhone.value = maskPhone(originalPhone.value);
|
||||
contactText.value = val?.callServiceContent || "";
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// 处理图片上传
|
||||
const handleChooseImage = () => {
|
||||
@@ -143,6 +184,11 @@ const handleChooseImage = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 标记用户已编辑手机号
|
||||
const handleContactPhoneInput = () => {
|
||||
hasEditedPhone.value = true;
|
||||
};
|
||||
|
||||
const handleDeleteImage = () => {
|
||||
contentImgUrl.value = "";
|
||||
};
|
||||
@@ -168,7 +214,10 @@ const handleCall = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!contactPhone.value.trim()) {
|
||||
const phoneToSubmit = hasEditedPhone.value
|
||||
? contactPhone.value
|
||||
: originalPhone.value;
|
||||
if (!phoneToSubmit.trim()) {
|
||||
uni.showToast({ title: "请填写联系电话", icon: "none" });
|
||||
return;
|
||||
}
|
||||
@@ -178,19 +227,22 @@ const handleCall = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
sendCreateWorkOrder();
|
||||
sendCreateWorkOrder(phoneToSubmit);
|
||||
};
|
||||
|
||||
/// 创建工单
|
||||
const sendCreateWorkOrder = async () => {
|
||||
const sendCreateWorkOrder = async (phoneToSubmit) => {
|
||||
try {
|
||||
const res = await createWorkOrder({
|
||||
const params = {
|
||||
workOrderTypeId: workOrderTypeId.value,
|
||||
roomNo: roomId.value,
|
||||
userPhone: contactPhone.value,
|
||||
userPhone: phoneToSubmit,
|
||||
content: contactText.value,
|
||||
contentImgUrl: contentImgUrl.value,
|
||||
});
|
||||
};
|
||||
console.log("🚀 ~ sendCreateWorkOrder ~ params:", params);
|
||||
|
||||
const res = await createWorkOrder(params);
|
||||
|
||||
if (res.code === 0) {
|
||||
// 保存工单ID
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
width: 98px;
|
||||
height: 48px;
|
||||
}
|
||||
.order-content {
|
||||
width: 335px;
|
||||
}
|
||||
|
||||
.help-icon {
|
||||
width: 16px;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view v-if="!isCallSuccess" class="order-content border-box p-12">
|
||||
<view v-if="!isCallSuccess" class="border-box p-12">
|
||||
<view
|
||||
class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12"
|
||||
>
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
.order-content {
|
||||
width: 335px;
|
||||
}
|
||||
|
||||
.help-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { wxLogin } from "../request/api/LoginApi";
|
||||
import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager";
|
||||
import { clientId } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
|
||||
// 跳转登录
|
||||
export const goLogin = () => uni.navigateTo({ url: "/pages/login/index" });
|
||||
@@ -46,14 +47,44 @@ export const onLogin = async (e) => {
|
||||
|
||||
// 检测token
|
||||
export const checkToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const appStore = useAppStore();
|
||||
console.log("appStore.hasToken: ", appStore.hasToken);
|
||||
if (!appStore.hasToken) {
|
||||
console.log("没有token,跳转到登录页");
|
||||
if (!token) {
|
||||
goLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
// 刷新token
|
||||
export const refreshToken = () => {
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
uni.login({
|
||||
provider: "weixin", //使用微信登录
|
||||
success: async ({ code }) => {
|
||||
console.log("refreshToken", code);
|
||||
const params = {
|
||||
openIdCode: [code],
|
||||
grant_type: "wechat",
|
||||
scope: "server",
|
||||
clientId: clientId,
|
||||
};
|
||||
console.log("获取到的微信授权params:", JSON.stringify(params));
|
||||
const response = await wxLogin(params);
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,6 +16,8 @@ app.$mount();
|
||||
import { createSSRApp } from "vue";
|
||||
import * as Pinia from "pinia";
|
||||
import { createUnistorage } from "pinia-plugin-unistorage";
|
||||
import noclick from "./utils/noclick";
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App);
|
||||
const pinia = Pinia.createPinia();
|
||||
@@ -23,10 +25,11 @@ export function createApp() {
|
||||
pinia.use(createUnistorage());
|
||||
app.use(pinia);
|
||||
app.use(share);
|
||||
app.use(noclick);
|
||||
|
||||
return {
|
||||
app,
|
||||
pinia,
|
||||
};
|
||||
}
|
||||
// #endif
|
||||
// #endif
|
||||
@@ -22,12 +22,8 @@ export const getWeChatAuthCode = (e) => {
|
||||
uni.login({
|
||||
provider,
|
||||
onlyAuthorize: true,
|
||||
success: (res) => {
|
||||
resolve(res.code);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
success: (res) => resolve(res.code),
|
||||
fail: (err) => reject(err),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@ import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||
const loginAuth = (e) => {
|
||||
uni.setStorageSync("token", "");
|
||||
const appStore = useAppStore();
|
||||
appStore.setHasToken(false);
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const openIdCode = await getWeChatAuthCode(e);
|
||||
@@ -28,8 +27,6 @@ const loginAuth = (e) => {
|
||||
|
||||
if (response.access_token) {
|
||||
uni.setStorageSync("token", response.access_token);
|
||||
const appStore = useAppStore();
|
||||
appStore.setHasToken(true);
|
||||
// 登录成功后,触发登录成功事件
|
||||
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||
resolve();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
/>
|
||||
<text
|
||||
class="font-size-16 font-500 color-white"
|
||||
@click="emit('payClick', orderData)"
|
||||
@click="$onMultipleClicks(() => emit('payClick', orderData))"
|
||||
>立即支付</text
|
||||
>
|
||||
</view>
|
||||
@@ -57,7 +57,6 @@ const count = computed({
|
||||
const totalAmt = computed(() => {
|
||||
const { totalDays } = props.selectedDate;
|
||||
const { specificationPrice } = props.orderData;
|
||||
|
||||
return count.value * Number(specificationPrice) * totalDays;
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -128,11 +128,6 @@ const isDeleting = ref(false); // 标志位,防止删除时watch冲突
|
||||
watch(
|
||||
quantity,
|
||||
async (newQuantity) => {
|
||||
// 非酒店类型,不处理
|
||||
if (orderData.value.commodityTypeCode !== "0") {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果正在执行删除操作,跳过watch逻辑
|
||||
if (isDeleting.value) {
|
||||
isDeleting.value = false;
|
||||
@@ -208,96 +203,107 @@ const validateUserForms = () => {
|
||||
|
||||
// 处理支付点击事件
|
||||
const handlePayClick = ThrottleUtils.createThrottle(async (goodsData) => {
|
||||
console.log("处理支付点击事件", userFormList.value);
|
||||
// 判断是酒店类型
|
||||
if (goodsData.commodityTypeCode === "0") {
|
||||
// 校验用户姓名
|
||||
if (!validateUserForms()) {
|
||||
// 点击后立即展示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
|
||||
try {
|
||||
console.log("处理支付点击事件", userFormList.value);
|
||||
// 判断是酒店类型
|
||||
if (goodsData.commodityTypeCode === "0") {
|
||||
// 校验用户姓名
|
||||
if (!validateUserForms()) {
|
||||
uni.hideLoading();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 购买的商品id
|
||||
const commodityId = goodsData.commodityId;
|
||||
// 消费者信息
|
||||
const consumerInfoEntityList = userFormList.value;
|
||||
// 购买数量
|
||||
const purchaseAmount = consumerInfoEntityList.length;
|
||||
// 支付方式 0-微信 1-支付宝 2-云闪付
|
||||
const payWay = "0";
|
||||
// 支付渠道 0-app 1-小程序 2-h5
|
||||
const paySource = "1";
|
||||
|
||||
const params = {
|
||||
commodityId,
|
||||
purchaseAmount,
|
||||
payWay,
|
||||
paySource,
|
||||
consumerInfoEntityList,
|
||||
};
|
||||
|
||||
//酒店类型添加入住时间、离店时间
|
||||
if (goodsData.commodityTypeCode === "0" && selectedDate.value) {
|
||||
const { startDate, endDate } = selectedDate.value;
|
||||
// 入住时间
|
||||
params.checkInData = startDate;
|
||||
// 离店时间
|
||||
params.checkOutData = endDate;
|
||||
}
|
||||
|
||||
const res = await orderPay(params);
|
||||
console.log("确认订单---2:", res);
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = res;
|
||||
const { nonceStr, packageVal, paySign, signType, timeStamp } = data;
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
timeStamp: String(timeStamp), // 确保为字符串类型
|
||||
nonceStr: String(nonceStr),
|
||||
package: String(packageVal), // 确保为字符串类型
|
||||
signType: String(signType),
|
||||
paySign: String(paySign),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: "支付成功",
|
||||
icon: "success",
|
||||
success: () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages-order/order/list",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
uni.showToast({ title: "请求出错,请重试", icon: "none" });
|
||||
} finally {
|
||||
// 防止某些分支忘记 hide,确保最终关闭 loading(requestPayment 后也可以安全调用 hide)
|
||||
uni.hideLoading();
|
||||
}
|
||||
// 校验手机号
|
||||
if (!PhoneUtils.validatePhone(userFormList.value[0].contactPhone)) {
|
||||
uni.showToast({ title: "请输入正确的手机号", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 购买的商品id
|
||||
const commodityId = goodsData.commodityId;
|
||||
// 消费者信息
|
||||
const consumerInfoEntityList = userFormList.value;
|
||||
// 购买数量
|
||||
const purchaseAmount = consumerInfoEntityList.length;
|
||||
// 支付方式 0-微信 1-支付宝 2-云闪付
|
||||
const payWay = "0";
|
||||
// 支付渠道 0-app 1-小程序 2-h5
|
||||
const paySource = "1";
|
||||
|
||||
const params = {
|
||||
commodityId,
|
||||
purchaseAmount,
|
||||
payWay,
|
||||
paySource,
|
||||
consumerInfoEntityList,
|
||||
};
|
||||
|
||||
//酒店类型添加入住时间、离店时间
|
||||
if (goodsData.commodityTypeCode === "0" && selectedDate.value) {
|
||||
const { startDate, endDate } = selectedDate.value;
|
||||
// 入住时间
|
||||
params.checkInData = startDate;
|
||||
// 离店时间
|
||||
params.checkOutData = endDate;
|
||||
}
|
||||
|
||||
const res = await orderPay(params);
|
||||
console.log("确认订单---2:", res);
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||
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" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
timeStamp: String(timeStamp), // 确保为字符串类型
|
||||
nonceStr: String(nonceStr),
|
||||
package: String(packageVal), // 确保为字符串类型
|
||||
signType: String(signType),
|
||||
paySign: String(paySign),
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: "支付成功",
|
||||
icon: "success",
|
||||
success: () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages-order/order/list",
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: "支付失败,请重试", icon: "none" });
|
||||
},
|
||||
});
|
||||
}, 1000);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
'bg-2D91FF': ['1', '2', '3', '4', '5', '6'].includes(statusCode),
|
||||
},
|
||||
]"
|
||||
@click="handleButtonClick(orderData)"
|
||||
@click="$onmultipleClicks(() => handleButtonClick(orderData))"
|
||||
>
|
||||
{{ buttonText }}
|
||||
</button>
|
||||
@@ -71,10 +71,14 @@ const handleButtonClick = async (orderData) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/goods/index?commodityId=${orderData.commodityId}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 待支付状态,调用支付接口
|
||||
if (statusCode.value === "0") {
|
||||
// 显示 loading
|
||||
uni.showLoading({ title: "正在提交订单..." });
|
||||
|
||||
const orderId = orderData.orderId;
|
||||
const payWay = orderData.payWay;
|
||||
const paySource = orderData.paySource;
|
||||
@@ -84,6 +88,7 @@ const handleButtonClick = async (orderData) => {
|
||||
|
||||
// 检查接口返回数据
|
||||
if (!res || !res.data) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "订单创建失败,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
@@ -93,17 +98,14 @@ const handleButtonClick = async (orderData) => {
|
||||
|
||||
// 验证支付参数是否完整
|
||||
if (!nonceStr || !packageVal || !paySign || !signType || !timeStamp) {
|
||||
// console.error("支付参数不完整:", {
|
||||
// nonceStr: !!nonceStr,
|
||||
// packageVal: !!packageVal,
|
||||
// paySign: !!paySign,
|
||||
// signType: !!signType,
|
||||
// timeStamp: !!timeStamp,
|
||||
// });
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "支付参数错误,请重试", icon: "none" });
|
||||
return;
|
||||
}
|
||||
|
||||
// 在发起微信支付前关闭 loading(避免与原生支付 UI 冲突)
|
||||
uni.hideLoading();
|
||||
|
||||
// 调用微信支付
|
||||
uni.requestPayment({
|
||||
provider: "wxpay",
|
||||
@@ -126,6 +128,7 @@ const handleButtonClick = async (orderData) => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("操作失败:", error);
|
||||
uni.hideLoading();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -100,8 +100,6 @@ const handleLogout = () => {
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.clearStorageSync();
|
||||
appStore.setHasToken(false);
|
||||
appStore.setTokenExpired(true);
|
||||
emits("close");
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
v-else-if="
|
||||
item.toolCall.componentName === CompName.callServiceCard
|
||||
"
|
||||
:toolCall="item.toolCall"
|
||||
/>
|
||||
<Feedback
|
||||
v-else-if="
|
||||
@@ -132,7 +133,6 @@ import {
|
||||
NOTICE_EVENT_LOGOUT,
|
||||
NOTICE_EVENT_LOGIN_SUCCESS,
|
||||
} from "@/constant/constant";
|
||||
import { WSS_URL } from "@/request/base/baseUrl";
|
||||
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
|
||||
import ChatTopWelcome from "../ChatTopWelcome/index.vue";
|
||||
import ChatTopNavBar from "../ChatTopNavBar/index.vue";
|
||||
@@ -346,7 +346,9 @@ onLoad(() => {
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
console.log("initHandler");
|
||||
if (!appStore.hasToken) return;
|
||||
const token = uni.getStorageSync("token");
|
||||
|
||||
if (!token) return;
|
||||
loadRecentConversation();
|
||||
///loadConversationMsgList();
|
||||
initWebSocket();
|
||||
@@ -405,7 +407,7 @@ const getMainPageData = async () => {
|
||||
|
||||
/// =============对话↓================
|
||||
// 初始化WebSocket
|
||||
const initWebSocket = () => {
|
||||
const initWebSocket = async () => {
|
||||
// 清理旧实例
|
||||
if (webSocketManager) {
|
||||
webSocketManager.destroy();
|
||||
@@ -413,7 +415,7 @@ const initWebSocket = () => {
|
||||
|
||||
// 使用配置的WebSocket服务器地址
|
||||
const token = uni.getStorageSync("token");
|
||||
const wsUrl = `${WSS_URL}?access_token=${token}`;
|
||||
const wsUrl = `${appStore.serverConfig.wssUrl}?access_token=${token}`;
|
||||
|
||||
// 初始化WebSocket管理器
|
||||
webSocketManager = new WebSocketManager({
|
||||
@@ -424,9 +426,10 @@ const initWebSocket = () => {
|
||||
|
||||
// 连接成功回调
|
||||
onOpen: (event) => {
|
||||
console.log("WebSocket连接成功");
|
||||
// 重置会话状态
|
||||
webSocketConnectStatus = true;
|
||||
isSessionActive.value = true;
|
||||
isSessionActive.value = false; // 连接成功时重置会话状态,避免影响新消息发送
|
||||
},
|
||||
|
||||
// 连接断开回调
|
||||
@@ -439,9 +442,9 @@ const initWebSocket = () => {
|
||||
|
||||
// 错误回调
|
||||
onError: (error) => {
|
||||
console.error("WebSocket错误:", error);
|
||||
webSocketConnectStatus = false;
|
||||
isSessionActive.value = false;
|
||||
console.error("WebSocket错误:", error);
|
||||
},
|
||||
|
||||
// 消息回调
|
||||
@@ -456,67 +459,73 @@ const initWebSocket = () => {
|
||||
getAgentId: () => agentId.value,
|
||||
});
|
||||
|
||||
// 初始化连接
|
||||
webSocketManager
|
||||
.connect()
|
||||
.then(() => {
|
||||
webSocketConnectStatus = true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("WebSocket连接失败:", error);
|
||||
});
|
||||
try {
|
||||
// 初始化连接
|
||||
await webSocketManager.connect();
|
||||
console.log("WebSocket连接初始化成功");
|
||||
webSocketConnectStatus = true;
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("WebSocket连接失败:", error);
|
||||
webSocketConnectStatus = false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理WebSocket消息
|
||||
const handleWebSocketMessage = (data) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
data.content = String(data.content);
|
||||
}
|
||||
|
||||
// 直接拼接内容到AI消息
|
||||
if (data.content) {
|
||||
if (chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
const handleWebSocketMessage = (data) => {
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) {
|
||||
console.error("处理WebSocket消息时找不到对应的AI消息项");
|
||||
return;
|
||||
}
|
||||
chatMsgList.value[aiMsgIndex].msg += data.content;
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
// 处理完成状态
|
||||
if (data.finish) {
|
||||
const msg = chatMsgList.value[aiMsgIndex].msg;
|
||||
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
if (data.toolCall) {
|
||||
// 确保消息内容是字符串类型
|
||||
if (data.content && typeof data.content !== "string") {
|
||||
data.content = String(data.content);
|
||||
}
|
||||
|
||||
// 直接拼接内容到AI消息
|
||||
if (data.content) {
|
||||
if (chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
chatMsgList.value[aiMsgIndex].msg += data.content;
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
nextTick(() => scrollToBottom());
|
||||
}
|
||||
|
||||
// 处理toolCall
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].toolCall = data.toolCall;
|
||||
}
|
||||
// 处理完成状态
|
||||
if (data.finish) {
|
||||
const msg = chatMsgList.value[aiMsgIndex].msg;
|
||||
if (!msg || chatMsgList.value[aiMsgIndex].isLoading) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理question
|
||||
if (data.question && data.question.length > 0) {
|
||||
chatMsgList.value[aiMsgIndex].question = data.question;
|
||||
}
|
||||
// 处理toolCall
|
||||
if (data.toolCall) {
|
||||
chatMsgList.value[aiMsgIndex].toolCall = data.toolCall;
|
||||
}
|
||||
|
||||
// 重置会话状态
|
||||
isSessionActive.value = false;
|
||||
}
|
||||
};
|
||||
// 处理question
|
||||
if (data.question && data.question.length > 0) {
|
||||
chatMsgList.value[aiMsgIndex].question = data.question;
|
||||
}
|
||||
|
||||
// 重置会话状态
|
||||
isSessionActive.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 重置消息状态
|
||||
const resetMessageState = () => {};
|
||||
const resetMessageState = () => {
|
||||
// 重置当前会话消息ID
|
||||
currentSessionMessageId = null;
|
||||
};
|
||||
|
||||
// 初始化数据 首次数据加载的时候
|
||||
const initData = () => {
|
||||
@@ -534,12 +543,39 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
|
||||
await checkToken();
|
||||
|
||||
// 检查WebSocket连接状态,如果未连接,尝试重新连接
|
||||
if (!webSocketConnectStatus) {
|
||||
uni.showToast({
|
||||
title: "当前网络异常,请稍后重试",
|
||||
icon: "none",
|
||||
console.log("WebSocket未连接,尝试重新连接...");
|
||||
// 显示加载提示
|
||||
uni.showLoading({
|
||||
title: "正在连接服务器...",
|
||||
});
|
||||
return;
|
||||
|
||||
// 尝试重新初始化WebSocket连接
|
||||
try {
|
||||
await initWebSocket();
|
||||
// 等待短暂时间确保连接建立
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
// 检查连接是否成功建立
|
||||
if (!webSocketConnectStatus) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.hideLoading();
|
||||
} catch (error) {
|
||||
console.error("重新连接WebSocket失败:", error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "连接服务器失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSessionActive.value) {
|
||||
@@ -561,6 +597,8 @@ const sendMessage = async (message, isInstruct = false) => {
|
||||
};
|
||||
chatMsgList.value.push(newMsg);
|
||||
inputMessage.value = "";
|
||||
// 发送消息后滚动到底部
|
||||
setTimeoutScrollToBottom();
|
||||
sendChat(message, isInstruct);
|
||||
console.log("发送的新消息:", JSON.stringify(newMsg));
|
||||
};
|
||||
@@ -576,9 +614,11 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
|
||||
};
|
||||
|
||||
try {
|
||||
webSocketManager.sendMessage(args);
|
||||
// 直接调用webSocketManager的sendMessage方法,利用其内部的消息队列机制
|
||||
// 即使当前连接断开,消息也会被加入队列,等待连接恢复后发送
|
||||
const result = webSocketManager.sendMessage(args);
|
||||
console.log(`WebSocket消息已发送 [类型:${messageType}]:`, args);
|
||||
return true;
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("发送WebSocket消息失败:", error);
|
||||
isSessionActive.value = false;
|
||||
@@ -588,9 +628,26 @@ const sendWebSocketMessage = (messageType, messageContent, options = {}) => {
|
||||
|
||||
// 发送获取AI聊天消息
|
||||
const sendChat = (message, isInstruct = false) => {
|
||||
if (!webSocketManager || !webSocketManager.isConnected()) {
|
||||
console.error("WebSocket未连接");
|
||||
isSessionActive.value = false;
|
||||
// 检查WebSocket管理器是否存在,如果不存在,尝试重新初始化
|
||||
if (!webSocketManager) {
|
||||
console.error("WebSocket管理器不存在,尝试重新初始化...");
|
||||
initWebSocket();
|
||||
// 短暂延迟后再次检查连接状态
|
||||
setTimeout(() => {
|
||||
if (webSocketManager && webSocketManager.isConnected()) {
|
||||
// 连接成功后重新发送消息
|
||||
sendChat(message, isInstruct);
|
||||
} else {
|
||||
console.error("WebSocket重新初始化失败");
|
||||
isSessionActive.value = false;
|
||||
// 更新AI消息状态为失败
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
if (aiMsgIndex >= 0 && chatMsgList.value[aiMsgIndex].msgType === MessageRole.AI) {
|
||||
chatMsgList.value[aiMsgIndex].msg = "发送消息失败,请重试";
|
||||
chatMsgList.value[aiMsgIndex].isLoading = false;
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -613,6 +670,8 @@ const sendChat = (message, isInstruct = false) => {
|
||||
},
|
||||
};
|
||||
chatMsgList.value.push(aiMsg);
|
||||
// 添加AI消息后滚动到底部
|
||||
setTimeoutScrollToBottom();
|
||||
const aiMsgIndex = chatMsgList.value.length - 1;
|
||||
|
||||
// 发送消息
|
||||
@@ -676,6 +735,7 @@ const resetConfig = () => {
|
||||
|
||||
// 重置消息状态
|
||||
resetMessageState();
|
||||
isSessionActive.value = false;
|
||||
|
||||
// 清理定时器
|
||||
if (holdKeyboardTimer.value) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view
|
||||
class="quick-access border-box flex flex-nowrap items-center ml-12 pt-8 pb-8"
|
||||
class="quick-access flex flex-row ml-12 pt-8 pb-8 scroll-x whitespace-nowrap"
|
||||
>
|
||||
<view
|
||||
class="item border-box rounded-50 flex flex-row items-center"
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
></view>
|
||||
<text
|
||||
v-show="show"
|
||||
class="font-size-14 font-500 color-171717 ml-10"
|
||||
:class="{ 'text-animated': show }"
|
||||
>沐沐</text
|
||||
:class="[
|
||||
'font-size-14 font-500 color-171717 ml-10',
|
||||
{ 'text-animated': show },
|
||||
]"
|
||||
>
|
||||
{{ config.name }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class="w-24 h-24"></view>
|
||||
@@ -34,10 +37,8 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const show = ref(false);
|
||||
|
||||
const config = getCurrentConfig();
|
||||
const getStyle = computed(() => {
|
||||
const config = getCurrentConfig();
|
||||
|
||||
return {
|
||||
"--ipSmallImageStep": config.ipSmallImageStep,
|
||||
"--ipSmallImageHeight": config.ipSmallImageHeight,
|
||||
|
||||
@@ -3,11 +3,21 @@
|
||||
}
|
||||
|
||||
.ip {
|
||||
position: relative;
|
||||
flex: 0 0 158px;
|
||||
width: 158px;
|
||||
height: 134px;
|
||||
animation: sprite-play calc(var(--ipLargeTime) * 1s)
|
||||
steps(var(--ipLargeImageStep)) infinite;
|
||||
&::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
background-color: #f9fcfd;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sprite-play {
|
||||
|
||||
@@ -43,8 +43,7 @@
|
||||
type="primary"
|
||||
@click="handleAgreeAndGetPhone"
|
||||
>
|
||||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||||
微信一键登录
|
||||
手机号快捷登录
|
||||
</button>
|
||||
|
||||
<button
|
||||
@@ -54,18 +53,7 @@
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
>
|
||||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||||
微信一键登录
|
||||
</button>
|
||||
|
||||
<button
|
||||
v-if="isAgree && appStore.tokenExpired"
|
||||
class="login-btn"
|
||||
type="primary"
|
||||
@click="handleLogin"
|
||||
>
|
||||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||||
微信一键登录
|
||||
手机号快捷登录
|
||||
</button>
|
||||
</view>
|
||||
|
||||
@@ -123,20 +111,6 @@ const getPhoneNumber = (e) => {
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
const handleLogin = () => {
|
||||
console.log("handleLogin");
|
||||
onLogin()
|
||||
.then(() => {
|
||||
uni.showToast({
|
||||
title: "登录成功",
|
||||
icon: "success",
|
||||
});
|
||||
appStore.setTokenExpired(false);
|
||||
goBack();
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
// 处理同意协议点击事件
|
||||
const handleAgreeClick = (type) => {
|
||||
visible.value = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BASE_URL } from "@/request/base/baseUrl";
|
||||
import { goLogin } from "@/hooks/useGoLogin";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
/// 请求流式数据的API
|
||||
const API = "/agent/assistant/chat";
|
||||
@@ -93,8 +93,9 @@ const agentChatStream = (params, onChunk) => {
|
||||
};
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const { serverConfig } = useAppStore();
|
||||
requestTask = uni.request({
|
||||
url: BASE_URL + API, // 替换为你的接口地址
|
||||
url: serverConfig.baseUrl + API, // 替换为你的接口地址
|
||||
method: "POST",
|
||||
data: params,
|
||||
enableChunked: true,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { BASE_URL } from "@/request/base/baseUrl";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
export const updateImageFile = (file) => {
|
||||
const url = BASE_URL + "/hotelBiz/hotBizCommon/upload";
|
||||
const { serverConfig } = useAppStore();
|
||||
const url = serverConfig.baseUrl + "/hotelBiz/hotBizCommon/upload";
|
||||
const token = uni.getStorageSync("token");
|
||||
const clientId = getCurrentConfig().clientId;
|
||||
|
||||
|
||||
17
src/request/api/config.js
Normal file
17
src/request/api/config.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import request from "../base/request";
|
||||
import { isProd } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
|
||||
// 获取服务地址
|
||||
const getEvnUrl = (args) => {
|
||||
if (isProd) {
|
||||
const appStore = useAppStore();
|
||||
request
|
||||
.post("https://biz.nianxx.cn/hotelBiz/mainScene/getServiceUrl", args)
|
||||
.then(({ data }) => {
|
||||
appStore.setServerConfig(data);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export { getEvnUrl };
|
||||
@@ -1,19 +1 @@
|
||||
import { isProd } from '@/constant/base.js';
|
||||
|
||||
// 测试
|
||||
const VITE_BASE_URL_TEST = "https://onefeel.brother7.cn/ingress";
|
||||
const VITE_WSS_URL_TEST = "wss://onefeel.brother7.cn/ingress/agent/ws/chat";
|
||||
|
||||
// 生产
|
||||
const VITE_BASE_URL_PRO = "https://biz.nianxx.cn";
|
||||
const VITE_WSS_URL_PRO = "wss://biz.nianxx.cn/agent/ws/chat";
|
||||
|
||||
// 环境配置 - 根据客户端配置动态决定环境
|
||||
export const BASE_URL = isProd ? VITE_BASE_URL_PRO : VITE_BASE_URL_TEST;
|
||||
export const WSS_URL = isProd ? VITE_WSS_URL_PRO : VITE_WSS_URL_TEST;
|
||||
|
||||
// =====================================
|
||||
// 环境配置文件使用方法
|
||||
// console.log("当前环境:", import.meta.env);
|
||||
// export const BASE_URL = import.meta.env.VITE_BASE_URL;
|
||||
// export const WSS_URL = import.meta.env.VITE_WSS_URL;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { goLogin } from "../../hooks/useGoLogin";
|
||||
import { BASE_URL } from "./baseUrl";
|
||||
import { getCurrentConfig } from "@/constant/base";
|
||||
import { useAppStore } from "@/store";
|
||||
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||
@@ -14,9 +13,10 @@ const defaultConfig = {
|
||||
};
|
||||
|
||||
function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
const appStore = useAppStore();
|
||||
// 判断 url 是否以 http 开头
|
||||
if (!/^http/.test(url)) {
|
||||
url = BASE_URL + url;
|
||||
url = appStore.serverConfig?.baseUrl + url;
|
||||
}
|
||||
// 动态获取 token
|
||||
const token = uni.getStorageSync("token");
|
||||
@@ -25,6 +25,7 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
...defaultConfig.header,
|
||||
...customConfig.header,
|
||||
};
|
||||
|
||||
// 判断是否需要 token
|
||||
if (customConfig.noToken) {
|
||||
delete header.Authorization;
|
||||
@@ -58,9 +59,6 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
||||
if (res.statusCode && res.statusCode === 424) {
|
||||
console.log("424错误,重新登录");
|
||||
uni.setStorageSync("token", "");
|
||||
const appStore = useAppStore();
|
||||
appStore.setHasToken(false);
|
||||
appStore.setTokenExpired(true);
|
||||
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||
goLogin();
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ export const useAppStore = defineStore("app", {
|
||||
state() {
|
||||
return {
|
||||
title: "",
|
||||
sceneId: "", /// 分身场景id
|
||||
hasToken: false, /// 是否有token
|
||||
tokenExpired: false, /// token是否过期
|
||||
previewImageData: [], /// 预览图片数据
|
||||
sceneId: "", // 分身场景id
|
||||
previewImageData: [], // 预览图片数据
|
||||
serverConfig: {
|
||||
baseUrl: "https://onefeel.brother7.cn/ingress", // 服务器基础地址
|
||||
wssUrl: "wss://onefeel.brother7.cn/ingress/agent/ws/chat", // 服务器ws地址
|
||||
}, // 服务器配置
|
||||
};
|
||||
},
|
||||
getters: {},
|
||||
@@ -19,15 +21,12 @@ export const useAppStore = defineStore("app", {
|
||||
setSceneId(data) {
|
||||
this.sceneId = data;
|
||||
},
|
||||
setHasToken(status) {
|
||||
this.hasToken = status;
|
||||
},
|
||||
setTokenExpired(status) {
|
||||
this.tokenExpired = status;
|
||||
},
|
||||
setPreviewImageData(data) {
|
||||
this.previewImageData = data;
|
||||
},
|
||||
setServerConfig(data) {
|
||||
this.serverConfig = data;
|
||||
},
|
||||
},
|
||||
|
||||
unistorage: true,
|
||||
|
||||
@@ -3,7 +3,11 @@ import { defineStore } from "pinia";
|
||||
export const useSelectedDateStore = defineStore("selectedDate", {
|
||||
state() {
|
||||
return {
|
||||
selectedDate: {},
|
||||
selectedDate: {
|
||||
startDate: "",
|
||||
endDate: "",
|
||||
totalDays: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
28
src/utils/noclick.js
Normal file
28
src/utils/noclick.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// 防止处理多次点击
|
||||
// methods是需要点击后需要执行的函数, info是点击需要传的参数
|
||||
export function noMultipleClicks(fn, info, delay = 2000) {
|
||||
if (typeof fn !== 'function') return;
|
||||
// this 会是组件实例(因为通过 globalProperties 调用时 Vue 会把组件实例作为上下文)
|
||||
const ctx = this || {};
|
||||
if (!ctx.__noClickMap) ctx.__noClickMap = new WeakMap();
|
||||
|
||||
const map = ctx.__noClickMap;
|
||||
if (map.get(fn)) {
|
||||
console.log('请勿重复点击:', fn.name);
|
||||
return;
|
||||
}
|
||||
|
||||
map.set(fn, true);
|
||||
// 保留组件上下文调用方法
|
||||
fn.call(ctx, info);
|
||||
|
||||
setTimeout(() => {
|
||||
map.set(fn, false);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
app.config.globalProperties.$noMultipleClicks = noMultipleClicks;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ export default {
|
||||
app.mixin({
|
||||
onLoad() {
|
||||
const page = getCurrentPages().pop();
|
||||
if (page) {
|
||||
console.log("Current page:", page);
|
||||
const allowShare = page && page.route && page.route !== "pages/login/index";
|
||||
if (allowShare) {
|
||||
uni.showShareMenu({
|
||||
withShareTicket: true,
|
||||
menus: ["shareAppMessage", "shareTimeline"],
|
||||
|
||||
Reference in New Issue
Block a user