Split my and admin
Cette révision appartient à :
@@ -1,23 +1,28 @@
|
||||
import { reactive, ref } from 'vue'
|
||||
import { create, list, remove, update } from '@/api/address_book_collection'
|
||||
import { list as admin_list, create as admin_create, update as admin_update, remove as admin_remove } from '@/api/address_book_collection'
|
||||
import { list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book_collection'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { T } from '@/utils/i18n'
|
||||
|
||||
export function useRepositories (is_my) {
|
||||
const apis = {
|
||||
admin: { list: admin_list, remove: admin_remove, update: admin_update, create: admin_create },
|
||||
my: { list: my_list, remove: my_remove, create: my_create, update: my_update },
|
||||
}
|
||||
|
||||
export function useRepositories (api_type = 'my') {
|
||||
const listRes = reactive({
|
||||
list: [], total: 0, loading: false,
|
||||
})
|
||||
const listQuery = reactive({
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
is_my,
|
||||
name: null,
|
||||
user_id: null,
|
||||
})
|
||||
|
||||
const getList = async () => {
|
||||
listRes.loading = true
|
||||
const res = await list(listQuery).catch(_ => false)
|
||||
const res = await apis[api_type].list(listQuery).catch(_ => false)
|
||||
listRes.loading = false
|
||||
if (res) {
|
||||
listRes.list = res.data.list
|
||||
@@ -42,7 +47,7 @@ export function useRepositories (is_my) {
|
||||
return false
|
||||
}
|
||||
|
||||
const res = await remove({ id: row.id }).catch(_ => false)
|
||||
const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
|
||||
if (res) {
|
||||
ElMessage.success(T('OperationSuccess'))
|
||||
getList()
|
||||
@@ -72,7 +77,7 @@ export function useRepositories (is_my) {
|
||||
|
||||
}
|
||||
const submit = async () => {
|
||||
const api = formData.id ? update : create
|
||||
const api = formData.id ? apis[api_type].update : apis[api_type].create
|
||||
const res = await api(formData).catch(_ => false)
|
||||
if (res) {
|
||||
ElMessage.success(T('OperationSuccess'))
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur