Pārlūkot izejas kodu

autolaunch front

gaoshuaixing 5 gadi atpakaļ
vecāks
revīzija
95e2380eeb

+ 6 - 2
app/controller/v1/setting.js

@@ -6,18 +6,22 @@ class SettingController extends BaseController {
 
   async autoLaunchEnable() {
     const { service } = this;
-    const data = {};
 
     await service.setting.autoLaunchEnable();
+    const data = {
+      isEnabled: true
+    };
 
     this.sendSuccess(data);
   }
   
   async autoLaunchDisable() {
     const { service } = this;
-    const data = {};
     
     await service.setting.autoLaunchDisable();
+    const data = {
+      isEnabled: false
+    };
 
     this.sendSuccess(data);
   }

+ 0 - 20
electron/lib/AutoLaunch.js

@@ -12,37 +12,17 @@ class AutoLaunch {
       openAtLogin: true
     })
     return true;
-    // return new Promise((resolve, reject) => {
-    //   const enabled = app.getLoginItemSettings(LOGIN_SETTING_OPTIONS).openAtLogin
-    //   if (enabled) {
-    //     resolve()
-    //   }
-
-    //   app.setLoginItemSettings({
-    //     ...LOGIN_SETTING_OPTIONS,
-    //     openAtLogin: true
-    //   })
-    //   resolve()
-    // })
   }
   
   disable () {
     app.setLoginItemSettings({ openAtLogin: false })
     return true;
-    // return new Promise((resolve, reject) => {
-    //   app.setLoginItemSettings({ openAtLogin: false })
-    //   resolve()
-    // })
   }
 
   isEnabled () {
     const enabled = app.getLoginItemSettings(LOGIN_SETTING_OPTIONS).openAtLogin;
     console.log('AutoLaunch isEnabled:', enabled);
     return enabled;
-    // return new Promise((resolve, reject) => {
-    //   const enabled = app.getLoginItemSettings(LOGIN_SETTING_OPTIONS).openAtLogin
-    //   resolve(enabled)
-    // })
   }
 }
 

+ 1 - 1
frontend/.env

@@ -1,3 +1,3 @@
 NODE_ENV=production
 VUE_APP_PREVIEW=false
-VUE_APP_API_BASE_URL=api
+VUE_APP_API_BASE_URL=

+ 1 - 1
frontend/.env.development

@@ -1,3 +1,3 @@
 NODE_ENV=development
 VUE_APP_PREVIEW=true
-VUE_APP_API_BASE_URL=http://localhost:7068/api
+VUE_APP_API_BASE_URL=http://localhost:7068

+ 1 - 1
frontend/.env.preview

@@ -1,3 +1,3 @@
 NODE_ENV=production
 VUE_APP_PREVIEW=true
-VUE_APP_API_BASE_URL=http://localhost:7068/api
+VUE_APP_API_BASE_URL=http://localhost:7068

+ 39 - 3
frontend/src/api/main.js

@@ -2,9 +2,12 @@ import request from '@/utils/request'
 // import storage from 'store'
 
 const mainApi = {
-  outApi: '/v1/outApi',
-  openDir: '/v1/example/openLocalDir',
-  uploadFile: '/v1/example/uploadFile',
+  outApi: '/api/v1/outApi',
+  openDir: '/api/v1/example/openLocalDir',
+  uploadFile: '/api/v1/example/uploadFile',
+  autoLaunchEnable: '/api/v1/setting/autoLaunchEnable',
+  autoLaunchDisable: '/api/v1/setting/autoLaunchDisable',
+  autoLaunchIsEnabled: '/api/v1/setting/autoLaunchIsEnabled'
 }
 
 /**
@@ -40,4 +43,37 @@ export function uploadFile (parameter) {
     method: 'post',
     data: parameter
   })
+}
+
+/**
+ * autoLaunchEnable
+ */
+export function autoLaunchEnable (parameter) {
+  return request({
+    url: mainApi.autoLaunchEnable,
+    method: 'post',
+    data: parameter
+  })
+}
+
+/**
+ * autoLaunchDisable
+ */
+export function autoLaunchDisable (parameter) {
+  return request({
+    url: mainApi.autoLaunchDisable,
+    method: 'post',
+    data: parameter
+  })
+}
+
+/**
+ * autoLaunchIsEnabled
+ */
+export function autoLaunchIsEnabled (parameter) {
+  return request({
+    url: mainApi.autoLaunchIsEnabled,
+    method: 'post',
+    data: parameter
+  })
 }

