| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- import { reactive } from 'vue'
- import { list, remove, fileList, fileRemove, batchDelete, fileBatchDelete } from '@/api/audit'
- import { ElMessage, ElMessageBox } from 'element-plus'
- import { formatTime } from '@/utils/time'
- import { T } from '@/utils/i18n'
- import { downBlob, jsonToCsv } from '@/utils/file'
- export function useRepositories () {
- const listRes = reactive({
- list: [], total: 0, loading: false,
- })
- const listQuery = reactive({
- page: 1,
- page_size: 10,
- peer_id: null,
- from_peer: null,
- })
- const getList = async () => {
- listRes.loading = true
- const res = await list(listQuery).catch(_ => false)
- listRes.loading = false
- if (res) {
- listRes.list = res.data.list.map(item => {
- item.close_time = item.close_time ? formatTime(item.close_time * 1000) : '-'
- return item
- })
- 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 remove({ id: row.id }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const batchdel = async (rows) => {
- const ids = rows.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 batchDelete({ ids }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const toExport = async () => {
- const q = { ...listQuery }
- q.page_size = 1000000
- q.page = 1
- const res = await list(q).catch(_ => false)
- if (res) {
- const csv = jsonToCsv(res.data.list)
- downBlob(csv, 'connectLog.csv')
- }
- }
- return {
- listRes,
- listQuery,
- getList,
- handlerQuery,
- del,
- batchdel,
- toExport,
- }
- }
- export function useFileRepositories () {
- const listRes = reactive({
- list: [], total: 0, loading: false,
- })
- const listQuery = reactive({
- page: 1,
- page_size: 10,
- peer_id: null,
- from_peer: null,
- })
- const getList = async () => {
- listRes.loading = true
- const res = await fileList(listQuery).catch(_ => false)
- listRes.loading = false
- if (res) {
- listRes.list = res.data.list.map(item => {
- item.info = item.info ? JSON.parse(item.info) : '-'
- return item
- })
- 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 fileRemove({ id: row.id }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const batchdel = async (rows) => {
- const ids = rows.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 fileBatchDelete({ ids }).catch(_ => false)
- if (res) {
- ElMessage.success(T('OperationSuccess'))
- getList()
- }
- }
- const toExport = async () => {
- const q = { ...listQuery }
- q.page_size = 1000000
- q.page = 1
- const res = await fileList(q).catch(_ => false)
- if (res) {
- const csv = jsonToCsv(res.data.list)
- downBlob(csv, 'fileTransformLog.csv')
- }
- }
- return {
- listRes,
- listQuery,
- getList,
- handlerQuery,
- del,
- batchdel,
- toExport,
- }
- }
|