Browse Source

Split my and admin

lejianwen 1 year ago
parent
commit
8ecfe9cbd0

+ 0 - 7
src/api/address_book.js

@@ -61,10 +61,3 @@ export function batchCreateFromPeers (data) {
61 61
   })
62 62
 }
63 63
 
64
-export function batchUpdateTags (data) {
65
-  return request({
66
-    url: '/address_book/batchUpdateTags',
67
-    method: 'post',
68
-    data,
69
-  })
70
-}

+ 0 - 39
src/api/my.js

@@ -1,39 +0,0 @@
1
-import request from '@/utils/request'
2
-
3
-export function share_record_list (params) {
4
-  return request({
5
-    url: '/my/share_record/list',
6
-    params,
7
-  })
8
-}
9
-
10
-export function share_record_remove (data) {
11
-  return request({
12
-    url: '/my/share_record/delete',
13
-    method: 'post',
14
-    data,
15
-  })
16
-}
17
-
18
-export function share_record_batchDelete (data) {
19
-  return request({
20
-    url: '/my/share_record/batchDelete',
21
-    method: 'post',
22
-    data,
23
-  })
24
-}
25
-
26
-export function peer_list (params) {
27
-  return request({
28
-    url: '/my/peer/list',
29
-    params,
30
-  })
31
-}
32
-
33
-export function address_book_batchCreateFromPeers (data) {
34
-  return request({
35
-    url: '/my/address_book/batchCreateFromPeers',
36
-    method: 'post',
37
-    data,
38
-  })
39
-}

+ 48 - 0
src/api/my/address_book.js

@@ -0,0 +1,48 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/address_book/list',
6
+    params,
7
+  })
8
+}
9
+
10
+export function batchCreateFromPeers (data) {
11
+  return request({
12
+    url: '/my/address_book/batchCreateFromPeers',
13
+    method: 'post',
14
+    data,
15
+  })
16
+}
17
+
18
+export function batchUpdateTags (data) {
19
+  return request({
20
+    url: '/my/address_book/batchUpdateTags',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}
25
+
26
+export function create (data) {
27
+  return request({
28
+    url: '/my/address_book/create',
29
+    method: 'post',
30
+    data,
31
+  })
32
+}
33
+
34
+export function update (data) {
35
+  return request({
36
+    url: '/my/address_book/update',
37
+    method: 'post',
38
+    data,
39
+  })
40
+}
41
+
42
+export function remove (data) {
43
+  return request({
44
+    url: '/my/address_book/delete',
45
+    method: 'post',
46
+    data,
47
+  })
48
+}

+ 33 - 0
src/api/my/address_book_collection.js

@@ -0,0 +1,33 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/address_book_collection/list',
6
+    params,
7
+  })
8
+}
9
+
10
+export function create (data) {
11
+  return request({
12
+    url: '/my/address_book_collection/create',
13
+    method: 'post',
14
+    data,
15
+  })
16
+}
17
+
18
+export function update (data) {
19
+  return request({
20
+    url: '/my/address_book_collection/update',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}
25
+
26
+export function remove (data) {
27
+  return request({
28
+    url: '/my/address_book_collection/delete',
29
+    method: 'post',
30
+    data,
31
+  })
32
+}
33
+

+ 40 - 0
src/api/my/address_book_collection_rule.js

@@ -0,0 +1,40 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/address_book_collection_rule/list',
6
+    params,
7
+  })
8
+}
9
+
10
+export function create (data) {
11
+  return request({
12
+    url: '/my/address_book_collection_rule/create',
13
+    method: 'post',
14
+    data,
15
+  })
16
+}
17
+
18
+export function update (data) {
19
+  return request({
20
+    url: '/my/address_book_collection_rule/update',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}
25
+
26
+export function remove (data) {
27
+  return request({
28
+    url: '/my/address_book_collection_rule/delete',
29
+    method: 'post',
30
+    data,
31
+  })
32
+}
33
+
34
+export function batchCreate (data) {
35
+  return request({
36
+    url: '/my/address_book_collection_rule/batchCreate',
37
+    method: 'post',
38
+    data,
39
+  })
40
+}

+ 8 - 0
src/api/my/peer.js

@@ -0,0 +1,8 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/peer/list',
6
+    params,
7
+  })
8
+}

+ 24 - 0
src/api/my/share_record.js

