diff --git a/common/config.js b/common/config.js new file mode 100644 index 0000000..4b0f316 --- /dev/null +++ b/common/config.js @@ -0,0 +1,54 @@ +// const debug = process.env.NODE_ENV == 'development' ? true : false; +const debug = false; +// #ifdef H5 +const proxyApi = "/api"; +// #endif + +// #ifdef MP-WEIXIN || APP || MP-ALIPAY +const proxyApi = "http://192.168.1.42"; // 调试地址 +const proxyApiwws = "ws://192.168.1.42:2348"; // 调试地址 +// #endif + +// #ifdef H5 +const baseUrl = debug ? proxyApi : "http://192.168.1.42"; +const baseUrlwws = "ws://192.168.1.42:2348"; +// #endif + +// #ifdef APP || MP-WEIXIN || MP-ALIPAY +const baseUrl = debug ? proxyApi : "https://cashier.sxczgkj.com"; // 线上 +const baseUrlwws = debug ? proxyApiwws : "wss://czgeatws.sxczgkj.com/wss"; // 线上 +// #endif + +const version = "100"; +const autoRemoveCache = { + count: 100000, + size: 100000, +}; + uni.conf = { + debug, + baseUrl, + version, + autoRemoveCache, + baseUrlwws, +}; + +export const changeEnv = (env) => { + if (env === "test") { + uni.conf = { + debug: true, + baseUrl: "http://192.168.1.42", + version: 100, + autoRemoveCache, + baseUrlwws: "ws://192.168.1.42:2348", + }; + } + if (env === "prod") { + uni.conf = { + debug: false, + baseUrl: "https://cashier.sxczgkj.com", + version: 100, + autoRemoveCache, + baseUrlwws: "wss://czgeatws.sxczgkj.com/wss", + }; + } +}; diff --git a/components/devetools.vue b/components/devetools.vue index c1afafb..2e8b22d 100644 --- a/components/devetools.vue +++ b/components/devetools.vue @@ -34,6 +34,14 @@ > + + + 当前环境: + {{ uni.conf.debug ? "测试环境" : "生产环境" }} + + import { ref, defineProps, defineEmits, computed } from "vue"; +import { changeEnv } from "@/common/config.js"; +import { Storelogin } from "@/stores/user.js"; const show = computed(() => { // trial const sysInfo = uni.getAccountInfoSync(); if ( sysInfo && sysInfo.miniProgram && - ( - sysInfo.miniProgram.envVersion == "develop") + sysInfo.miniProgram.envVersion == "develop" ) { return true; } @@ -109,6 +118,18 @@ const props = defineProps({ operations: { type: Array, default: () => [ + { + name: "切换为测试环境", + icon: "arrowup", + action: "test", + color: "#007aff", + }, + { + name: "切换为正式环境", + icon: "arrowup", + action: "prod", + color: "#007aff", + }, { name: "复制token", icon: "arrowup", @@ -201,9 +222,31 @@ async function getWxloginCode() { }); }); } +const storelogin = Storelogin(); + // 处理操作选择 const handleOperation = async (action) => { let data = ""; + + if (action == "prod" || action == "test") { + changeEnv(action); + emit("onOperation", action); + uni.showToast({ + title: "切换成功", + icon: "success", + }); + uni.clearStorageSync(); + + await storelogin.actionslogin(); + setTimeout(() => { + uni.reLaunch({ + url: "/pages/index/index", + }); + }, 1500); + + closePopup(); + return; + } if (action == "token") { data = uni.cache.get("token"); } @@ -220,10 +263,13 @@ const handleOperation = async (action) => { data = JSON.stringify(uni.cache.get("shopUserInfo")); } console.log("data", data); - uni.setClipboardData({ - data: data, - success: function () {}, - }); + if (data) { + uni.setClipboardData({ + data: data, + success: function () {}, + }); + } + emit("onOperation", action); closePopup(); }; @@ -269,7 +315,7 @@ const handleOperation = async (action) => { position: absolute; bottom: calc(100% + 15px); right: 0; - min-width: 160px; + min-width: 180px; background-color: #ffffff; border-radius: 12px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15); @@ -318,7 +364,6 @@ const handleOperation = async (action) => { } .item-text { - margin-left: 12px; font-size: 14px; color: #333333; line-height: 1; diff --git a/user/components/registermember.vue b/user/components/registermember.vue index b215fdf..0596a4b 100644 --- a/user/components/registermember.vue +++ b/user/components/registermember.vue @@ -118,6 +118,10 @@ type: Boolean, default: false }, + shopId: { + type: String, + default: '' + }, }); // 定义事件发射器 @@ -145,11 +149,11 @@ const init = async () => { - // if (uni.cache.get('shopUserInfo') && uni.cache.get('shopId') == uni.cache.get('shopUserInfo').id) { + // if (uni.cache.get('shopUserInfo') && props.shopId||uni.cache.get('shopId') == uni.cache.get('shopUserInfo').id) { // shopUserInfo = uni.cache.get('shopUserInfo'); // } else { // let res = await this.api.shopUserInfo({ - // "shopId": uni.cache.get('shopId'), + // "shopId": props.shopId||uni.cache.get('shopId'), // "userId": uni.cache.get('userInfo').id, // }) // if (res.code == 0) { @@ -192,7 +196,7 @@ url: uni.conf.baseUrl + '/account/user/common/upload', filePath: avatarUrl, header: { - shopId: uni.cache.get('shopId'), + shopId: props.shopId||uni.cache.get('shopId'), token: uni.cache.get('token') || '', 'content-type': 'multipart/form-data' }, @@ -339,7 +343,7 @@ } const submitForm={ // id: uni.cache.get('userInfo').id, - // shopId: uni.cache.get('shopId'), + shopId: props.shopId||uni.cache.get('shopId'), nickName: formInfo.nickName, headImg: userHeadImg.value, phone: formInfo.telephone, @@ -348,7 +352,7 @@ } await APIshopUser(submitForm) let APIshopUserInfores = await APIshopUserInfo({ - shopId: uni.cache.get('shopId') + shopId: props.shopId||uni.cache.get('shopId') }) uni.cache.set('orderVIP', APIshopUserInfores) uni.cache.set('ordershopUserInfo', APIshopUserInfores.shopInfo) diff --git a/user/vip/buy-vip.vue b/user/vip/buy-vip.vue index 4ff9230..d608abf 100644 --- a/user/vip/buy-vip.vue +++ b/user/vip/buy-vip.vue @@ -137,7 +137,7 @@ - +