Browse Source

🐞 fix: 修复乐跑登录器无法使用的问题

Pchen. 10 months ago
parent
commit
6a5abd91d7
3 changed files with 122 additions and 2 deletions
  1. 1 1
      src/layout/default-layout.vue
  2. 100 0
      src/pages/openProxy/index.vue
  3. 21 1
      src/router/index.js

+ 1 - 1
src/layout/default-layout.vue

@@ -98,7 +98,7 @@ onUnmounted(() => {
   position: fixed;
   top: 0;
   left: 0;
-  z-index: 100;
+  z-index: 999;
   width: 100%;
   height: @nav-size-height;
 }

+ 100 - 0
src/pages/openProxy/index.vue

@@ -0,0 +1,100 @@
+<template>
+    <div class="container">
+        <Breadcrumb :items="['乐跑登录', '启动登录器']" />
+        <a-card title="启动乐跑登录器">
+            <a-result title="乐跑登录器未开启" subtitle="点击下方按钮开启登录器" v-if="!ready">
+                <template #extra>
+                    <a-space>
+                        <a-button type="primary" @click="openProxy" :loading="loading">开启登录器</a-button>
+                    </a-space>
+                </template>
+            </a-result>
+            <a-result status="success" title="启动命令已发送" subtitle="请根据下方输出进行操作" v-else>
+                <template #extra>
+                    <a-space>
+                        <a-button type='primary' @click="closeProxy" :loading="loading">关闭登录器</a-button>
+                    </a-space>
+                </template>
+            </a-result>
+            <div class="output" v-if="output.length > 0">
+                <div v-for="(item, index) in output">{{ item }}</div>
+            </div>
+        </a-card>
+    </div>
+
+</template>
+
+<script setup>
+import { ref } from 'vue'
+
+const ready = ref(false)
+const loading = ref(false)
+const output = ref([])
+
+const openProxy = async () => {
+    try {
+        loading.value = true
+        const result = await window.electron.openProxy()
+        loading.value = false
+        ready.value = true
+
+        let msg = `[系统消息] ${result}`
+        if (msg !== output.value[output.value.length - 1])
+            output.value.push(msg)
+
+        window.electron.onProcessOutput(data => {
+            console.log(data)
+            if (data.includes('>>>')) {
+                const parts = data.split('>>>');
+
+                for (let i = 1; i < parts.length; i++) {
+                    const part = parts[i].trim();
+                    if (part && part !== output.value[output.value.length - 1])
+                        output.value.push(part)
+
+                }
+            }
+        })
+
+        window.electron.onProcessClose(data => {
+            let msg = `[系统消息] 乐跑登录器已停止运行`
+            if (output.value[output.value.length - 1] !== msg)
+                output.value.push(msg)
+        })
+
+        window.electron.onProcessError(data => {
+            let msg = `[系统消息] 乐跑登录器启动时出错:${data}`
+            if (output.value[output.value.length - 1] !== msg)
+                output.value.push(msg)
+        })
+    } catch (error) {
+        let msg = `[系统消息] 开启乐跑登录器失败!请确保没有任何程序阻止登录器启动。若有疑问请提交工单联系客服`
+        if (output.value[output.value.length - 1] !== msg)
+            output.value.push(msg)
+    } finally {
+        loading.value = false
+    }
+}
+
+const closeProxy = async () => {
+    loading.value = true
+    await window.electron.killProcess()
+    output.value.push(`[系统消息] 乐跑登录器关闭命令已发送`)
+    ready.value = false
+    loading.value = false
+}
+
+</script>
+
+<style scoped>
+.container {
+    padding: 0 20px 20px 20px;
+}
+
+.output {
+    margin: 10px;
+    padding: 10px;
+    min-height: 300px;
+    background-color: rgba(136, 136, 136, 0.2);
+}
+</style>

+ 21 - 1
src/router/index.js

@@ -24,6 +24,26 @@ const routes = [
             hideInMenu: true
         }
     },
+    {
+        path: "/proxy",
+        name: "proxy",
+        component: DEFAULT_LAYOUT,
+        meta: {
+            title: '乐跑登录',
+            icon: 'icon-command',
+            onlyElectron: true
+        },
+        children: [
+            {
+                path: 'openProxy',
+                name: 'proxy.openProxy',
+                component: () => import('../pages/openProxy/index.vue'),
+                meta: {
+                    title: '启动登录器'
+                }
+            }
+        ]
+    },
     {
         path: "/htmlView",
         name: "htmlView",
@@ -314,7 +334,7 @@ router.beforeEach(async (to, from, next) => {
 
     if (to.meta && (to.meta.onlyWeb || to.meta.onlyElectron)) {
         const electronEnv = isElectron()
-        if (to.meta.onlyWeb && electronEnv) return next('/lepao/accountList')
+        if (to.meta.onlyWeb && electronEnv) return next('/proxy/openProxy')
         if (to.meta.onlyElectron && !electronEnv) return next('/lepao/accountList')
     }