@@ -0,0 +1,24 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/share_record/list',
6
+    params,
7
+  })
8
+}
9
+
10
+export function remove (data) {
11
+  return request({
12
+    url: '/my/share_record/delete',
13
+    method: 'post',
14
+    data,
15
+  })
16
+}
17
+
18
+export function batchDelete (data) {
19
+  return request({
20
+    url: '/my/share_record/batchDelete',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}

+ 33 - 0
src/api/my/tag.js

@@ -0,0 +1,33 @@
1
+import request from '@/utils/request'
2
+
3
+export function list (params) {
4
+  return request({
5
+    url: '/my/tag/list',
6
+    params,
7
+  })
8
+}
9
+
10
+export function create (data) {
11
+  return request({
12
+    url: '/my/tag/create',
13
+    method: 'post',
14
+    data,
15
+  })
16
+}
17
+
18
+export function update (data) {
19
+  return request({
20
+    url: '/my/tag/update',
21
+    method: 'post',
22
+    data,
23
+  })
24
+}
25
+
26
+export function remove (data) {
27
+  return request({
28
+    url: '/my/tag/delete',
29
+    method: 'post',
30
+    data,
31
+  })
32
+}
33
+

+ 1 - 0
src/components/icons/platform.vue

@@ -17,6 +17,7 @@
17 17
     name: {
18 18
       type: String,
19 19
       required: true,
20
+      default: '',
20 21
       values: ['windows', 'android', 'mac', 'linux'],
21 22
     },
22 23
     color: {

+ 11 - 6
src/views/address_book/collection.js

@@ -1,23 +1,28 @@
1 1
 import { reactive, ref } from 'vue'
2
-import { create, list, remove, update } from '@/api/address_book_collection'
2
+import { list as admin_list, create as admin_create, update as admin_update, remove as admin_remove } from '@/api/address_book_collection'
3
+import { list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book_collection'
3 4
 import { ElMessage, ElMessageBox } from 'element-plus'
4 5
 import { T } from '@/utils/i18n'
5 6
 
6
-export function useRepositories (is_my) {
7
+const apis = {
8
+  admin: { list: admin_list, remove: admin_remove, update: admin_update, create: admin_create },
9
+  my: { list: my_list, remove: my_remove, create: my_create, update: my_update },
10
+}
11
+
12
+export function useRepositories (api_type = 'my') {
7 13
   const listRes = reactive({
8 14
     list: [], total: 0, loading: false,
9 15
   })
10 16
   const listQuery = reactive({
11 17
     page: 1,
12 18
     page_size: 10,
13
-    is_my,
14 19
     name: null,
15 20
     user_id: null,
16 21
   })
17 22
 
18 23
   const getList = async () => {
19 24
     listRes.loading = true
20
-    const res = await list(listQuery).catch(_ => false)
25
+    const res = await apis[api_type].list(listQuery).catch(_ => false)
21 26
     listRes.loading = false
22 27
     if (res) {
23 28
       listRes.list = res.data.list
@@ -42,7 +47,7 @@ export function useRepositories (is_my) {
42 47
       return false
43 48
     }
44 49
 
45
-    const res = await remove({ id: row.id }).catch(_ => false)
50
+    const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
46 51
     if (res) {
47 52
       ElMessage.success(T('OperationSuccess'))
48 53
       getList()
@@ -72,7 +77,7 @@ export function useRepositories (is_my) {
72 77
 
73 78
   }
74 79
   const submit = async () => {
75
-    const api = formData.id ? update : create
80
+    const api = formData.id ? apis[api_type].update : apis[api_type].create
76 81
     const res = await api(formData).catch(_ => false)
77 82
     if (res) {
78 83
       ElMessage.success(T('OperationSuccess'))

+ 1 - 1
src/views/address_book/collection.vue

@@ -96,7 +96,7 @@
96 96
     toEdit,
97 97
     toAdd,
98 98
     submit,
99
-  } = useRepositories()
99
+  } = useRepositories('admin')
100 100
 
101 101
   listQuery.is_my = 0
102 102
 

+ 45 - 51
src/views/address_book/index.js

@@ -1,28 +1,24 @@
1 1
 import { reactive, ref } from 'vue'
2
-import { batchUpdateTags, create, list, remove, update } from '@/api/address_book'
2
+import { create as admin_create, list as admin_list, remove as admin_remove, update as admin_update } from '@/api/address_book'
3
+import { batchUpdateTags, list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book'
3 4
 import { ElMessage, ElMessageBox } from 'element-plus'
4 5
 import { T } from '@/utils/i18n'
5 6
 import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
6 7
 import { useRepositories as useTagRepositories } from '@/views/tag/index'
7
-import { loadAllUsers } from '@/global'
8 8
 import { simpleData } from '@/api/peer'
9 9
 
10
-export function useRepositories (is_my = 0) {
11
-
12
-  const { allUsers, getAllUsers } = loadAllUsers()
10
+const apis = {
11
+  admin: { list: admin_list, remove: admin_remove, update: admin_update, create: admin_create },
12
+  my: { list: my_list, remove: my_remove, create: my_create, update: my_update },
13
+}
13 14
 
15
+export function useRepositories (api_type = 'my') {
14 16
   const {
15 17
     listRes: collectionListRes,
16 18
     listQuery: collectionListQuery,
17 19
     getList: getCollectionList,
18
-  } = useCollectionRepositories(is_my)
20
+  } = useCollectionRepositories(api_type)
19 21
   collectionListQuery.page_size = 9999
20
-  const {
21
-    listRes: tagListRes,
22
-    listQuery: tagListQuery,
23
-    getList: getTagList,
24
-  } = useTagRepositories(is_my)
25
-  tagListQuery.page_size = 9999
26 22
 
27 23
   const listRes = reactive({
28 24
     list: [], total: 0, loading: false,
@@ -30,7 +26,6 @@ export function useRepositories (is_my = 0) {
30 26
   const listQuery = reactive({
31 27
     page: 1,
32 28
     page_size: 10,
33
-    is_my,
34 29
     id: null,
35 30
     user_id: null,
36 31
     username: null,
@@ -40,7 +35,7 @@ export function useRepositories (is_my = 0) {
40 35
 
41 36
   const getList = async () => {
42 37
     listRes.loading = true
43
-    const res = await list(listQuery).catch(_ => false)
38
+    const res = await apis[api_type].list(listQuery).catch(_ => false)
44 39
     listRes.loading = false
45 40
     if (res) {
46 41
       const ids = res.data.list.map(item => item.id)
@@ -78,13 +73,14 @@ export function useRepositories (is_my = 0) {
78 73
       return false
79 74
     }
80 75
 
81
-    const res = await remove({ row_id: row.row_id }).catch(_ => false)
76
+    const res = await apis[api_type].remove({ row_id: row.row_id }).catch(_ => false)
82 77
     if (res) {
83 78
       ElMessage.success(T('OperationSuccess'))
84 79
       getList()
85 80
     }
86 81
   }
87 82
 
83
+  //创建或者修改
88 84
   const platformList = [
89 85
     { label: 'Windows', value: 'Windows', icon: 'windows' },
90 86
     { label: 'Linux', value: 'Linux', icon: 'linux' },
@@ -112,6 +108,18 @@ export function useRepositories (is_my = 0) {
112 108
     'username': '',
113 109
     collection_id: null,
114 110
   })
111
+  const {
112
+    listRes: collectionListResForUpdate,
113
+    listQuery: collectionListQueryForUpdate,
114
+    getList: getCollectionListForUpdate,
115
+  } = useCollectionRepositories(api_type)
116
+  collectionListQueryForUpdate.page_size = 9999
117
+  const {
118
+    listRes: tagListRes,
119
+    listQuery: tagListQuery,
120
+    getList: getTagList,
121
+  } = useTagRepositories(api_type)
122
+  tagListQuery.page_size = 9999
115 123
 
116 124
   const toEdit = (row) => {
117 125
     formVisible.value = true
@@ -119,9 +127,9 @@ export function useRepositories (is_my = 0) {
119 127
     Object.keys(formData).forEach(key => {
120 128
       formData[key] = row[key]
121 129
     })
122
-    collectionListQuery.user_id = row.user_id
123
-    getCollectionList()
130
+    collectionListQueryForUpdate.user_id = row.user_id
124 131
     tagListQuery.collection_id = row.collection_id
132
+    getCollectionListForUpdate()
125 133
     getTagList()
126 134
 
127 135
   }
@@ -147,7 +155,7 @@ export function useRepositories (is_my = 0) {
147 155
 
148 156
   }
149 157
   const submit = async () => {
150
-    const api = formData.row_id ? update : create
158
+    const api = formData.row_id ? apis[api_type].update : apis[api_type].create
151 159
     const res = await api(formData).catch(_ => false)
152 160
     if (res) {
153 161
       ElMessage.success(T('OperationSuccess'))
@@ -155,16 +163,6 @@ export function useRepositories (is_my = 0) {
155 163
       getList()
156 164
     }
157 165
   }
158
-  const shareToWebClientVisible = ref(false)
159
-  const shareToWebClientForm = reactive({
160
-    id: '',
161
-    hash: '',
162
-  })
163
-  const toShowShare = (row) => {
164
-    shareToWebClientForm.id = row.id
165
-    shareToWebClientForm.hash = row.hash
166
-    shareToWebClientVisible.value = true
167
-  }
168 166
 
169 167
   const changeQueryUser = async (val) => {
170 168
     tagListRes.list = []
@@ -176,18 +174,18 @@ export function useRepositories (is_my = 0) {
176 174
       getCollectionList()
177 175
     }
178 176
   }
179
-  const changeUser = async (val) => {
177
+  const changeUserForUpdate = async (val) => {
180 178
     tagListRes.list = []
181 179
     formData.tags = []
182 180
     formData.collection_id = 0
183 181
     if (!val) {
184
-      collectionListRes.list = []
182
+      collectionListResForUpdate.list = []
185 183
     } else {
186
-      collectionListQuery.user_id = val
187
-      getCollectionList()
184
+      collectionListQueryForUpdate.user_id = val
185
+      getCollectionListForUpdate()
188 186
     }
189 187
   }
190
-  const changeCollection = async (val) => {
188
+  const changeCollectionForUpdate = async (val) => {
191 189
     tagListRes.list = []
192 190
     formData.tags = []
193 191
     tagListQuery.user_id = formData.user_id
@@ -217,42 +215,38 @@ export function useRepositories (is_my = 0) {
217 215
     listQuery,
218 216
     getList,
219 217
     handlerQuery,
220
-    del,
218
+    collectionListQuery,
219
+    getCollectionList,
220
+    collectionListRes,
221
+    changeQueryUser,
222
+
221 223
     platformList,
224
+
225
+    del,
226
+
222 227
     formVisible,
223 228
     formData,
224 229
     toEdit,
225 230
     toAdd,
226 231
     submit,
227
-    shareToWebClientVisible,
228
-    shareToWebClientForm,
229
-    toShowShare,
230
-
231
-    collectionListQuery,
232
-    getCollectionList,
233
-    collectionListRes,
234
-
232
+    getCollectionListForUpdate,
233
+    collectionListResForUpdate,
234
+    changeUserForUpdate,
235
+    changeCollectionForUpdate,
235 236
     tagListQuery,
236 237
     getTagList,
237 238
     tagListRes,
238 239
 
239
-    allUsers,
240
-    getAllUsers,
241
-
242
-    changeQueryUser,
243
-    changeUser,
244
-    changeCollection,
245
-
246 240
     fromPeer,
247 241
   }
248 242
 }
249 243
 
250
-export function useBatchUpdateTagsRepositories (is_my = 0) {
244
+export function useBatchUpdateTagsRepositories () {
251 245
   const {
252 246
     listRes: tagListRes,
253 247
     listQuery: tagListQuery,
254 248
     getList: getTagList,
255
-  } = useTagRepositories(is_my)
249
+  } = useTagRepositories('my')
256 250
   tagListQuery.page_size = 9999
257 251
 
258 252
   const visible = ref(false)

+ 13 - 19
src/views/address_book/index.vue

@@ -89,7 +89,7 @@
89 89
     <el-dialog v-model="formVisible" width="800" :title="!formData.row_id?T('Create') :T('Update') ">
90 90
       <el-form class="dialog-form" ref="form" :model="formData" label-width="120px">
91 91
         <el-form-item :label="T('Owner')" prop="user_id" required>
92
-          <el-select v-model="formData.user_id" @change="changeUser">
92
+          <el-select v-model="formData.user_id" @change="changeUserForUpdate">
93 93
             <el-option
94 94
                 v-for="item in allUsers"
95 95
                 :key="item.id"
@@ -99,9 +99,9 @@
99 99
           </el-select>
100 100
         </el-form-item>
101 101
         <el-form-item :label="T('AddressBookName')">
102
-          <el-select v-model="formData.collection_id" clearable @change="changeCollection">
102
+          <el-select v-model="formData.collection_id" clearable @change="changeCollectionForUpdate">
103 103
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
104
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
104
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
105 105
           </el-select>
106 106
         </el-form-item>
107 107
         <el-form-item label="ID" prop="id" required>
@@ -162,7 +162,6 @@
162 162
                 <el-switch v-model="formData.sameServer"></el-switch>
163 163
               </el-form-item>-->
164 164
 
165
-
166 165
         <el-form-item>
167 166
           <el-button @click="formVisible = false">{{ T('Cancel') }}</el-button>
168 167
           <el-button @click="submit" type="primary">{{ T('Submit') }}</el-button>
@@ -179,9 +178,9 @@
179 178
 </template>
180 179
 
181 180
 <script setup>
182
-  import { onActivated, onMounted, reactive, ref, watch } from 'vue'
181
+  import { onActivated, onMounted, watch } from 'vue'
183 182
   import { useRepositories } from '@/views/address_book/index'
184
-  import { toWebClientLink, getPeerSlat } from '@/utils/webclient'
183
+  import { toWebClientLink } from '@/utils/webclient'
185 184
   import { T } from '@/utils/i18n'
186 185
   import { useRoute } from 'vue-router'
187 186
   import { connectByClient } from '@/utils/peer'
@@ -189,18 +188,19 @@
189 188
   import { handleClipboard } from '@/utils/clipboard'
190 189
   import { CopyDocument } from '@element-plus/icons'
191 190
   import PlatformIcons from '@/components/icons/platform.vue'
192
-
193
-
191
+  import { loadAllUsers } from '@/global'
194 192
 
195 193
   const appStore = useAppStore()
196 194
   const route = useRoute()
197
-
195
+  const { allUsers, getAllUsers } = loadAllUsers()
198 196
 
199 197
   const {
200 198
     listRes,
201 199
     listQuery,
202 200
     getList,
203 201
     handlerQuery,
202
+    collectionListRes,
203
+
204 204
     del,
205 205
     formVisible,
206 206
     platformList,
@@ -208,19 +208,13 @@
208 208
     toEdit,
209 209
     toAdd,
210 210
     submit,
211
-    // shareToWebClientVisible,
212
-    // shareToWebClientForm,
213
-    // toShowShare,
214
-    collectionListRes,
215
-
211
+    changeUserForUpdate,
212
+    changeCollectionForUpdate,
213
+    collectionListResForUpdate,
216 214
     tagListRes,
217 215
 
218
-    allUsers, getAllUsers,
219
-
220 216
     changeQueryUser,
221
-    changeUser,
222
-    changeCollection
223
-  } = useRepositories()
217
+  } = useRepositories('admin')
224 218
 
225 219
   if (route.query?.user_id) {
226 220
     listQuery.user_id = parseInt(route.query.user_id)

+ 11 - 7
src/views/address_book/rule.js

@@ -1,11 +1,16 @@
1 1
 import { computed, reactive, ref } from 'vue'
2
-import { create, list, remove, update } from '@/api/address_book_collection_rule'
2
+import { list as admin_list, create as admin_create, update as admin_update, remove as admin_remove } from '@/api/address_book_collection_rule'
3
+import { list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book_collection_rule'
3 4
 import { groupUsers } from '@/api/user'
4 5
 import { ElMessage, ElMessageBox } from 'element-plus'
5 6
 import { T } from '@/utils/i18n'
6
-import collection from '@element-plus/icons/lib/Collection'
7 7
 
8
-export function useRepositories (is_my) {
8
+const apis = {
9
+  admin: { list: admin_list, remove: admin_remove, update: admin_update, create: admin_create },
10
+  my: { list: my_list, remove: my_remove, create: my_create, update: my_update },
11
+}
12
+
13
+export function useRepositories (api_type = 'my') {
9 14
   const listRes = reactive({
10 15
     list: [], total: 0, loading: false,
11 16
   })
@@ -13,12 +18,11 @@ export function useRepositories (is_my) {
13 18
     page: 1,
14 19
     page_size: 10,
15 20
     collection_id: null,
16
-    is_my,
17 21
   })
18 22
 
19 23
   const getList = async () => {
20 24
     listRes.loading = true
21
-    const res = await list(listQuery).catch(_ => false)
25
+    const res = await apis[api_type].list(listQuery).catch(_ => false)
22 26
     listRes.loading = false
23 27
     if (res) {
24 28
       listRes.list = res.data.list
@@ -43,7 +47,7 @@ export function useRepositories (is_my) {
43 47
       return false
44 48
     }
45 49
 
46
-    const res = await remove({ id: row.id }).catch(_ => false)
50
+    const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
47 51
     if (res) {
48 52
       ElMessage.success(T('OperationSuccess'))
49 53
       getList()
@@ -79,7 +83,7 @@ export function useRepositories (is_my) {
79 83
 
80 84
   }
81 85
   const submit = async () => {
82
-    const api = formData.id ? update : create
86
+    const api = formData.id ? apis[api_type].update : apis[api_type].create
83 87
     const res = await api(formData).catch(_ => false)
84 88
     if (res) {
85 89
       ElMessage.success(T('OperationSuccess'))

+ 2 - 2
src/views/address_book/rule.vue

@@ -56,7 +56,7 @@
56 56
           </el-radio-group>
57 57
         </el-form-item>
58 58
         <el-form-item :label="T('ShareTo')" prop="to_id" required>
59
-<!--          <el-input-number v-model="formData.to_id"></el-input-number>-->
59
+          <!--          <el-input-number v-model="formData.to_id"></el-input-number>-->
60 60
           <el-select v-model="formData.to_id">
61 61
             <el-option
62 62
                 v-for="item in groupUsersList"
@@ -106,7 +106,7 @@
106 106
     rules,
107 107
     groupUsersList,
108 108
     getGroupUsers,
109
-  } = useRepositories(props.is_my)
109
+  } = useRepositories(props.is_my ? 'my' : 'admin')
110 110
 
111 111
   formData.collection_id = props.collection.id
112 112
   formData.user_id = props.collection.user_id

+ 1 - 1
src/views/my/address_book/collection.vue

@@ -71,7 +71,7 @@
71 71
     toEdit,
72 72
     toAdd,
73 73
     submit,
74
-  } = useRepositories(1)
74
+  } = useRepositories('my')
75 75
 
76 76
   onMounted(getList)
77 77
 

+ 25 - 14
src/views/my/address_book/index.vue

@@ -76,9 +76,9 @@
76 76
     <el-dialog v-model="formVisible" width="800" :title="!formData.row_id?T('Create') :T('Update') ">
77 77
       <el-form class="dialog-form" ref="form" :model="formData" label-width="120px">
78 78
         <el-form-item :label="T('AddressBookName')" required prop="collection_id">
79
-          <el-select v-model="formData.collection_id" clearable @change="changeCollection">
79
+          <el-select v-model="formData.collection_id" clearable @change="changeCollectionForUpdate">
80 80
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
81
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
81
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
82 82
           </el-select>
83 83
         </el-form-item>
84 84
         <el-form-item label="ID" prop="id" required>
@@ -174,7 +174,7 @@
174 174
 </template>
175 175
 
176 176
 <script setup>
177
-  import { onActivated, onMounted, ref, watch } from 'vue'
177
+  import { onActivated, onMounted, reactive, ref, watch } from 'vue'
178 178
   import { useBatchUpdateTagsRepositories, useRepositories } from '@/views/address_book'
179 179
   import { toWebClientLink } from '@/utils/webclient'
180 180
   import { T } from '@/utils/i18n'
@@ -185,32 +185,33 @@
185 185
   import { CopyDocument } from '@element-plus/icons'
186 186
   import PlatformIcons from '@/components/icons/platform.vue'
187 187
 
188
-  const is_my = 1
189 188
   const appStore = useAppStore()
190
-
191 189
   const {
192 190
     listRes,
193 191
     listQuery,
194 192
     getList,
195 193
     handlerQuery,
194
+    collectionListRes,
195
+    getCollectionList,
196
+
196 197
     del,
198
+
197 199
     formVisible,
198 200
     platformList,
199 201
     formData,
200 202
     toEdit,
201 203
     toAdd,
202 204
     submit,
203
-    shareToWebClientVisible,
204
-    shareToWebClientForm,
205
-    toShowShare,
206
-    // collectionListQuery,
207
-    collectionListRes,
208
-    getCollectionList,
209 205
     tagListRes,
210
-    changeCollection,
211
-  } = useRepositories(is_my)
206
+    changeCollectionForUpdate,
207
+    getCollectionListForUpdate,
208
+    collectionListResForUpdate,
209
+    // collectionListQuery,
210
+
211
+  } = useRepositories('my')
212 212
 
213 213
   onMounted(getCollectionList)
214
+  onMounted(getCollectionListForUpdate)
214 215
   onMounted(getList)
215 216
   onActivated(getList)
216 217
 
@@ -218,6 +219,16 @@
218 219
 
219 220
   watch(() => listQuery.page_size, handlerQuery)
220 221
 
222
+  const shareToWebClientVisible = ref(false)
223
+  const shareToWebClientForm = reactive({
224
+    id: '',
225
+    hash: '',
226
+  })
227
+  const toShowShare = (row) => {
228
+    shareToWebClientForm.id = row.id
229
+    shareToWebClientForm.hash = row.hash
230
+    shareToWebClientVisible.value = true
231
+  }
221 232
   const {
222 233
     tagListRes: tagListResForBatchEdit,
223 234
     getTagList: getTagListForBatchEdit,
@@ -225,7 +236,7 @@
225 236
     show: showBatchEditTags,
226 237
     formData: batchEditTagsFormData,
227 238
     submit: _submitBatchEditTags,
228
-  } = useBatchUpdateTagsRepositories(is_my)
239
+  } = useBatchUpdateTagsRepositories()
229 240
   onMounted(getTagListForBatchEdit)
230 241
   const submitBatchEditTags = async () => {
231 242
     const res = await _submitBatchEditTags().catch(_ => false)

+ 22 - 19
src/views/my/peer/index.vue

@@ -22,7 +22,7 @@
22 22
         <el-form-item>
23 23
           <el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
24 24
           <el-button type="success" @click="toExport">{{ T('Export') }}</el-button>
25
-          <el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>
25
+          <!--          <el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>-->
26 26
           <el-button type="primary" @click="toBatchAddToAB">{{ T('BatchAddToAB') }}</el-button>
27 27
 
28 28
         </el-form-item>
@@ -59,7 +59,7 @@
59 59
             <el-button v-if="appStore.setting.appConfig.web_client" type="success" @click="toWebClientLink(row)">Web Client</el-button>
60 60
             <el-button type="primary" @click="toAddressBook(row)">{{ T('AddToAddressBook') }}</el-button>
61 61
             <el-button @click="toView(row)">{{ T('View') }}</el-button>
62
-            <el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
62
+            <!--            <el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>-->
63 63
           </template>
64 64
         </el-table-column>
65 65
       </el-table>
@@ -105,9 +105,9 @@
105 105
     <el-dialog v-model="ABFormVisible" width="800" :title="T('Create')">
106 106
       <el-form class="dialog-form" ref="form" :model="ABFormData" label-width="120px">
107 107
         <el-form-item :label="T('AddressBookName')" required prop="collection_id">
108
-          <el-select v-model="ABFormData.collection_id" clearable @change="changeCollection">
108
+          <el-select v-model="ABFormData.collection_id" clearable @change="changeCollectionForUpdate">
109 109
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
110
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
110
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
111 111
           </el-select>
112 112
         </el-form-item>
113 113
         <el-form-item label="ID" prop="id" required>
@@ -153,9 +153,9 @@
153 153
     <el-dialog v-model="batchABFormVisible" width="800" :title="T('Create')">
154 154
       <el-form class="dialog-form" ref="form" :model="batchABFormData" label-width="120px">
155 155
         <el-form-item :label="T('AddressBookName')" required prop="collection_id">
156
-          <el-select v-model="batchABFormData.collection_id" clearable @change="changeCollection">
156
+          <el-select v-model="batchABFormData.collection_id" clearable @change="changeCollectionForBatchCreateAB">
157 157
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
158
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
158
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
159 159
           </el-select>
160 160
         </el-form-item>
161 161
         <el-form-item :label="T('Tags')" prop="tags">
@@ -179,8 +179,7 @@
179 179
 
180 180
 <script setup>
181 181
   import { computed, onActivated, onMounted, reactive, ref, watch } from 'vue'
182
-  import { batchRemove, remove } from '@/api/peer'
183
-  import { myPeer } from '@/api/user'
182
+  import { list } from '@/api/my/peer'
184 183
   import { ElMessage, ElMessageBox } from 'element-plus'
185 184
   import { toWebClientLink } from '@/utils/webclient'
186 185
   import { T } from '@/utils/i18n'
@@ -191,7 +190,7 @@
191 190
   import { connectByClient } from '@/utils/peer'
192 191
   import { CopyDocument } from '@element-plus/icons'
193 192
   import { handleClipboard } from '@/utils/clipboard'
194
-  import { address_book_batchCreateFromPeers as batchCreateFromPeers } from '@/api/my'
193
+  import { batchCreateFromPeers } from '@/api/my/address_book'
195 194
 
196 195
   const appStore = useAppStore()
197 196
   const listRes = reactive({
@@ -207,7 +206,7 @@
207 206
 
208 207
   const getList = async () => {
209 208
     listRes.loading = true
210
-    const res = await myPeer(listQuery).catch(_ => false)
209
+    const res = await list(listQuery).catch(_ => false)
211 210
     listRes.loading = false
212 211
     if (res) {
213 212
       listRes.list = res.data.list
@@ -222,7 +221,7 @@
222 221
     }
223 222
   }
224 223
 
225
-  const del = async (row) => {
224
+  /*const del = async (row) => {
226 225
     const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
227 226
       confirmButtonText: T('Confirm'),
228 227
       cancelButtonText: T('Cancel'),
@@ -237,7 +236,7 @@
237 236
       ElMessage.success(T('OperationSuccess'))
238 237
       getList()
239 238
     }
240
-  }
239
+  }*/
241 240
   onMounted(getList)
242 241
   onActivated(getList)
243 242
 
@@ -305,14 +304,14 @@
305 304
     platformList: ABPlatformList,
306 305
     formVisible: ABFormVisible,
307 306
     formData: ABFormData,
308
-    collectionListRes,
309
-    getCollectionList,
307
+    collectionListResForUpdate,
308
+    getCollectionListForUpdate,
310 309
     tagListRes,
311
-    changeCollection,
310
+    changeCollectionForUpdate,
312 311
     submit: ABSubmit,
313 312
     fromPeer,
314
-  } = useABRepositories(1)
315
-  onMounted(getCollectionList)
313
+  } = useABRepositories('my')
314
+  onMounted(getCollectionListForUpdate)
316 315
   const toAddressBook = (peer) => {
317 316
     fromPeer(peer)
318 317
     ABFormVisible.value = true
@@ -322,7 +321,7 @@
322 321
   const handleSelectionChange = (val) => {
323 322
     multipleSelection.value = val
324 323
   }
325
-  const toBatchDelete = async () => {
324
+  /*const toBatchDelete = async () => {
326 325
     if (!multipleSelection.value.length) {
327 326
       ElMessage.warning(T('PleaseSelectData'))
328 327
       return false
@@ -341,7 +340,7 @@
341 340
       ElMessage.success(T('OperationSuccess'))
342 341
       getList()
343 342
     }
344
-  }
343
+  }*/
345 344
 
346 345
   const batchABFormVisible = ref(false)
347 346
   const toBatchAddToAB = () => {
@@ -352,6 +351,10 @@
352 351
     tags: [],
353 352
     peer_ids: [],
354 353
   })
354
+  const changeCollectionForBatchCreateAB = (val) => {
355
+    batchABFormData.value.tags = []
356
+    changeCollectionForUpdate(val)
357
+  }
355 358
   const submitBatchAddToAB = async () => {
356 359
     if (multipleSelection.value.length === 0) {
357 360
       ElMessage.warning(T('PleaseSelectData'))

+ 13 - 77
src/views/my/share_record/index.vue

@@ -16,7 +16,7 @@
16 16
         <el-table-column prop="created_at" :label="T('CreatedAt')" align="center"/>
17 17
         <el-table-column :label="`${T('ExpireTime')}(${T('Second')})`" prop="expire" align="center">
18 18
           <template #default="{row}">
19
-            <el-tag :type="expired(row)?'info':'success'">{{ row.expire ? row.expire : '-' }}</el-tag>
19
+            <el-tag :type="expired(row)?'info':'success'">{{ row.expire ? row.expire : T('Forever') }}</el-tag>
20 20
           </template>
21 21
         </el-table-column>
22 22
         <el-table-column :label="T('Actions')" align="center" width="400">
@@ -39,95 +39,31 @@
39 39
 </template>
40 40
 
41 41
 <script setup>
42
-  import { onActivated, onMounted, ref, watch, reactive } from 'vue'
42
+  import { onActivated, onMounted, watch } from 'vue'
43 43
   import { T } from '@/utils/i18n'
44
-  import { share_record_remove as remove, share_record_list as list, share_record_batchDelete as batchDelete } from '@/api/my'
45
-  import { ElMessage, ElMessageBox } from 'element-plus'
44
+  import { useRepositories } from '@/views/share_record'
46 45
 
47
-  const listRes = reactive({
48
-    list: [], total: 0, loading: false,
49
-  })
50
-  const listQuery = reactive({
51
-    page: 1,
52
-    page_size: 10,
53
-  })
46
+  const {
47
+    listRes,
48
+    listQuery,
49
+    getList,
50
+    handlerQuery,
51
+    del,
52
+    multipleSelection,
53
+    toBatchDelete,
54
+    expired,
55
+  } = useRepositories('my')
54 56
 
55
-  const getList = async () => {
56
-    listRes.loading = true
57
-    const res = await list(listQuery).catch(_ => false)
58
-    listRes.loading = false
59
-    if (res) {
60
-      listRes.list = res.data.list
61
-      listRes.total = res.data.total
62
-    }
63
-  }
64
-  const handlerQuery = () => {
65
-    if (listQuery.page === 1) {
66
-      getList()
67
-    } else {
68
-      listQuery.page = 1
69
-    }
70
-  }
71
-
72
-  const del = async (row) => {
73
-    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
74
-      confirmButtonText: T('Confirm'),
75
-      cancelButtonText: T('Cancel'),
76
-      type: 'warning',
77
-    }).catch(_ => false)
78
-    if (!cf) {
79
-      return false
80
-    }
81
-    const res = await remove({ id: row.id }).catch(_ => false)
82
-    if (res) {
83
-      ElMessage.success(T('OperationSuccess'))
84
-      getList()
85
-    }
86
-  }
87 57
   onMounted(getList)
88 58
   onActivated(getList)
89 59
 
90 60
   watch(() => listQuery.page, getList)
91 61
 
92 62
   watch(() => listQuery.page_size, handlerQuery)
93
-  const multipleSelection = ref([])
94 63
   const handleSelectionChange = (val) => {
95 64
     multipleSelection.value = val
96 65
   }
97
-  const toBatchDelete = () => {
98
-    if (multipleSelection.value.length === 0) {
99
-      return
100
-    }
101
-    batchdel(multipleSelection.value)
102
-  }
103 66
 
104
-  const batchdel = async (rows) => {
105
-    const ids = rows.map(r => r.id)
106
-    if (!ids.length) {
107
-      ElMessage.warning(T('PleaseSelectData'))
108
-      return false
109
-    }
110
-    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
111
-      confirmButtonText: T('Confirm'),
112
-      cancelButtonText: T('Cancel'),
113
-      type: 'warning',
114
-    }).catch(_ => false)
115
-    if (!cf) {
116
-      return false
117
-    }
118
-
119
-    const res = await batchDelete({ ids }).catch(_ => false)
120
-    if (res) {
121
-      ElMessage.success(T('OperationSuccess'))
122
-      getList()
123
-    }
124
-  }
125
-
126
-  const expired = (row) => {
127
-    const now = new Date().getTime()
128
-    const created_at = new Date(row.created_at).getTime()
129
-    return row.expire * 1000 + created_at < now
130
-  }
131 67
 
132 68
 </script>
133 69
 

+ 8 - 11
src/views/my/tag/index.vue

@@ -58,7 +58,7 @@
58 58
         <el-form-item :label="T('AddressBookName')">
59 59
           <el-select v-model="formData.collection_id" clearable>
60 60
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
61
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
61
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
62 62
           </el-select>
63 63
         </el-form-item>
64 64
         <el-form-item :label="T('Name')" prop="name" required>
@@ -86,7 +86,6 @@
86 86
   import { onMounted, watch, onActivated } from 'vue'
87 87
   import { useRepositories } from '@/views/tag'
88 88
   import { T } from '@/utils/i18n'
89
-  import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
90 89
 
91 90
   const {
92 91
     listRes,
@@ -101,9 +100,13 @@
101 100
     submit,
102 101
     activeChange,
103 102
     currentColor,
104
-  } = useRepositories()
105 103
 
106
-  listQuery.is_my = 1
104
+    collectionListRes,
105
+    getCollectionList,
106
+
107
+    collectionListResForUpdate,
108
+    getCollectionListForUpdate,
109
+  } = useRepositories('my')
107 110
 
108 111
   onMounted(getList)
109 112
   onActivated(getList)
@@ -112,14 +115,8 @@
112 115
 
113 116
   watch(() => listQuery.page_size, handlerQuery)
114 117
 
115
-  const {
116
-    listRes: collectionListRes,
117
-    listQuery: collectionListQuery,
118
-    getList: getCollectionList,
119
-  } = useCollectionRepositories()
120
-  collectionListQuery.is_my = 1
121
-  collectionListQuery.page_size = 999
122 118
   onMounted(getCollectionList)
119
+  onMounted(getCollectionListForUpdate)
123 120
 
124 121
 </script>
125 122
 

+ 20 - 15
src/views/peer/index.vue

@@ -163,7 +163,7 @@
163 163
     <el-dialog v-model="batchABFormVisible" width="800" :title="T('Create')">
164 164
       <el-form class="dialog-form" ref="form" :model="batchABFormData" label-width="120px">
165 165
         <el-form-item :label="T('Owner')" prop="user_id" required>
166
-          <el-select v-model="batchABFormData.user_id" @change="changeUser">
166
+          <el-select v-model="batchABFormData.user_id" @change="changeUserForBatchCreateAB">
167 167
             <el-option
168 168
                 v-for="item in allUsers"
169 169
                 :key="item.id"
@@ -173,9 +173,9 @@
173 173
           </el-select>
174 174
         </el-form-item>
175 175
         <el-form-item :label="T('AddressBookName')" required prop="collection_id">
176
-          <el-select v-model="batchABFormData.collection_id" clearable @change="changeCollection">
176
+          <el-select v-model="batchABFormData.collection_id" clearable>
177 177
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
178
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
178
+            <el-option v-for="c in collectionListResForBatchCreateAB.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
179 179
           </el-select>
180 180
         </el-form-item>
181 181
         <!--        <el-form-item :label="T('Tags')" prop="tags">
@@ -214,6 +214,7 @@
214 214
   import { CopyDocument } from '@element-plus/icons'
215 215
   import { handleClipboard } from '@/utils/clipboard'
216 216
   import { batchCreateFromPeers } from '@/api/address_book'
217
+  import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
217 218
 
218 219
   const appStore = useAppStore()
219 220
   const listRes = reactive({
@@ -345,16 +346,15 @@
345 346
     }
346 347
   }
347 348
 
349
+  //添加到地址簿 start
350
+  const { allUsers, getAllUsers } = loadAllUsers()
351
+  onMounted(getAllUsers)
348 352
   const {
349 353
     platformList: ABPlatformList,
350 354
     formVisible: ABFormVisible,
351 355
     formData: ABFormData,
352 356
     fromPeer,
353
-    changeCollection,
354
-    collectionListRes,
355
-    collectionListQuery,
356
-    getCollectionList,
357
-  } = useABRepositories()
357
+  } = useABRepositories('admin')
358 358
   const toAddressBook = (peer) => {
359 359
     fromPeer(peer)
360 360
     ABFormVisible.value = true
@@ -366,8 +366,6 @@
366 366
       ABFormVisible.value = false
367 367
     }
368 368
   }
369
-
370
-  const { allUsers, getAllUsers } = loadAllUsers()
371 369
   const tagList = ref([])
372 370
   const fetchTagListData = async (user_id) => {
373 371
     const res = await fetchTagList({ user_id }).catch(_ => false)
@@ -381,8 +379,8 @@
381 379
       tagList.value = ls.map(item => ({ name: item }))
382 380
     }
383 381
   }
384
-  onMounted(getAllUsers)
385 382
   onMounted(fetchTagListData)
383
+  // 添加到地址簿 end
386 384
 
387 385
   const multipleSelection = ref([])
388 386
   const handleSelectionChange = (val) => {
@@ -409,11 +407,17 @@
409 407
     }
410 408
   }
411 409
 
412
-  // 批量添加到地址簿
413
-  const changeUser = (val) => {
414
-    collectionListQuery.user_id = val
410
+  // 批量添加到地址簿 start
411
+  const {
412
+    listRes: collectionListResForBatchCreateAB,
413
+    listQuery: collectionListQueryForBatchCreateAB,
414
+    getList: getCollectionListForBatchCreateAB,
415
+  } = useCollectionRepositories('admin')
416
+  collectionListQueryForBatchCreateAB.page_size = 9999
417
+  const changeUserForBatchCreateAB = (val) => {
415 418
     batchABFormData.value.collection_id = 0
416
-    getCollectionList()
419
+    collectionListQueryForBatchCreateAB.user_id = val
420
+    getCollectionListForBatchCreateAB()
417 421
   }
418 422
   const batchABFormVisible = ref(false)
419 423
   const toBatchAddToAB = () => {
@@ -442,6 +446,7 @@
442 446
       batchABFormVisible.value = false
443 447
     }
444 448
   }
449
+  // 批量添加到地址簿 end
445 450
 
446 451
 </script>
447 452
 

+ 100 - 0
src/views/share_record/index.js

@@ -0,0 +1,100 @@
1
+import { reactive, ref } from 'vue'
2
+import { batchDelete as admin_batchDelete, list as admin_list, remove as admin_remove } from '@/api/share_record'
3
+import { batchDelete as my_batchDelete, list as my_list, remove as my_remove } from '@/api/my/share_record'
4
+import { ElMessage, ElMessageBox } from 'element-plus'
5
+import { T } from '@/utils/i18n'
6
+
7
+const apis = {
8
+  admin: { batchDelete: admin_batchDelete, list: admin_list, remove: admin_remove },
9
+  my: { batchDelete: my_batchDelete, list: my_list, remove: my_remove },
10
+}
11
+
12
+export function useRepositories (api_type = 'my') {
13
+  const listRes = reactive({
14
+    list: [], total: 0, loading: false,
15
+  })
16
+  const listQuery = reactive({
17
+    page: 1,
18
+    page_size: 10,
19
+  })
20
+
21
+  const getList = async () => {
22
+    listRes.loading = true
23
+    const res = await apis[api_type].list(listQuery).catch(_ => false)
24
+    listRes.loading = false
25
+    if (res) {
26
+      listRes.list = res.data.list
27
+      listRes.total = res.data.total
28
+    }
29
+  }
30
+  const handlerQuery = () => {
31
+    if (listQuery.page === 1) {
32
+      getList()
33
+    } else {
34
+      listQuery.page = 1
35
+    }
36
+  }
37
+
38
+  const del = async (row) => {
39
+    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
40
+      confirmButtonText: T('Confirm'),
41
+      cancelButtonText: T('Cancel'),
42
+      type: 'warning',
43
+    }).catch(_ => false)
44
+    if (!cf) {
45
+      return false
46
+    }
47
+    const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
48
+    if (res) {
49
+      ElMessage.success(T('OperationSuccess'))
50
+      getList()
51
+    }
52
+  }
53
+
54
+  const multipleSelection = ref([])
55
+  const toBatchDelete = async () => {
56
+    if (multipleSelection.value.length === 0) {
57
+      return
58
+    }
59
+
60
+    const ids = multipleSelection.value.map(r => r.id)
61
+    if (!ids.length) {
62
+      ElMessage.warning(T('PleaseSelectData'))
63
+      return false
64
+    }
65
+    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
66
+      confirmButtonText: T('Confirm'),
67
+      cancelButtonText: T('Cancel'),
68
+      type: 'warning',
69
+    }).catch(_ => false)
70
+    if (!cf) {
71
+      return false
72
+    }
73
+
74
+    const res = await apis[api_type].batchDelete({ ids }).catch(_ => false)
75
+    if (res) {
76
+      ElMessage.success(T('OperationSuccess'))
77
+      getList()
78
+    }
79
+  }
80
+
81
+  const expired = (row) => {
82
+    if (row.expire === 0) {
83
+      return false
84
+    }
85
+    const now = new Date().getTime()
86
+    const created_at = new Date(row.created_at).getTime()
87
+    return row.expire * 1000 + created_at < now
88
+  }
89
+
90
+  return {
91
+    listRes,
92
+    listQuery,
93
+    getList,
94
+    handlerQuery,
95
+    del,
96
+    multipleSelection,
97
+    toBatchDelete,
98
+    expired,
99
+  }
100
+}

+ 12 - 75
src/views/share_record/index.vue

@@ -31,7 +31,7 @@
31 31
         <el-table-column prop="created_at" :label="T('CreatedAt')" align="center"/>
32 32
         <el-table-column :label="`${T('ExpireTime')}(${T('Second')})`" prop="expire" align="center">
33 33
           <template #default="{row}">
34
-            <el-tag :type="expired(row)?'info':'success'">{{ row.expire ? row.expire : '-' }}</el-tag>
34
+            <el-tag :type="expired(row)?'info':'success'">{{ row.expire ? row.expire : T('Forever') }}</el-tag>
35 35
           </template>
36 36
         </el-table-column>
37 37
         <el-table-column :label="T('Actions')" align="center" width="400">
@@ -59,95 +59,32 @@
59 59
   import { T } from '@/utils/i18n'
60 60
   import { remove, list, batchDelete } from '@/api/share_record'
61 61
   import { ElMessage, ElMessageBox } from 'element-plus'
62
+  import { useRepositories } from '@/views/share_record/index'
62 63
 
63 64
   const { allUsers, getAllUsers } = loadAllUsers()
64 65
   getAllUsers()
65 66
 
66
-  const listRes = reactive({
67
-    list: [], total: 0, loading: false,
68
-  })
69
-  const listQuery = reactive({
70
-    page: 1,
71
-    page_size: 10,
72
-    is_my: 0,
73
-    user_id: null,
74
-  })
67
+  const {
68
+    listRes,
69
+    listQuery,
70
+    getList,
71
+    handlerQuery,
72
+    del,
73
+    multipleSelection,
74
+    toBatchDelete,
75
+    expired,
76
+  } = useRepositories('admin')
75 77
 
76
-  const getList = async () => {
77
-    listRes.loading = true
78
-    const res = await list(listQuery).catch(_ => false)
79
-    listRes.loading = false
80
-    if (res) {
81
-      listRes.list = res.data.list
82
-      listRes.total = res.data.total
83
-    }
84
-  }
85
-  const handlerQuery = () => {
86
-    if (listQuery.page === 1) {
87
-      getList()
88
-    } else {
89
-      listQuery.page = 1
90
-    }
91
-  }
92
-  const expired = (row) => {
93
-    const now = new Date().getTime()
94
-    const created_at = new Date(row.created_at).getTime()
95
-    return row.expire * 1000 + created_at  < now
96
-  }
97
-
98
-  const del = async (row) => {
99
-    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
100
-      confirmButtonText: T('Confirm'),
101
-      cancelButtonText: T('Cancel'),
102
-      type: 'warning',
103
-    }).catch(_ => false)
104
-    if (!cf) {
105
-      return false
106
-    }
107
-    const res = await remove({ id: row.id }).catch(_ => false)
108
-    if (res) {
109
-      ElMessage.success(T('OperationSuccess'))
110
-      getList()
111
-    }
112
-  }
113 78
   onMounted(getList)
114 79
   onActivated(getList)
115 80
 
116 81
   watch(() => listQuery.page, getList)
117 82
 
118 83
   watch(() => listQuery.page_size, handlerQuery)
119
-  const multipleSelection = ref([])
120 84
   const handleSelectionChange = (val) => {
121 85
     multipleSelection.value = val
122 86
   }
123
-  const toBatchDelete = () => {
124
-    if (multipleSelection.value.length === 0) {
125
-      return
126
-    }
127
-    batchdel(multipleSelection.value)
128
-  }
129 87
 
130
-  const batchdel = async (rows) => {
131
-    const ids = rows.map(r => r.id)
132
-    if (!ids.length) {
133
-      ElMessage.warning(T('PleaseSelectData'))
134
-      return false
135
-    }
136
-    const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
137
-      confirmButtonText: T('Confirm'),
138
-      cancelButtonText: T('Cancel'),
139
-      type: 'warning',
140
-    }).catch(_ => false)
141
-    if (!cf) {
142
-      return false
143
-    }
144
-
145
-    const res = await batchDelete({ ids }).catch(_ => false)
146
-    if (res) {
147
-      ElMessage.success(T('OperationSuccess'))
148
-      getList()
149
-    }
150
-  }
151 88
 
152 89
 </script>
153 90
 

+ 40 - 25
src/views/tag/index.js

@@ -1,20 +1,18 @@
1 1
 import { reactive, ref } from 'vue'
2
-import { create, list, remove, update } from '@/api/tag'
2
+import { create as admin_create, list as admin_list, remove as admin_remove, update as admin_update } from '@/api/tag'
3
+import { create as my_create, list as my_list, remove as my_remove, update as my_update } from '@/api/my/tag'
3 4
 import { ElMessage, ElMessageBox } from 'element-plus'
4 5
 import { useRoute } from 'vue-router'
5 6
 import { T } from '@/utils/i18n'
6
-import { loadAllUsers } from '@/global'
7 7
 import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
8 8
 
9
-export function useRepositories (is_my = 0) {
10
-  const { allUsers, getAllUsers } = loadAllUsers()
9
+const apis = {
10
+  admin: { list: admin_list, remove: admin_remove, update: admin_update, create: admin_create },
11
+  my: { list: my_list, remove: my_remove, create: my_create, update: my_update },
12
+}
13
+
14
+export function useRepositories (api_type = 'my') {
11 15
 
12
-  const {
13
-    listRes: collectionListRes,
14
-    listQuery: collectionListQuery,
15
-    getList: getCollectionList,
16
-  } = useCollectionRepositories(is_my)
17
-  collectionListQuery.page_size = 9999
18 16
   //获取query
19 17
   const route = useRoute()
20 18
   const user_id = route.query?.user_id
@@ -24,7 +22,6 @@ export function useRepositories (is_my = 0) {
24 22
   const listQuery = reactive({
25 23
     page: 1,
26 24
     page_size: 10,
27
-    is_my,
28 25
     user_id: user_id ? parseInt(user_id) : null,
29 26
     collection_id: null,
30 27
   })
@@ -72,7 +69,7 @@ export function useRepositories (is_my = 0) {
72 69
 
73 70
   const getList = async () => {
74 71
     listRes.loading = true
75
-    const res = await list(listQuery).catch(_ => false)
72
+    const res = await apis[api_type].list(listQuery).catch(_ => false)
76 73
     listRes.loading = false
77 74
     if (res) {
78 75
       listRes.list = res.data.list.map(item => {
@@ -100,7 +97,7 @@ export function useRepositories (is_my = 0) {
100 97
       return false
101 98
     }
102 99
 
103
-    const res = await remove({ id: row.id }).catch(_ => false)
100
+    const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
104 101
     if (res) {
105 102
       ElMessage.success(T('OperationSuccess'))
106 103
       getList()
@@ -112,12 +109,11 @@ export function useRepositories (is_my = 0) {
112 109
     id: 0,
113 110
     name: '',
114 111
     color: 0,
115
-    user_id: 0,
116
-    collection_id: 0,
112
+    user_id: null,
113
+    collection_id: null,
117 114
   })
118 115
   const currentColor = ref('')
119 116
   const activeChange = (c) => {
120
-    console.log(c)
121 117
     currentColor.value = c
122 118
   }
123 119
   const toEdit = (row) => {
@@ -137,7 +133,7 @@ export function useRepositories (is_my = 0) {
137 133
     formData.name = ''
138 134
     formData.color = ''
139 135
     formData.user_id = null
140
-    formData.collection_id = 0
136
+    formData.collection_id = null
141 137
   }
142 138
   const submit = async () => {
143 139
     console.log(formData)
@@ -145,7 +141,7 @@ export function useRepositories (is_my = 0) {
145 141
       ElMessage.error('请选择颜色')
146 142
       return
147 143
     }
148
-    const api = formData.id ? update : create
144
+    const api = formData.id ? apis[api_type].update : apis[api_type].create
149 145
     const data = {
150 146
       ...formData,
151 147
       color: rgba2flutterColor(formData.color),
@@ -159,8 +155,15 @@ export function useRepositories (is_my = 0) {
159 155
     }
160 156
   }
161 157
 
162
-  const changeQueryUser = async (val) => {
163
-    listQuery.collection_id = null
158
+  //query form collection
159
+  const {
160
+    listRes: collectionListRes,
161
+    listQuery: collectionListQuery,
162
+    getList: getCollectionList,
163
+  } = useCollectionRepositories(api_type)
164
+  collectionListQuery.page_size = 9999
165
+  const changeUser = async (val) => {
166
+    formData.collection_id = 0
164 167
     if (!val) {
165 168
       collectionListRes.list = []
166 169
     } else {
@@ -168,13 +171,21 @@ export function useRepositories (is_my = 0) {
168 171
       getCollectionList()
169 172
     }
170 173
   }
171
-  const changeUser = async (val) => {
172
-    formData.collection_id = 0
174
+
175
+  const {
176
+    listRes: collectionListResForUpdate,
177
+    listQuery: collectionListQueryForUpdate,
178
+    getList: getCollectionListForUpdate,
179
+  } = useCollectionRepositories(api_type)
180
+  collectionListQueryForUpdate.page_size = 9999
181
+  //create or update form collection
182
+  const changeUserForUpdate = async (val) => {
183
+    listQuery.collection_id = null
173 184
     if (!val) {
174 185
       collectionListRes.list = []
175 186
     } else {
176 187
       collectionListQuery.user_id = val
177
-      getCollectionList()
188
+      getCollectionListForUpdate()
178 189
     }
179 190
   }
180 191
   return {
@@ -192,8 +203,12 @@ export function useRepositories (is_my = 0) {
192 203
     currentColor,
193 204
 
194 205
     collectionListRes,
195
-    allUsers, getAllUsers,
196
-    changeQueryUser,
197 206
     changeUser,
207
+    getCollectionList,
208
+
209
+    collectionListResForUpdate,
210
+    changeUserForUpdate,
211
+    getCollectionListForUpdate,
212
+
198 213
   }
199 214
 }

+ 14 - 7
src/views/tag/index.vue

@@ -3,7 +3,7 @@
3 3
     <el-card class="list-query" shadow="hover">
4 4
       <el-form inline label-width="120px">
5 5
         <el-form-item :label="T('Owner')">
6
-          <el-select v-model="listQuery.user_id" clearable @change="changeQueryUser">
6
+          <el-select v-model="listQuery.user_id" clearable @change="changeUser">
7 7
             <el-option
8 8
                 v-for="item in allUsers"
9 9
                 :key="item.id"
@@ -71,7 +71,7 @@
71 71
     <el-dialog v-model="formVisible" :title="!formData.id?T('Create'):T('Update')" width="800">
72 72
       <el-form class="dialog-form" ref="form" :model="formData" label-width="120px">
73 73
         <el-form-item :label="T('Owner')" prop="user_id" required>
74
-          <el-select v-model="formData.user_id" @change="changeUser">
74
+          <el-select v-model="formData.user_id" @change="changeUserForUpdate">
75 75
             <el-option
76 76
                 v-for="item in allUsers"
77 77
                 :key="item.id"
@@ -83,7 +83,7 @@
83 83
         <el-form-item :label="T('AddressBookName')" prop="collection_id" required>
84 84
           <el-select v-model="formData.collection_id" clearable>
85 85
             <el-option :value="0" :label="T('MyAddressBook')"></el-option>
86
-            <el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
86
+            <el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
87 87
           </el-select>
88 88
         </el-form-item>
89 89
         <el-form-item :label="T('Name')" prop="name" required>
@@ -111,7 +111,10 @@
111 111
   import { onMounted, reactive, watch, ref, onActivated } from 'vue'
112 112
   import { useRepositories } from '@/views/tag/index'
113 113
   import { T } from '@/utils/i18n'
114
+  import { loadAllUsers } from '@/global'
114 115
 
116
+  const { allUsers, getAllUsers } = loadAllUsers()
117
+  onMounted(getAllUsers)
115 118
   const {
116 119
     listRes,
117 120
     listQuery,
@@ -125,12 +128,16 @@
125 128
     submit,
126 129
     activeChange,
127 130
     currentColor,
131
+
128 132
     collectionListRes,
129
-    allUsers, getAllUsers,
130
-    changeQueryUser,
131 133
     changeUser,
132
-  } = useRepositories()
133
-  onMounted(getAllUsers)
134
+    // getCollectionList,
135
+
136
+    collectionListResForUpdate,
137
+    changeUserForUpdate,
138
+    // getCollectionListForUpdate,
139
+  } = useRepositories('admin')
140
+
134 141
   onMounted(getList)
135 142
   onActivated(getList)
136 143