|
@@ -240,47 +240,55 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</ul>
|
|
|
- <div class="fr">
|
|
|
- <!-- :value="12" -->
|
|
|
- <el-badge
|
|
|
- :value="badgeNum"
|
|
|
- style="cursor: pointer"
|
|
|
- class="badge"
|
|
|
- @click="noticeTableModal = true"
|
|
|
- >
|
|
|
- <el-icon :size="20">
|
|
|
- <BellFilled />
|
|
|
- </el-icon>
|
|
|
- </el-badge>
|
|
|
- <notice
|
|
|
- v-model="noticeTableModal"
|
|
|
- @changeNum="(e) => (badgeNum = e)"
|
|
|
- ></notice>
|
|
|
- <el-dropdown
|
|
|
- @command="handleCommand"
|
|
|
- class="right-menu-item hover-effect"
|
|
|
- trigger="click"
|
|
|
+ <div
|
|
|
+ class="jdTokenStatus"
|
|
|
+ style="display: flex; align-items: center; justify-content: center"
|
|
|
>
|
|
|
- <div class="dropdown-box">
|
|
|
- {{ userData }}
|
|
|
- </div>
|
|
|
- <template #dropdown>
|
|
|
- <el-dropdown-menu>
|
|
|
- <router-link to="/user/profile">
|
|
|
- <el-dropdown-item>{{
|
|
|
- $t("header.personalCenter")
|
|
|
- }}</el-dropdown-item>
|
|
|
- </router-link>
|
|
|
- <el-dropdown-item command="setLayout">
|
|
|
- <span>{{ $t("header.layoutSettings") }}</span>
|
|
|
- </el-dropdown-item>
|
|
|
- <el-dropdown-item divided command="logout">
|
|
|
- <span>{{ $t("header.logout") }}</span>
|
|
|
- </el-dropdown-item>
|
|
|
- </el-dropdown-menu>
|
|
|
- </template>
|
|
|
- </el-dropdown>
|
|
|
- </div>
|
|
|
+ <img v-if="tokenStatus" :src="'/img/jd-on.jpg'" style="width: 40px"/>
|
|
|
+ <img v-if="!tokenStatus" :src="'/img/jd-off.jpg'" style="width: 40px" @click="changeJdLoginModal"/>
|
|
|
+ </div>
|
|
|
+ <jdStatus v-model="jdLoginModal" :iframeUrl="jdLoginUrl"></jdStatus>
|
|
|
+ <div class="fr">
|
|
|
+ <!-- :value="12" -->
|
|
|
+ <el-badge
|
|
|
+ :value="badgeNum"
|
|
|
+ style="cursor: pointer"
|
|
|
+ class="badge"
|
|
|
+ @click="noticeTableModal = true"
|
|
|
+ >
|
|
|
+ <el-icon :size="20">
|
|
|
+ <BellFilled />
|
|
|
+ </el-icon>
|
|
|
+ </el-badge>
|
|
|
+ <notice
|
|
|
+ v-model="noticeTableModal"
|
|
|
+ @changeNum="(e) => (badgeNum = e)"
|
|
|
+ ></notice>
|
|
|
+ <el-dropdown
|
|
|
+ @command="handleCommand"
|
|
|
+ class="right-menu-item hover-effect"
|
|
|
+ trigger="click"
|
|
|
+ >
|
|
|
+ <div class="dropdown-box">
|
|
|
+ {{ userData }}
|
|
|
+ </div>
|
|
|
+ <template #dropdown>
|
|
|
+ <el-dropdown-menu>
|
|
|
+ <router-link to="/user/profile">
|
|
|
+ <el-dropdown-item>{{
|
|
|
+ $t("header.personalCenter")
|
|
|
+ }}</el-dropdown-item>
|
|
|
+ </router-link>
|
|
|
+ <el-dropdown-item command="setLayout">
|
|
|
+ <span>{{ $t("header.layoutSettings") }}</span>
|
|
|
+ </el-dropdown-item>
|
|
|
+ <el-dropdown-item divided command="logout">
|
|
|
+ <span>{{ $t("header.logout") }}</span>
|
|
|
+ </el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </template>
|
|
|
+ </el-dropdown>
|
|
|
+ </div>
|
|
|
</header>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -291,6 +299,8 @@ import { ElMessageBox, ElNotification, ElMessage } from "element-plus";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
import "@/components/headerBar/header.scss";
|
|
|
import notice from "@/components/notice/index";
|
|
|
+import jdStatus from "@/components/jdStatus/index";
|
|
|
+import {getToken} from "@/utils/auth";
|
|
|
const router = useRouter();
|
|
|
const userStore = useUserStore();
|
|
|
const { proxy } = getCurrentInstance();
|
|
@@ -304,6 +314,24 @@ const noticeTableModal = ref(false);
|
|
|
const userData = ref(Cookies.get("nickName") || "");
|
|
|
const commonsRouterList = ref([]);
|
|
|
const activeLeftData = ref({});
|
|
|
+let tokenStatus = ref(false);
|
|
|
+
|
|
|
+const jdLoginModal = ref(false);
|
|
|
+const jdLoginUrl = ref('');
|
|
|
+
|
|
|
+
|
|
|
+const changeJdLoginModal = () => {
|
|
|
+ getJd2LoginUrl();
|
|
|
+ jdLoginModal.value = true;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const getJd2LoginUrl = async () => {
|
|
|
+ proxy.get("/open/jd/build2LoginUrl").then((res) => {
|
|
|
+ jdLoginUrl.value = res.data;
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
const openLeftBaner = (i, index) => {
|
|
|
leftBanerType.value = 1;
|
|
|
activeLeftData.value = i;
|
|
@@ -466,9 +494,64 @@ function calcAutoListChidren() {
|
|
|
autoListChidrenNum.value = Math.floor((getBrowserWidth() - 616) / 120);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+const intervalId = ref(null);
|
|
|
+const scoket = ref(null);
|
|
|
+const socketInit = () => {
|
|
|
+ window.ws = new WebSocket(
|
|
|
+ "ws://" +
|
|
|
+ import.meta.env.VITE_APP_IP +
|
|
|
+ import.meta.env.VITE_APP_WS_API +
|
|
|
+ "/webStock/" +
|
|
|
+ getToken()
|
|
|
+ // 'ws://192.168.1.97:8300/webStock/' + window.localStorage.getItem('token')
|
|
|
+ );
|
|
|
+ //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
|
|
|
+ window.ws.onopen = function () {
|
|
|
+ //当WebSocket创建成功时,触发onopen事件
|
|
|
+ console.log("open");
|
|
|
+ scoket.value = window.ws;
|
|
|
+ //立马发送一次心跳
|
|
|
+ sendSocketMsg();
|
|
|
+ // 设置定时器,每30秒执行一次myFunction
|
|
|
+ intervalId.value = setInterval(sendSocketMsg, 15000);
|
|
|
+ };
|
|
|
+ window.ws.onmessage = function (e) {
|
|
|
+ //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
|
|
+ //在data.value前面插入
|
|
|
+ let jsonObj = JSON.parse(e.data);
|
|
|
+ if(jsonObj.cmd == "jdStatus"){
|
|
|
+ console.log(jsonObj.status);
|
|
|
+ tokenStatus.value = jsonObj.status;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ window.ws.onclose = function (e) {
|
|
|
+ //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
|
|
+ console.log("close");
|
|
|
+ if(intervalId.value) clearInterval(intervalId.value);
|
|
|
+ };
|
|
|
+ window.ws.onerror = function (e) {
|
|
|
+ //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
|
|
+ console.log("error");
|
|
|
+ if(intervalId.value) clearInterval(intervalId.value);
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+// 定义要执行的函数
|
|
|
+function sendSocketMsg() {
|
|
|
+ let jsonData = {
|
|
|
+ cmd: "jdStatus",
|
|
|
+ content: "heartbeat",
|
|
|
+ };
|
|
|
+ scoket.value.send(JSON.stringify(jsonData));
|
|
|
+ console.log('Timer executed!');
|
|
|
+}
|
|
|
+
|
|
|
//一维数组转tree
|
|
|
|
|
|
onMounted(() => {
|
|
|
+ getJd2LoginUrl();
|
|
|
calcAutoListChidren();
|
|
|
window.addEventListener("resize", calcAutoListChidren);
|
|
|
proxy.get("/getInfo").then((res) => {
|
|
@@ -500,6 +583,13 @@ onMounted(() => {
|
|
|
proxy.post("/sysUserMenu/list", { type: 1 }).then((res) => {
|
|
|
commonsRouterList.value = res;
|
|
|
});
|
|
|
+
|
|
|
+ socketInit();
|
|
|
+});
|
|
|
+
|
|
|
+// 在组件销毁时停止WebSocket
|
|
|
+onUnmounted(() => {
|
|
|
+ scoket.value.close();
|
|
|
});
|
|
|
</script>
|
|
|
|