Split my and admin
This commit is contained in:
+44
-29
@@ -1,20 +1,18 @@
|
||||
import { reactive, ref } from 'vue'
|
||||
import { create, list, remove, update } from '@/api/tag'
|
||||
import { create as admin_create, list as admin_list, remove as admin_remove, update as admin_update } from '@/api/tag'
|
||||
import { create as my_create, list as my_list, remove as my_remove, update as my_update } from '@/api/my/tag'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { T } from '@/utils/i18n'
|
||||
import { loadAllUsers } from '@/global'
|
||||
import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
|
||||
|
||||
export function useRepositories (is_my = 0) {
|
||||
const { allUsers, getAllUsers } = loadAllUsers()
|
||||
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: collectionListRes,
|
||||
listQuery: collectionListQuery,
|
||||
getList: getCollectionList,
|
||||
} = useCollectionRepositories(is_my)
|
||||
collectionListQuery.page_size = 9999
|
||||
//获取query
|
||||
const route = useRoute()
|
||||
const user_id = route.query?.user_id
|
||||
@@ -24,7 +22,6 @@ export function useRepositories (is_my = 0) {
|
||||
const listQuery = reactive({
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
is_my,
|
||||
user_id: user_id ? parseInt(user_id) : null,
|
||||
collection_id: null,
|
||||
})
|
||||
@@ -72,7 +69,7 @@ export function useRepositories (is_my = 0) {
|
||||
|
||||
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.map(item => {
|
||||
@@ -100,7 +97,7 @@ export function useRepositories (is_my = 0) {
|
||||
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()
|
||||
@@ -112,12 +109,11 @@ export function useRepositories (is_my = 0) {
|
||||
id: 0,
|
||||
name: '',
|
||||
color: 0,
|
||||
user_id: 0,
|
||||
collection_id: 0,
|
||||
user_id: null,
|
||||
collection_id: null,
|
||||
})
|
||||
const currentColor = ref('')
|
||||
const activeChange = (c) => {
|
||||
console.log(c)
|
||||
currentColor.value = c
|
||||
}
|
||||
const toEdit = (row) => {
|
||||
@@ -137,7 +133,7 @@ export function useRepositories (is_my = 0) {
|
||||
formData.name = ''
|
||||
formData.color = ''
|
||||
formData.user_id = null
|
||||
formData.collection_id = 0
|
||||
formData.collection_id = null
|
||||
}
|
||||
const submit = async () => {
|
||||
console.log(formData)
|
||||
@@ -145,7 +141,7 @@ export function useRepositories (is_my = 0) {
|
||||
ElMessage.error('请选择颜色')
|
||||
return
|
||||
}
|
||||
const api = formData.id ? update : create
|
||||
const api = formData.id ? apis[api_type].update : apis[api_type].create
|
||||
const data = {
|
||||
...formData,
|
||||
color: rgba2flutterColor(formData.color),
|
||||
@@ -159,15 +155,13 @@ export function useRepositories (is_my = 0) {
|
||||
}
|
||||
}
|
||||
|
||||
const changeQueryUser = async (val) => {
|
||||
listQuery.collection_id = null
|
||||
if (!val) {
|
||||
collectionListRes.list = []
|
||||
} else {
|
||||
collectionListQuery.user_id = val
|
||||
getCollectionList()
|
||||
}
|
||||
}
|
||||
//query form collection
|
||||
const {
|
||||
listRes: collectionListRes,
|
||||
listQuery: collectionListQuery,
|
||||
getList: getCollectionList,
|
||||
} = useCollectionRepositories(api_type)
|
||||
collectionListQuery.page_size = 9999
|
||||
const changeUser = async (val) => {
|
||||
formData.collection_id = 0
|
||||
if (!val) {
|
||||
@@ -177,6 +171,23 @@ export function useRepositories (is_my = 0) {
|
||||
getCollectionList()
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
listRes: collectionListResForUpdate,
|
||||
listQuery: collectionListQueryForUpdate,
|
||||
getList: getCollectionListForUpdate,
|
||||
} = useCollectionRepositories(api_type)
|
||||
collectionListQueryForUpdate.page_size = 9999
|
||||
//create or update form collection
|
||||
const changeUserForUpdate = async (val) => {
|
||||
listQuery.collection_id = null
|
||||
if (!val) {
|
||||
collectionListRes.list = []
|
||||
} else {
|
||||
collectionListQuery.user_id = val
|
||||
getCollectionListForUpdate()
|
||||
}
|
||||
}
|
||||
return {
|
||||
listRes,
|
||||
listQuery,
|
||||
@@ -192,8 +203,12 @@ export function useRepositories (is_my = 0) {
|
||||
currentColor,
|
||||
|
||||
collectionListRes,
|
||||
allUsers, getAllUsers,
|
||||
changeQueryUser,
|
||||
changeUser,
|
||||
getCollectionList,
|
||||
|
||||
collectionListResForUpdate,
|
||||
changeUserForUpdate,
|
||||
getCollectionListForUpdate,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -3,7 +3,7 @@
|
||||
<el-card class="list-query" shadow="hover">
|
||||
<el-form inline label-width="120px">
|
||||
<el-form-item :label="T('Owner')">
|
||||
<el-select v-model="listQuery.user_id" clearable @change="changeQueryUser">
|
||||
<el-select v-model="listQuery.user_id" clearable @change="changeUser">
|
||||
<el-option
|
||||
v-for="item in allUsers"
|
||||
:key="item.id"
|
||||
@@ -71,7 +71,7 @@
|
||||
<el-dialog v-model="formVisible" :title="!formData.id?T('Create'):T('Update')" width="800">
|
||||
<el-form class="dialog-form" ref="form" :model="formData" label-width="120px">
|
||||
<el-form-item :label="T('Owner')" prop="user_id" required>
|
||||
<el-select v-model="formData.user_id" @change="changeUser">
|
||||
<el-select v-model="formData.user_id" @change="changeUserForUpdate">
|
||||
<el-option
|
||||
v-for="item in allUsers"
|
||||
:key="item.id"
|
||||
@@ -83,7 +83,7 @@
|
||||
<el-form-item :label="T('AddressBookName')" prop="collection_id" required>
|
||||
<el-select v-model="formData.collection_id" clearable>
|
||||
<el-option :value="0" :label="T('MyAddressBook')"></el-option>
|
||||
<el-option v-for="c in collectionListRes.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
|
||||
<el-option v-for="c in collectionListResForUpdate.list" :key="c.id" :label="c.name" :value="c.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="T('Name')" prop="name" required>
|
||||
@@ -111,7 +111,10 @@
|
||||
import { onMounted, reactive, watch, ref, onActivated } from 'vue'
|
||||
import { useRepositories } from '@/views/tag/index'
|
||||
import { T } from '@/utils/i18n'
|
||||
import { loadAllUsers } from '@/global'
|
||||
|
||||
const { allUsers, getAllUsers } = loadAllUsers()
|
||||
onMounted(getAllUsers)
|
||||
const {
|
||||
listRes,
|
||||
listQuery,
|
||||
@@ -125,12 +128,16 @@
|
||||
submit,
|
||||
activeChange,
|
||||
currentColor,
|
||||
|
||||
collectionListRes,
|
||||
allUsers, getAllUsers,
|
||||
changeQueryUser,
|
||||
changeUser,
|
||||
} = useRepositories()
|
||||
onMounted(getAllUsers)
|
||||
// getCollectionList,
|
||||
|
||||
collectionListResForUpdate,
|
||||
changeUserForUpdate,
|
||||
// getCollectionListForUpdate,
|
||||
} = useRepositories('admin')
|
||||
|
||||
onMounted(getList)
|
||||
onActivated(getList)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user