Your Name 3 년 전
부모
커밋
3c353f33e2
6개의 변경된 파일90개의 추가작업 그리고 1개의 파일을 삭제
  1. 1
    0
      package.json
  2. 21
    1
      src/pages/login/index.vue
  3. 34
    0
      src/plugins/index.js
  4. 18
    0
      src/plugins/plugins/onNote.js
  5. 11
    0
      src/utils/cache.js
  6. 5
    0
      yarn.lock

+ 1
- 0
package.json 파일 보기

@@ -13,6 +13,7 @@
13 13
     "@zjxpcyc/vue-tiny-store": "^1.0.1",
14 14
     "ant-design-vue": "^3.2.4",
15 15
     "axios": "^0.27.2",
16
+    "crypto-js": "^4.1.1",
16 17
     "js-base64": "^3.7.2",
17 18
     "nprogress": "^0.2.0",
18 19
     "vue": "^3.2.25",

+ 21
- 1
src/pages/login/index.vue 파일 보기

@@ -14,6 +14,9 @@
14 14
         <a-form-item has-feedback label="Client Secret" name="client_secret">
15 15
           <a-input v-model:value="formData.client_secret"></a-input>
16 16
         </a-form-item>
17
+        <a-form-item has-feedback label="密钥" name="encrypt_secret">
18
+          <a-input v-model:value="formData.encrypt_secret"></a-input>
19
+        </a-form-item>
17 20
         <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
18 21
           <a-button type="primary" html-type="submit">登录</a-button>
19 22
         </a-form-item>
@@ -23,9 +26,10 @@
23 26
 </template>
24 27
 
25 28
 <script setup>
26
-import { reactive, ref } from 'vue'
29
+import { onMounted, reactive, ref } from 'vue'
27 30
 import { useRouter } from 'vue-router'
28 31
 import { useModel } from '@zjxpcyc/vue-tiny-store'
32
+import * as cache from '@/utils/cache'
29 33
 
30 34
 const router = useRouter()
31 35
 const { signIn } = useModel('user')
@@ -41,6 +45,7 @@ const rules = {
41 45
   password: [{ required: true, message: '请填写密码', trigger: 'blur' }],
42 46
   client_id: [{ required: true, message: '请填写client_id', trigger: 'blur' }],
43 47
   client_secret: [{ required: true, message: '请填写client_secret', trigger: 'blur' }],
48
+  encrypt_secret: [{ required: true, message: '请填写密钥', trigger: 'blur' }],
44 49
 }
45 50
 
46 51
 const formData = reactive({
@@ -49,15 +54,30 @@ const formData = reactive({
49 54
   password: undefined,
50 55
   client_id: undefined,
51 56
   client_secret: undefined,
57
+  encrypt_secret: undefined,
52 58
   scope: 'user_info projects pull_requests issues notes keys hook groups gists enterprises'
53 59
 })
54 60
 
55 61
 const submitForm = () => {
62
+  cache.set('loginfo', formData)
63
+
56 64
   signIn(formData).then(() => {
65
+    cache.set('encrypt_secret', formData.encrypt_secret)
57 66
     router.replace({ name: 'index' })
58 67
   })
59 68
 }
60 69
 
70
+onMounted(() => {
71
+  const cacheData = cache.get('loginfo')
72
+  if (cacheData) {
73
+    formData.username = cacheData.username
74
+    formData.password = cacheData.password
75
+    formData.client_id = cacheData.client_id
76
+    formData.client_secret = cacheData.client_secret
77
+    formData.encrypt_secret = cacheData.encrypt_secret
78
+  }
79
+})
80
+
61 81
 </script>
62 82
 
63 83
 <style lang="less" scoped>

+ 34
- 0
src/plugins/index.js 파일 보기

@@ -0,0 +1,34 @@
1
+import createEvent from '@zjxpcyc/js_event'
2
+const eventBus = createEvent();
3
+
4
+// from redux code
5
+function compose(...funcs) {
6
+  if (funcs.length === 0) {
7
+      return arg => arg
8
+  }
9
+
10
+  if (funcs.length === 1) {
11
+      return funcs[0]
12
+  }
13
+
14
+  return funcs.reduce((a, b) => (...args) => a(b(...args)))
15
+}
16
+
17
+function createPlugin(hookBus) {
18
+  const hooks = {};
19
+
20
+  const apply = (type, func) => {
21
+    let listeners = hooks[type] || []
22
+    listeners = listeners.filter(x => x !== func).concat(func)
23
+    hooks[type] = apply
24
+  }
25
+
26
+  const invoke = (type, ...args) => {
27
+    const listeners = hooks[type] || []
28
+    return compose(...listeners)(...args)
29
+  }
30
+
31
+  return { apply, invoke }
32
+}
33
+
34
+const plugins = createPlugin(eventBus)

+ 18
- 0
src/plugins/plugins/onNote.js 파일 보기

@@ -0,0 +1,18 @@
1
+import CryptoJS from 'crypto-js'
2
+import * as cache from '@/utils/cache'
3
+import plugins from '../index'
4
+
5
+
6
+plugins.apply('readNote', (rawNote) => {
7
+  const secretKey = cache.get('encrypt_secret')
8
+  if (!secretKey) return rawNote;
9
+
10
+  return CryptoJS.AES.decrypt(rawNote, secretKey).toString(CryptoJS.enc.Utf8)
11
+})
12
+
13
+plugins.apply('writeNote', (rawNote) => {
14
+  const secretKey = cache.get('encrypt_secret')
15
+  if (!secretKey) return rawNote;
16
+
17
+  return CryptoJS.AES.encrypt(rawNote, secretKey).toString()
18
+})

+ 11
- 0
src/utils/cache.js 파일 보기

@@ -0,0 +1,11 @@
1
+
2
+export const set = (k, v) => {
3
+  localStorage.setItem(k, JSON.stringify(v))
4
+}
5
+
6
+export const get = k => {
7
+  const val = localStorage.getItem(k)
8
+  if (!val) return;
9
+
10
+  return JSON.parse(val)
11
+}

+ 5
- 0
yarn.lock 파일 보기

@@ -313,6 +313,11 @@ core-js@^3.15.1:
313 313
   resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.22.7.tgz#8d6c37f630f6139b8732d10f2c114c3f1d00024f"
314 314
   integrity sha512-Jt8SReuDKVNZnZEzyEQT5eK6T2RRCXkfTq7Lo09kpm+fHjgGewSbNjV+Wt4yZMhPDdzz2x1ulI5z/w4nxpBseg==
315 315
 
316
+crypto-js@^4.1.1:
317
+  version "4.1.1"
318
+  resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
319
+  integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
320
+
316 321
 csstype@^2.6.8:
317 322
   version "2.6.20"
318 323
   resolved "https://registry.npmmirror.com/csstype/-/csstype-2.6.20.tgz#9229c65ea0b260cf4d3d997cb06288e36a8d6dda"