项目初始化
This commit is contained in:
12
web/src/views/backend/routine/attachment/index.ts
Normal file
12
web/src/views/backend/routine/attachment/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { buildSuffixSvgUrl } from '/@/api/common'
|
||||
|
||||
/**
|
||||
* 表格和表单中文件预览图的生成
|
||||
*/
|
||||
export const previewRenderFormatter = (row: TableRow, column: TableColumn, cellValue: string) => {
|
||||
const imgSuffix = ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp']
|
||||
if (imgSuffix.includes(cellValue)) {
|
||||
return row.full_url
|
||||
}
|
||||
return buildSuffixSvgUrl(cellValue)
|
||||
}
|
||||
184
web/src/views/backend/routine/attachment/index.vue
Normal file
184
web/src/views/backend/routine/attachment/index.vue
Normal file
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<div class="default-main">
|
||||
<div class="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', 'edit', 'comSearch', 'quickSearch', 'columnDisplay']"
|
||||
:quick-search-placeholder="t('Quick search placeholder', { fields: t('utils.Original name') })"
|
||||
>
|
||||
<el-popconfirm
|
||||
v-if="auth('del')"
|
||||
@confirm="baTable.onTableHeaderAction('delete', {})"
|
||||
:confirm-button-text="t('Delete')"
|
||||
:cancel-button-text="t('Cancel')"
|
||||
confirmButtonType="danger"
|
||||
:title="t('routine.attachment.Files and records will be deleted at the same time Are you sure?')"
|
||||
:disabled="baTable.table.selection!.length > 0 ? false : true"
|
||||
>
|
||||
<template #reference>
|
||||
<div class="mlr-12">
|
||||
<el-tooltip :content="t('Delete selected row')" placement="top">
|
||||
<el-button
|
||||
v-blur
|
||||
:disabled="baTable.table.selection!.length > 0 ? false : true"
|
||||
class="table-header-operate"
|
||||
type="danger"
|
||||
>
|
||||
<Icon color="#ffffff" name="fa fa-trash" />
|
||||
<span class="table-header-operate-text">{{ t('Delete') }}</span>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</template>
|
||||
</el-popconfirm>
|
||||
</TableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<!-- 要使用`el-table`组件原有的属性,直接加在Table标签上即可 -->
|
||||
<Table ref="tableRef" />
|
||||
|
||||
<!-- 编辑和新增表单 -->
|
||||
<PopupForm />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, provide, useTemplateRef } from 'vue'
|
||||
import PopupForm from './popupForm.vue'
|
||||
import Table from '/@/components/table/index.vue'
|
||||
import TableHeader from '/@/components/table/header/index.vue'
|
||||
import baTableClass from '/@/utils/baTable'
|
||||
import { defaultOptButtons } from '/@/components/table'
|
||||
import { previewRenderFormatter } from './index'
|
||||
import { baTableApi } from '/@/api/common'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { auth } from '/@/utils/common'
|
||||
|
||||
defineOptions({
|
||||
name: 'routine/attachment',
|
||||
})
|
||||
|
||||
const { t } = useI18n()
|
||||
const tableRef = useTemplateRef('tableRef')
|
||||
|
||||
const optBtn = defaultOptButtons(['edit', 'delete'])
|
||||
optBtn[1].popconfirm = {
|
||||
...optBtn[1].popconfirm,
|
||||
title: t('routine.attachment.Files and records will be deleted at the same time Are you sure?'),
|
||||
}
|
||||
|
||||
const baTable = new baTableClass(new baTableApi('/admin/routine.Attachment/'), {
|
||||
column: [
|
||||
{ type: 'selection', align: 'center', operator: false },
|
||||
{ label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
|
||||
{ label: t('utils.Breakdown'), prop: 'topic', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
|
||||
{
|
||||
label: t('routine.attachment.Upload administrator'),
|
||||
prop: 'admin.nickname',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('routine.attachment.Upload user'),
|
||||
prop: 'user.nickname',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('utils.size'),
|
||||
prop: 'size',
|
||||
align: 'center',
|
||||
formatter: (row: TableRow, column: TableColumn, cellValue: string) => {
|
||||
const size = parseFloat(cellValue)
|
||||
const i = Math.floor(Math.log(size) / Math.log(1024))
|
||||
return (size / Math.pow(1024, i)).toFixed(i < 1 ? 0 : 2) + ' ' + ['B', 'KB', 'MB', 'GB', 'TB'][i]
|
||||
},
|
||||
operator: 'RANGE',
|
||||
sortable: 'custom',
|
||||
operatorPlaceholder: 'bytes',
|
||||
},
|
||||
{
|
||||
label: t('utils.type'),
|
||||
prop: 'mimetype',
|
||||
align: 'center',
|
||||
operator: 'LIKE',
|
||||
showOverflowTooltip: true,
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('utils.preview'),
|
||||
prop: 'suffix',
|
||||
align: 'center',
|
||||
formatter: previewRenderFormatter,
|
||||
render: 'image',
|
||||
operator: false,
|
||||
},
|
||||
{
|
||||
label: t('utils.Upload (Reference) times'),
|
||||
prop: 'quote',
|
||||
align: 'center',
|
||||
width: 150,
|
||||
operator: 'RANGE',
|
||||
sortable: 'custom',
|
||||
},
|
||||
{
|
||||
label: t('utils.Original name'),
|
||||
prop: 'name',
|
||||
align: 'center',
|
||||
showOverflowTooltip: true,
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('routine.attachment.Storage mode'),
|
||||
prop: 'storage',
|
||||
align: 'center',
|
||||
width: 100,
|
||||
operator: 'LIKE',
|
||||
operatorPlaceholder: t('Fuzzy query'),
|
||||
},
|
||||
{
|
||||
label: t('utils.Last upload time'),
|
||||
prop: 'last_upload_time',
|
||||
align: 'center',
|
||||
render: 'datetime',
|
||||
operator: 'RANGE',
|
||||
width: 160,
|
||||
sortable: 'custom',
|
||||
},
|
||||
{
|
||||
label: t('Operate'),
|
||||
align: 'center',
|
||||
width: '100',
|
||||
render: 'buttons',
|
||||
buttons: optBtn,
|
||||
operator: false,
|
||||
},
|
||||
],
|
||||
defaultOrder: { prop: 'last_upload_time', order: 'desc' },
|
||||
})
|
||||
|
||||
provide('baTable', baTable)
|
||||
|
||||
onMounted(() => {
|
||||
baTable.table.ref = tableRef.value
|
||||
baTable.mount()
|
||||
baTable.getData()?.then(() => {
|
||||
baTable.initSort()
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.table-header-operate {
|
||||
margin-left: 12px;
|
||||
}
|
||||
.table-header-operate-text {
|
||||
margin-left: 6px;
|
||||
}
|
||||
</style>
|
||||
150
web/src/views/backend/routine/attachment/popupForm.vue
Normal file
150
web/src/views/backend/routine/attachment/popupForm.vue
Normal file
@@ -0,0 +1,150 @@
|
||||
<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
|
||||
@keyup.enter="baTable.onSubmit()"
|
||||
v-model="baTable.form.items"
|
||||
:label-position="config.layout.shrink ? 'top' : 'right'"
|
||||
:label-width="baTable.form.labelWidth + 'px'"
|
||||
>
|
||||
<el-form-item :label="t('utils.preview')">
|
||||
<el-image
|
||||
class="preview-img"
|
||||
:preview-src-list="[baTable.form.items!.full_url]"
|
||||
:src="previewRenderFormatter(baTable.form.items!, {}, baTable.form.items!.suffix)"
|
||||
></el-image>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('utils.Breakdown')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.topic"
|
||||
type="string"
|
||||
:placeholder="
|
||||
t(
|
||||
'routine.attachment.The file is saved in the directory, and the file will not be automatically transferred if the record is modified'
|
||||
)
|
||||
"
|
||||
readonly
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.Physical path')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.url"
|
||||
type="string"
|
||||
:placeholder="t('routine.attachment.File saving path Modifying records will not automatically transfer files')"
|
||||
readonly
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.image width')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.width"
|
||||
type="number"
|
||||
:placeholder="t('routine.attachment.Width of picture file')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.Picture height')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.height"
|
||||
type="number"
|
||||
:placeholder="t('routine.attachment.Height of picture file')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('utils.Original name')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.name"
|
||||
type="string"
|
||||
:placeholder="t('routine.attachment.Original file name')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.file size')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.size"
|
||||
type="number"
|
||||
:placeholder="t('routine.attachment.File size (bytes)')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.mime type')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.mimetype"
|
||||
type="string"
|
||||
:placeholder="t('routine.attachment.File MIME type')"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('utils.Upload (Reference) times')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.quote"
|
||||
type="number"
|
||||
:placeholder="t('routine.attachment.Upload (Reference) times of this file')"
|
||||
></el-input>
|
||||
<span class="block-help">
|
||||
{{
|
||||
t(
|
||||
'routine.attachment.When the same file is uploaded multiple times, only one attachment record will be saved and added'
|
||||
)
|
||||
}}
|
||||
</span>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.Storage mode')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.storage"
|
||||
type="string"
|
||||
:placeholder="t('routine.attachment.Storage mode')"
|
||||
readonly
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="t('routine.attachment.SHA1 code')">
|
||||
<el-input
|
||||
v-model="baTable.form.items!.sha1"
|
||||
type="string"
|
||||
:placeholder="t('routine.attachment.SHA1 encoding of file')"
|
||||
readonly
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</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()" type="primary">
|
||||
{{ 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 { inject } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import type baTableClass from '/@/utils/baTable'
|
||||
import { previewRenderFormatter } from './index'
|
||||
import { useConfig } from '/@/stores/config'
|
||||
|
||||
const config = useConfig()
|
||||
const baTable = inject('baTable') as baTableClass
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.preview-img {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user