+ 4 - 9
frontend/src/config/router.config.js

@@ -18,15 +18,10 @@ export const constantRouterMap = [
         component: () => import('@/views/file/UploadFile')
       },
       {
-        path: 'setting1',
-        name: 'setting1',
-        component: { template: '<div><h1>这是设置内一</h1></div>' }
-      },
-      {
-        path: 'setting2',
-        name: 'setting2',
-        component: { template: '<div><h1>这是设置内二</h1></div>' }
-      },
+        path: 'setting',
+        name: 'setting',
+        component: () => import('@/views/Setting')
+      }
     ]
   }
 ]

+ 0 - 32
frontend/src/views/Contenta.vue

@@ -1,32 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>这是首页内一</h1>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 0 - 32
frontend/src/views/Contentb.vue

@@ -1,32 +0,0 @@
-<template>
-  <div class="hello">
-    <h1>这是首页内二</h1>
-  </div>
-</template>
-
-<script>
-export default {
-  name: 'HelloWorld',
-  props: {
-    msg: String
-  }
-}
-</script>
-
-<!-- Add "scoped" attribute to limit CSS to this component only -->
-<style scoped>
-h3 {
-  margin: 40px 0 0;
-}
-ul {
-  list-style-type: none;
-  padding: 0;
-}
-li {
-  display: inline-block;
-  margin: 0 10px;
-}
-a {
-  color: #42b983;
-}
-</style>

+ 3 - 7
frontend/src/views/Layout.vue

@@ -65,13 +65,9 @@ export default {
         },
         'menu_2' : {
           'subMenu_1' : {
-            title: '设置菜单1',
-            page: '/setting1'
-          },
-          'subMenu_2' : {
-            title: '设置菜单2',
-            page: '/setting2'
-          },
+            title: '基础设置',
+            page: '/setting'
+          }
         },
       },
       contentPage: ''

+ 77 - 0
frontend/src/views/Setting.vue

@@ -0,0 +1,77 @@
+<template>
+  <a-list id="set" itemLayout="horizontal">
+    <a-list-item style="text-align: left;">
+      <a-list-item-meta>
+        <template v-slot:title>
+          <a>启动</a>
+        </template>
+        <template v-slot:description>
+          <span>
+            开机自动启动
+          </span>
+        </template>
+      </a-list-item-meta>
+      <template v-slot:actions>
+        <a-switch checkedChildren="开" unCheckedChildren="关" v-model="autoLaunchChecked" @change="autoLaunchChange(autoLaunchChecked)" />
+      </template>
+    </a-list-item>
+  </a-list>
+</template>
+<script>
+import { autoLaunchEnable, autoLaunchDisable, autoLaunchIsEnabled } from '@/api/main'
+
+export default {
+  data () {
+    return {
+      autoLaunchChecked: false
+    }
+  },
+  mounted () {
+    this.autoLaunchInit()
+  },
+  methods: {
+    autoLaunchInit () {
+      autoLaunchIsEnabled({}).then(res => {
+        if (res.code !== 0) {
+          return false
+        }
+        this.autoLaunchChecked = res.data.isEnabled;
+      }).catch(err => {
+        console.log('err:', err)
+      })
+    },
+    autoLaunchChange (checkStatus) {
+      const params = {
+        'checkStatus': checkStatus
+      }
+      if (checkStatus) {
+        autoLaunchEnable(params).then(res => {
+          if (res.code !== 0) {
+            return false
+          }
+          this.autoLaunchChecked = res.data.isEnabled;
+        }).catch(err => {
+          console.log('err:', err)
+        })
+      } else {
+        autoLaunchDisable(params).then(res => {
+          if (res.code !== 0) {
+            return false
+          }
+          this.autoLaunchChecked = res.data.isEnabled;
+        }).catch(err => {
+          console.log('err:', err)
+        })        
+      }
+    },
+  }
+}
+</script>
+<style lang="less" scoped>
+// 嵌套
+#set {
+  .ant-list-item:last-child {
+    border-bottom: 1px solid #e8e8e8;
+  }
+}  
+</style>  

+ 1 - 1
frontend/src/views/file/UploadFile.vue

@@ -44,7 +44,7 @@
 export default {
   data() {
     return {
-      action_url: process.env.VUE_APP_API_BASE_URL + '/v1/example/uploadFile',
+      action_url: process.env.VUE_APP_API_BASE_URL + '/api/v1/example/uploadFile',
       image_info: [],
       num: 0
     };