| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import { reactive, ref } from 'vue'
- import { batchDelete as admin_batchDelete, list as admin_list, remove as admin_remove } from '@/api/share_record'
- import { batchDelete as my_batchDelete, list as my_list, remove as my_remove } from '@/api/my/share_record'
- import { ElMessage, ElMessageBox } from 'element-plus'
- import { T } from '@/utils/i18n'
- const apis = {
- admin: { batchDelete: admin_batchDelete, list: admin_list, remove: admin_remove },
- my: { batchDelete: my_batchDelete, list: my_list, remove: my_remove },
- }
- export function useRepositories (api_type = 'my') {
- const listRes = reactive({
- list: [], total: 0, loading: false,
- })
- const listQuery = reactive({
- page: 1,
- page_size: 10,
- })
- const getList = async () => {
- listRes.loading = true
- const res = await apis[api_type].list(listQuery).catch(_ => false)
- listRes.loading = false
- if (res) {
- listRes.list = res.data.list
- listRes.total = res.data.total
- }
- }
- const handlerQuery = () => {
- if (listQuery.page === 1) {
- getList()
- } else {
- listQuery.page = 1
- }
- }
- const del = async (row) => {
- const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
- confirmButtonText: T('Confirm'),
- cancelButtonText: T('Cancel'),
- type: 'warning',
- }).catch(_ => false)
- if (!cf) {
- return false
- }
- const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const multipleSelection = ref([])
- const toBatchDelete = async () => {
- if (multipleSelection.value.length === 0) {
- return
- }
- const ids = multipleSelection.value.map(r => r.id)
- if (!ids.length) {
- ElMessage.warning(T('PleaseSelectData'))
- return false
- }
- const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
- confirmButtonText: T('Confirm'),
- cancelButtonText: T('Cancel'),
- type: 'warning',
- }).catch(_ => false)
- if (!cf) {
- return false
- }
- const res = await apis[api_type].batchDelete({ ids }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const expired = (row) => {
- if (row.expire === 0) {
- return false
- }
- const now = new Date().getTime()
- const created_at = new Date(row.created_at).getTime()
- return row.expire * 1000 + created_at < now
- }
- return {
- listRes,
- listQuery,
- getList,
- handlerQuery,
- del,
- multipleSelection,
- toBatchDelete,
- expired,
- }
- }
|