feat: 获取扫码的参数
This commit is contained in:
46
App.vue
46
App.vue
@@ -1,36 +1,36 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
|
import { onLaunch, onShow, onHide, onLoad } from "@dcloudio/uni-app";
|
||||||
import { checkPhone } from "@/manager/LoginManager";
|
import { checkPhone } from "@/manager/LoginManager";
|
||||||
import { goLogin } from "@/hooks/useGoLogin";
|
import { goLogin } from "@/hooks/useGoLogin";
|
||||||
import { goHome } from "@/hooks/useGoHome";
|
import { goHome } from "@/hooks/useGoHome";
|
||||||
|
|
||||||
onLaunch(async () => {
|
onLaunch(async () => {
|
||||||
console.log("App Launch");
|
console.log("App Launch");
|
||||||
|
|
||||||
const token = uni.getStorageSync("token");
|
const token = uni.getStorageSync("token");
|
||||||
|
|
||||||
// 检测是否绑定手机号和token
|
// 检测是否绑定手机号和token
|
||||||
if (!token) {
|
if (!token) {
|
||||||
goLogin();
|
goLogin();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
const res = await checkPhone();
|
const res = await checkPhone();
|
||||||
|
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
goHome();
|
goHome();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
console.log("App Show");
|
console.log("App Show");
|
||||||
});
|
});
|
||||||
|
|
||||||
onHide(() => {
|
onHide(() => {
|
||||||
console.log("App Hide");
|
console.log("App Hide");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -41,18 +41,18 @@ onHide(() => {
|
|||||||
page,
|
page,
|
||||||
body,
|
body,
|
||||||
#app {
|
#app {
|
||||||
font-family: PingFang SC, PingFang SC;
|
font-family: PingFang SC, PingFang SC;
|
||||||
background-color: #e9f3f7;
|
background-color: #e9f3f7;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*每个页面公共css */
|
/*每个页面公共css */
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mb12 {
|
.mb12 {
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -157,7 +157,9 @@ import {
|
|||||||
import WebSocketManager from "@/utils/WebSocketManager";
|
import WebSocketManager from "@/utils/WebSocketManager";
|
||||||
import TypewriterManager from "@/utils/TypewriterManager";
|
import TypewriterManager from "@/utils/TypewriterManager";
|
||||||
import { IdUtils } from "@/utils";
|
import { IdUtils } from "@/utils";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
|
||||||
|
const appStore = useAppStore();
|
||||||
/// 导航栏相关
|
/// 导航栏相关
|
||||||
const statusBarHeight = ref(20);
|
const statusBarHeight = ref(20);
|
||||||
/// 输入框组件引用
|
/// 输入框组件引用
|
||||||
@@ -182,8 +184,6 @@ const chatMsgList = ref([]);
|
|||||||
/// 输入口的输入消息
|
/// 输入口的输入消息
|
||||||
const inputMessage = ref("");
|
const inputMessage = ref("");
|
||||||
|
|
||||||
/// 从个渠道获取如二维,没有的时候就返回首页的数据
|
|
||||||
const sceneId = ref("");
|
|
||||||
/// agentId 首页接口中获取
|
/// agentId 首页接口中获取
|
||||||
const agentId = ref("1");
|
const agentId = ref("1");
|
||||||
/// 会话ID 历史数据接口中获取
|
/// 会话ID 历史数据接口中获取
|
||||||
@@ -383,7 +383,9 @@ const loadConversationMsgList = async () => {
|
|||||||
|
|
||||||
// 获取首页数据
|
// 获取首页数据
|
||||||
const getMainPageData = async () => {
|
const getMainPageData = async () => {
|
||||||
const res = await mainPageData(sceneId.value);
|
/// 从个渠道获取如二维,没有的时候就返回首页的数据
|
||||||
|
const sceneId = appStore.sceneId || "";
|
||||||
|
const res = await mainPageData(sceneId);
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
mainPageDataModel.value = res.data;
|
mainPageDataModel.value = res.data;
|
||||||
agentId.value = res.data.agentId;
|
agentId.value = res.data.agentId;
|
||||||
|
|||||||
@@ -5,21 +5,24 @@
|
|||||||
|
|
||||||
<!-- 日历组件 -->
|
<!-- 日历组件 -->
|
||||||
<Calender
|
<Calender
|
||||||
:visible="calendarVisible"
|
:visible="calendarVisible"
|
||||||
mode="single"
|
mode="single"
|
||||||
:default-value="selectedDate"
|
:default-value="selectedDate"
|
||||||
@close="handleCalendarClose"
|
@close="handleCalendarClose"
|
||||||
@select="handleDateSelect"
|
@select="handleDateSelect"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onUnmounted } from "vue";
|
import { ref, onMounted, onUnmounted } from "vue";
|
||||||
import ChatMainList from "../chat/ChatMainList.vue";
|
import ChatMainList from "../chat/ChatMainList.vue";
|
||||||
import Calender from "@/components/Calender/index.vue";
|
import Calender from "@/components/Calender/index.vue";
|
||||||
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
|
import { GetWxMiniProgramUrlParam } from "@/utils/UrlParams";
|
||||||
|
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
|
||||||
|
const appStore = useAppStore();
|
||||||
|
|
||||||
const calendarVisible = ref(false);
|
const calendarVisible = ref(false);
|
||||||
const selectedDate = ref("");
|
const selectedDate = ref("");
|
||||||
@@ -35,17 +38,28 @@ const handleDateSelect = (data) => {
|
|||||||
calendarVisible.value = false;
|
calendarVisible.value = false;
|
||||||
console.log("选择的日期:", data.date);
|
console.log("选择的日期:", data.date);
|
||||||
uni.$emit("selectCalendarDate", selectedDate.value); // 传回父组件
|
uni.$emit("selectCalendarDate", selectedDate.value); // 传回父组件
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uni.$on("openCalendar", () => {
|
uni.$on("openCalendar", () => {
|
||||||
calendarVisible.value = true;
|
calendarVisible.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
const getWeixinMiniProgramParams = (e) => {
|
||||||
// uni.$off('openCalendar')
|
console.log("Params:", e);
|
||||||
})
|
if (e.q && e.q != "undefined") {
|
||||||
|
const qrUrl = decodeURIComponent(e.q); // 获取到二维码原始链接内容
|
||||||
|
const params = GetWxMiniProgramUrlParam(qrUrl);
|
||||||
|
appStore.setSceneId(params.sceneId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onLoad((e) => {
|
||||||
|
getWeixinMiniProgramParams(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
// uni.$off('openCalendar')
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export const useAppStore = defineStore("app", {
|
|||||||
state() {
|
state() {
|
||||||
return {
|
return {
|
||||||
title: "",
|
title: "",
|
||||||
|
sceneId: "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getters: {},
|
getters: {},
|
||||||
@@ -12,6 +13,9 @@ export const useAppStore = defineStore("app", {
|
|||||||
setData(data) {
|
setData(data) {
|
||||||
this.title = data;
|
this.title = data;
|
||||||
},
|
},
|
||||||
|
setSceneId(data) {
|
||||||
|
this.sceneId = data;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
unistorage: true,
|
unistorage: true,
|
||||||
|
|||||||
17
utils/UrlParams.js
Normal file
17
utils/UrlParams.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
export function GetWxMiniProgramUrlParam(url) {
|
||||||
|
let theRequest = {};
|
||||||
|
if(url.indexOf("#") != -1){
|
||||||
|
const str=url.split("#")[1];
|
||||||
|
const strs=str.split("&");
|
||||||
|
for (let i = 0; i < strs.length; i++) {
|
||||||
|
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
|
||||||
|
}
|
||||||
|
}else if(url.indexOf("?") != -1){
|
||||||
|
const str=url.split("?")[1];
|
||||||
|
const strs=str.split("&");
|
||||||
|
for (let i = 0; i < strs.length; i++) {
|
||||||
|
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return theRequest;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user