项目初始化
This commit is contained in:
122
web/src/views/backend/security/dataRecycle/index.vue
Normal file
122
web/src/views/backend/security/dataRecycle/index.vue
Normal file
@@ -0,0 +1,122 @@
|
||||
<template>
|
||||
<div class="default-main ba-table-box">
|
||||
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
|
||||
|
||||
<!-- 表格顶部菜单 -->
|
||||
<TableHeader
|
||||
:buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||
:quick-search-placeholder="t('Quick search placeholder', { fields: t('security.dataRecycle.Rule name') })"
|
||||
/>
|
||||
|
||||
<!-- 表格 -->
|
||||
<!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
|
||||
<Table ref="tableRef" />
|
||||
|
||||
<!-- 表单 -->
|
||||
<PopupForm />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, provide, useTemplateRef } from 'vue'
|
||||
import baTableClass from '/@/utils/baTable'
|
||||
import { add, url } from '/@/api/backend/security/dataRecycle'
|
||||
import PopupForm from './popupForm.vue'
|
||||
import Table from '/@/components/table/index.vue'
|
||||
import TableHeader from '/@/components/table/header/index.vue'
|
||||
import { defaultOptButtons } from '/@/components/table'
|
||||
import { baTableApi } from '/@/api/common'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
defineOptions({
|
||||
name: 'security/dataRecycle',
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const tableRef = useTemplateRef('tableRef')
|
||||
|
||||
const baTable = new baTableClass(
|
||||
new baTableApi(url),
|
||||
{
|
||||
column: [
|
||||
{ type: 'selection', align: 'center', operator: false },
|
||||
{ label: 'ID', prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
|
||||
{ label: t('security.dataRecycle.Rule name'), prop: 'name', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||
{
|
||||
label: t('security.dataRecycle.controller'),
|
||||
prop: 'controller',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('Connection'),
|
||||
prop: 'connection',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('security.dataRecycle.data sheet'),
|
||||
prop: 'data_table',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('security.dataRecycle.Data table primary key'),
|
||||
prop: 'primary_key',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
label: t('State'),
|
||||
prop: 'status',
|
||||
align: 'center',
|
||||
render: 'tag',
|
||||
custom: { 0: 'danger', 1: 'success' },
|
||||
replaceValue: { 0: t('Disable'), 1: t('security.dataRecycle.Deleting monitoring') },
|
||||
},
|
||||
{ label: t('Update time'), prop: 'update_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
||||
{ label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
|
||||
{
|
||||
label: t('Operate'),
|
||||
align: 'center',
|
||||
width: '130',
|
||||
render: 'buttons',
|
||||
buttons: defaultOptButtons(['edit', 'delete']),
|
||||
operator: false,
|
||||
},
|
||||
],
|
||||
dblClickNotEditColumn: [undefined, 'status'],
|
||||
},
|
||||
{
|
||||
defaultItems: {
|
||||
status: 1,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// 获取控制器和数据表数据
|
||||
baTable.before.toggleForm = ({ operate }) => {
|
||||
if (operate == 'Add' || operate == 'Edit') {
|
||||
baTable.form.loading = true
|
||||
add().then((res) => {
|
||||
baTable.form.extend!.controllerList = res.data.controllers
|
||||
baTable.form.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
provide('baTable', baTable)
|
||||
|
||||
onMounted(() => {
|
||||
baTable.table.ref = tableRef.value
|
||||
baTable.mount()
|
||||
baTable.getData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
152
web/src/views/backend/security/dataRecycle/popupForm.vue
Normal file
152
web/src/views/backend/security/dataRecycle/popupForm.vue
Normal file
@@ -0,0 +1,152 @@
|
||||
<template>
|
||||
<!-- 对话框表单 -->
|
||||
<el-dialog
|
||||
class="ba-operate-dialog"
|
||||
:close-on-click-modal="false"
|
||||
:model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
|
||||
@close="baTable.toggleForm"
|
||||
>
|
||||
<template #header>
|
||||
<div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
|
||||
{{ baTable.form.operate ? t(baTable.form.operate) : '' }}
|
||||
</div>
|
||||
</template>
|
||||
<el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
|
||||
<div
|
||||
class="ba-operate-form"
|
||||
:class="'ba-' + baTable.form.operate + '-form'"
|
||||
:style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
|
||||
>
|
||||
<el-form
|
||||
v-if="!baTable.form.loading"
|
||||
ref="formRef"
|
||||
@keyup.enter="baTable.onSubmit(formRef)"
|
||||
:model="baTable.form.items"
|
||||
:label-position="config.layout.shrink ? 'top' : 'right'"
|
||||
:label-width="baTable.form.labelWidth + 'px'"
|
||||
:rules="rules"
|
||||
>
|
||||
<FormItem
|
||||
:label="t('security.dataRecycle.Rule name')"
|
||||
type="string"
|
||||
v-model="baTable.form.items!.name"
|
||||
prop="name"
|
||||
:placeholder="t('security.dataRecycle.The rule name helps to identify deleted data later')"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('security.dataRecycle.controller')"
|
||||
type="select"
|
||||
v-model="baTable.form.items!.controller"
|
||||
prop="controller"
|
||||
:input-attr="{ content: baTable.form.extend!.controllerList }"
|
||||
:placeholder="t('security.dataRecycle.The data collection mechanism will monitor delete operations under this controller')"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('Database connection')"
|
||||
v-model="baTable.form.items!.connection"
|
||||
type="remoteSelect"
|
||||
:block-help="t('Database connection help')"
|
||||
:input-attr="{
|
||||
pk: 'key',
|
||||
field: 'key',
|
||||
remoteUrl: getDatabaseConnectionListUrl,
|
||||
valueOnClear: '',
|
||||
}"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('security.dataRecycle.Corresponding data sheet')"
|
||||
type="remoteSelect"
|
||||
v-model="baTable.form.items!.data_table"
|
||||
:key="baTable.form.items!.connection"
|
||||
:input-attr="{
|
||||
pk: 'table',
|
||||
field: 'comment',
|
||||
params: {
|
||||
connection: baTable.form.items!.connection,
|
||||
samePrefix: 1,
|
||||
excludeTable: ['area', 'token', 'captcha', 'admin_group_access', 'user_money_log', 'user_score_log'],
|
||||
},
|
||||
remoteUrl: getTableListUrl,
|
||||
onRow: onTableChange,
|
||||
}"
|
||||
prop="data_table"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('security.dataRecycle.Data table primary key')"
|
||||
type="string"
|
||||
v-model="baTable.form.items!.primary_key"
|
||||
prop="primary_key"
|
||||
/>
|
||||
<FormItem
|
||||
:label="t('State')"
|
||||
type="radio"
|
||||
v-model="baTable.form.items!.status"
|
||||
prop="status"
|
||||
:input-attr="{
|
||||
border: true,
|
||||
content: { 0: t('Disable'), 1: t('Enable') },
|
||||
}"
|
||||
/>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
<template #footer>
|
||||
<div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
|
||||
<el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
|
||||
<el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
|
||||
{{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, inject, useTemplateRef } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type baTableClass from '/@/utils/baTable'
|
||||
import FormItem from '/@/components/formItem/index.vue'
|
||||
import type { FormItemRule } from 'element-plus'
|
||||
import { buildValidatorData } from '/@/utils/validate'
|
||||
import { getTablePk, getTableListUrl, getDatabaseConnectionListUrl } from '/@/api/common'
|
||||
import { useConfig } from '/@/stores/config'
|
||||
|
||||
const config = useConfig()
|
||||
const formRef = useTemplateRef('formRef')
|
||||
const baTable = inject('baTable') as baTableClass
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||
name: [buildValidatorData({ name: 'required', title: t('security.dataRecycle.Rule name') })],
|
||||
controller: [
|
||||
buildValidatorData({
|
||||
name: 'required',
|
||||
trigger: 'change',
|
||||
message: t('Please select field', { field: t('security.dataRecycle.controller') }),
|
||||
}),
|
||||
],
|
||||
data_table: [
|
||||
buildValidatorData({
|
||||
name: 'required',
|
||||
trigger: 'change',
|
||||
message: t('Please select field', { field: t('security.dataRecycle.data sheet') }),
|
||||
}),
|
||||
],
|
||||
primary_key: [buildValidatorData({ name: 'required', trigger: 'change', title: t('security.dataRecycle.Data table primary key') })],
|
||||
})
|
||||
|
||||
const onTableChange = () => {
|
||||
if (!baTable.form.items!.data_table) return
|
||||
getTablePk(baTable.form.items!.data_table, baTable.form.items!.connection).then((res) => {
|
||||
baTable.form.items!.primary_key = res.data.pk
|
||||
baTable.form.defaultItems!.primary_key = res.data.pk
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.ba-el-radio {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user