Split my and admin
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
toEdit,
|
||||
toAdd,
|
||||
submit,
|
||||
} = useRepositories()
|
||||
} = useRepositories('admin')
|
||||
|
||||
listQuery.is_my = 0
|
||||
|
||||
|
||||
@@ -1,28 +1,24 @@
|
||||
import { reactive, ref } from 'vue'
|
||||
import { batchUpdateTags, create, list, remove, update } from '@/api/address_book'
|
||||
import { create as admin_create, list as admin_list, remove as admin_remove, update as admin_update } from '@/api/address_book'
|
||||
import { batchUpdateTags, list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { T } from '@/utils/i18n'
|
||||
import { useRepositories as useCollectionRepositories } from '@/views/address_book/collection'
|
||||
import { useRepositories as useTagRepositories } from '@/views/tag/index'
|
||||
import { loadAllUsers } from '@/global'
|
||||
import { simpleData } from '@/api/peer'
|
||||
|
||||
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)
|
||||
} = useCollectionRepositories(api_type)
|
||||
collectionListQuery.page_size = 9999
|
||||
const {
|
||||
listRes: tagListRes,
|
||||
listQuery: tagListQuery,
|
||||
getList: getTagList,
|
||||
} = useTagRepositories(is_my)
|
||||
tagListQuery.page_size = 9999
|
||||
|
||||
const listRes = reactive({
|
||||
list: [], total: 0, loading: false,
|
||||
@@ -30,7 +26,6 @@ export function useRepositories (is_my = 0) {
|
||||
const listQuery = reactive({
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
is_my,
|
||||
id: null,
|
||||
user_id: null,
|
||||
username: null,
|
||||
@@ -40,7 +35,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) {
|
||||
const ids = res.data.list.map(item => item.id)
|
||||
@@ -78,13 +73,14 @@ export function useRepositories (is_my = 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
const res = await remove({ row_id: row.row_id }).catch(_ => false)
|
||||
const res = await apis[api_type].remove({ row_id: row.row_id }).catch(_ => false)
|
||||
if (res) {
|
||||
ElMessage.success(T('OperationSuccess'))
|
||||
getList()
|
||||
}
|
||||
}
|
||||
|
||||
//创建或者修改
|
||||
const platformList = [
|
||||
{ label: 'Windows', value: 'Windows', icon: 'windows' },
|
||||
{ label: 'Linux', value: 'Linux', icon: 'linux' },
|
||||
@@ -112,6 +108,18 @@ export function useRepositories (is_my = 0) {
|
||||
'username': '',
|
||||
collection_id: null,
|
||||
})
|
||||
const {
|
||||
listRes: collectionListResForUpdate,
|
||||
listQuery: collectionListQueryForUpdate,
|
||||
getList: getCollectionListForUpdate,
|
||||
} = useCollectionRepositories(api_type)
|
||||
collectionListQueryForUpdate.page_size = 9999
|
||||
const {
|
||||
listRes: tagListRes,
|
||||
listQuery: tagListQuery,
|
||||
getList: getTagList,
|
||||
} = useTagRepositories(api_type)
|
||||
tagListQuery.page_size = 9999
|
||||
|
||||
const toEdit = (row) => {
|
||||
formVisible.value = true
|
||||
@@ -119,9 +127,9 @@ export function useRepositories (is_my = 0) {
|
||||
Object.keys(formData).forEach(key => {
|
||||
formData[key] = row[key]
|
||||
})
|
||||
collectionListQuery.user_id = row.user_id
|
||||
getCollectionList()
|
||||
collectionListQueryForUpdate.user_id = row.user_id
|
||||
tagListQuery.collection_id = row.collection_id
|
||||
getCollectionListForUpdate()
|
||||
getTagList()
|
||||
|
||||
}
|
||||
@@ -147,7 +155,7 @@ export function useRepositories (is_my = 0) {
|
||||
|
||||
}
|
||||
const submit = async () => {
|
||||
const api = formData.row_id ? update : create
|
||||
const api = formData.row_id ? apis[api_type].update : apis[api_type].create
|
||||
const res = await api(formData).catch(_ => false)
|
||||
if (res) {
|
||||
ElMessage.success(T('OperationSuccess'))
|
||||
@@ -155,16 +163,6 @@ export function useRepositories (is_my = 0) {
|
||||
getList()
|
||||
}
|
||||
}
|
||||
const shareToWebClientVisible = ref(false)
|
||||
const shareToWebClientForm = reactive({
|
||||
id: '',
|
||||
hash: '',
|
||||
})
|
||||
const toShowShare = (row) => {
|
||||
shareToWebClientForm.id = row.id
|
||||
shareToWebClientForm.hash = row.hash
|
||||
shareToWebClientVisible.value = true
|
||||
}
|
||||
|
||||
const changeQueryUser = async (val) => {
|
||||
tagListRes.list = []
|
||||
@@ -176,18 +174,18 @@ export function useRepositories (is_my = 0) {
|
||||
getCollectionList()
|
||||
}
|
||||
}
|
||||
const changeUser = async (val) => {
|
||||
const changeUserForUpdate = async (val) => {
|
||||
tagListRes.list = []
|
||||
formData.tags = []
|
||||
formData.collection_id = 0
|
||||
if (!val) {
|
||||
collectionListRes.list = []
|
||||
collectionListResForUpdate.list = []
|
||||
} else {
|
||||
collectionListQuery.user_id = val
|
||||
getCollectionList()
|
||||
collectionListQueryForUpdate.user_id = val
|
||||
getCollectionListForUpdate()
|
||||
}
|
||||
}
|
||||
const changeCollection = async (val) => {
|
||||
const changeCollectionForUpdate = async (val) => {
|
||||
tagListRes.list = []
|
||||
formData.tags = []
|
||||
tagListQuery.user_id = formData.user_id
|
||||
@@ -217,42 +215,38 @@ export function useRepositories (is_my = 0) {
|
||||
listQuery,
|
||||
getList,
|
||||
handlerQuery,
|
||||
del,
|
||||
collectionListQuery,
|
||||
getCollectionList,
|
||||
collectionListRes,
|
||||
changeQueryUser,
|
||||
|
||||
platformList,
|
||||
|
||||
del,
|
||||
|
||||
formVisible,
|
||||
formData,
|
||||
toEdit,
|
||||
toAdd,
|
||||
submit,
|
||||
shareToWebClientVisible,
|
||||
shareToWebClientForm,
|
||||
toShowShare,
|
||||
|
||||
collectionListQuery,
|
||||
getCollectionList,
|
||||
collectionListRes,
|
||||
|
||||
getCollectionListForUpdate,
|
||||
collectionListResForUpdate,
|
||||
changeUserForUpdate,
|
||||
changeCollectionForUpdate,
|
||||
tagListQuery,
|
||||
getTagList,
|
||||
tagListRes,
|
||||
|
||||
allUsers,
|
||||
getAllUsers,
|
||||
|
||||
changeQueryUser,
|
||||
changeUser,
|
||||
changeCollection,
|
||||
|
||||
fromPeer,
|
||||
}
|
||||
}
|
||||
|
||||
export function useBatchUpdateTagsRepositories (is_my = 0) {
|
||||
export function useBatchUpdateTagsRepositories () {
|
||||
const {
|
||||
listRes: tagListRes,
|
||||
listQuery: tagListQuery,
|
||||
getList: getTagList,
|
||||
} = useTagRepositories(is_my)
|
||||
} = useTagRepositories('my')
|
||||
tagListQuery.page_size = 9999
|
||||
|
||||
const visible = ref(false)
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<el-dialog v-model="formVisible" width="800" :title="!formData.row_id?T('Create') :T('Update') ">
|
||||
<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"
|
||||
@@ -99,9 +99,9 @@
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="T('AddressBookName')">
|
||||
<el-select v-model="formData.collection_id" clearable @change="changeCollection">
|
||||
<el-select v-model="formData.collection_id" clearable @change="changeCollectionForUpdate">
|
||||
<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="ID" prop="id" required>
|
||||
@@ -162,7 +162,6 @@
|
||||
<el-switch v-model="formData.sameServer"></el-switch>
|
||||
</el-form-item>-->
|
||||
|
||||
|
||||
<el-form-item>
|
||||
<el-button @click="formVisible = false">{{ T('Cancel') }}</el-button>
|
||||
<el-button @click="submit" type="primary">{{ T('Submit') }}</el-button>
|
||||
@@ -179,9 +178,9 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onActivated, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { onActivated, onMounted, watch } from 'vue'
|
||||
import { useRepositories } from '@/views/address_book/index'
|
||||
import { toWebClientLink, getPeerSlat } from '@/utils/webclient'
|
||||
import { toWebClientLink } from '@/utils/webclient'
|
||||
import { T } from '@/utils/i18n'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { connectByClient } from '@/utils/peer'
|
||||
@@ -189,18 +188,19 @@
|
||||
import { handleClipboard } from '@/utils/clipboard'
|
||||
import { CopyDocument } from '@element-plus/icons'
|
||||
import PlatformIcons from '@/components/icons/platform.vue'
|
||||
|
||||
|
||||
import { loadAllUsers } from '@/global'
|
||||
|
||||
const appStore = useAppStore()
|
||||
const route = useRoute()
|
||||
|
||||
const { allUsers, getAllUsers } = loadAllUsers()
|
||||
|
||||
const {
|
||||
listRes,
|
||||
listQuery,
|
||||
getList,
|
||||
handlerQuery,
|
||||
collectionListRes,
|
||||
|
||||
del,
|
||||
formVisible,
|
||||
platformList,
|
||||
@@ -208,19 +208,13 @@
|
||||
toEdit,
|
||||
toAdd,
|
||||
submit,
|
||||
// shareToWebClientVisible,
|
||||
// shareToWebClientForm,
|
||||
// toShowShare,
|
||||
collectionListRes,
|
||||
|
||||
changeUserForUpdate,
|
||||
changeCollectionForUpdate,
|
||||
collectionListResForUpdate,
|
||||
tagListRes,
|
||||
|
||||
allUsers, getAllUsers,
|
||||
|
||||
changeQueryUser,
|
||||
changeUser,
|
||||
changeCollection
|
||||
} = useRepositories()
|
||||
} = useRepositories('admin')
|
||||
|
||||
if (route.query?.user_id) {
|
||||
listQuery.user_id = parseInt(route.query.user_id)
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { create, list, remove, update } from '@/api/address_book_collection_rule'
|
||||
import { list as admin_list, create as admin_create, update as admin_update, remove as admin_remove } from '@/api/address_book_collection_rule'
|
||||
import { list as my_list, create as my_create, update as my_update, remove as my_remove } from '@/api/my/address_book_collection_rule'
|
||||
import { groupUsers } from '@/api/user'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { T } from '@/utils/i18n'
|
||||
import collection from '@element-plus/icons/lib/Collection'
|
||||
|
||||
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,
|
||||
})
|
||||
@@ -13,12 +18,11 @@ export function useRepositories (is_my) {
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
collection_id: null,
|
||||
is_my,
|
||||
})
|
||||
|
||||
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
|
||||
@@ -43,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()
|
||||
@@ -79,7 +83,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'))
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item :label="T('ShareTo')" prop="to_id" required>
|
||||
<!-- <el-input-number v-model="formData.to_id"></el-input-number>-->
|
||||
<!-- <el-input-number v-model="formData.to_id"></el-input-number>-->
|
||||
<el-select v-model="formData.to_id">
|
||||
<el-option
|
||||
v-for="item in groupUsersList"
|
||||
@@ -106,7 +106,7 @@
|
||||
rules,
|
||||
groupUsersList,
|
||||
getGroupUsers,
|
||||
} = useRepositories(props.is_my)
|
||||
} = useRepositories(props.is_my ? 'my' : 'admin')
|
||||
|
||||
formData.collection_id = props.collection.id
|
||||
formData.user_id = props.collection.user_id
|
||||
|
||||
Reference in New Issue
Block a user