irc_web/src/views/dictionary/template/file/fileForm.vue

224 lines
5.8 KiB
Vue

<template>
<base-model :config="config">
<div slot="dialog-body">
<el-form
ref="fileForm"
:model="form"
label-width="100px"
size="small"
:rules="rules"
>
<div class="base-dialog-body">
<el-form-item :label="$t('dictionary:file:form:name')" prop="Name">
<el-input v-model="form.Name" />
</el-form-item>
<el-form-item
:label="$t('dictionary:file:form:nameCN')"
prop="NameCN"
>
<el-input v-model="form.NameCN" />
</el-form-item>
<el-form-item
:label="$t('dictionary:browser:form:ArchiveTypeEnum')"
prop="ArchiveTypeEnum"
>
<el-select
v-model="form.ArchiveTypeEnum"
clearable
placeholder=""
style="width: 100%"
>
<el-option
v-for="item in $d.ArchiveType"
:key="item.id"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item
:label="$t('dictionary:browser:form:SubIdentificationEnum')"
prop="SubIdentificationEnum"
>
<el-select
style="width: 100%"
v-model="form.SubIdentificationEnum"
clearable
placeholder=""
>
<el-option
v-for="item in $d.SubIdentification"
:key="item.id"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('dictionary:file:form:IsEnable')">
<el-switch
v-model="form.IsEnable"
:active-value="true"
:inactive-value="false"
>
</el-switch>
</el-form-item>
<el-form-item :label="$t('dictionary:file:form:IsConfirmRecord')">
<el-switch
v-model="form.IsConfirmRecord"
:active-value="true"
:inactive-value="false"
>
</el-switch>
</el-form-item>
</div>
</el-form>
</div>
<div slot="dialog-footer">
<el-button size="small" @click="canel">
{{ $t('dictionary:browser:button:canel') }}
</el-button>
<el-button size="small" type="primary" :loading="loading" @click="save">
{{ $t('dictionary:browser:button:save') }}
</el-button>
</div>
</base-model>
</template>
<script>
import baseModel from '@/components/BaseModel'
import { addOrUpdateSysFileType } from '@/api/dictionary'
export default {
props: {
config: {
required: true,
default: () => {
return {}
},
},
data: {
required: true,
default: () => {
return {}
},
},
},
components: {
'base-model': baseModel,
},
data() {
return {
form: {
ArchiveTypeEnum: null,
IsConfirmRecord: true,
IsEnable: true,
Name: null,
NameCN: null,
SubIdentificationEnum: null,
},
rules: {
Name: [
{
required: true,
message: this.$t('common:ruleMessage:specify'),
trigger: ['blur', 'change'],
},
],
NameCN: [
{
required: true,
message: this.$t('common:ruleMessage:specify'),
trigger: ['blur', 'change'],
},
],
SubIdentificationEnum: [
{
required: true,
message: this.$t('common:ruleMessage:select'),
trigger: ['blur', 'change'],
},
],
ArchiveTypeEnum: [
{
required: true,
message: this.$t('common:ruleMessage:select'),
trigger: ['blur', 'change'],
},
],
},
fileList: [],
loading: false,
}
},
created() {
if (this.config.status === 'edit') {
Object.keys(this.form).forEach((key) => {
this.form[key] = this.data[key]
})
if (this.form.FileName) {
this.fileList[0] = {
name: this.form.FileName,
path: this.form.Path,
fullPath: this.form.Path,
}
}
}
},
methods: {
async save() {
try {
let validate = await this.$refs.fileForm.validate()
if (!validate) return false
this.loading = true
if (this.config.status === 'edit') {
this.form.Id = this.data.Id
}
let res = await addOrUpdateSysFileType(this.form)
if (res.IsSuccess) {
this.$emit('close')
this.$emit('getList')
}
} catch (err) {
console.log(err)
this.loading = false
}
},
canel() {
this.$emit('close')
},
handleRemoveFile() {
this.form.FileName = null
this.form.Path = null
this.fileList = []
},
beforeUpload() {
if (this.fileList.length > 0) {
this.$alert(this.$t('dictionary:bbrowser:msg:message1'))
return
}
},
handlePreview(row, r2) {
if (row.fullPath) {
window.open(row.fullPath, '_blank')
}
},
async handleUploadFile(param) {
this.loading = true
var file = await this.fileToBlob(param.file)
const res = await this.OSSclient.put(
`/System/Browser/${param.file.name}`,
file
)
this.fileList.push({
name: param.file.name,
path: this.$getObjectName(res.url),
fullPath: this.$getObjectName(res.url),
url: this.$getObjectName(res.url),
})
this.form.Path = this.$getObjectName(res.url)
this.form.FileName = param.file.name
this.loading = false
},
},
}
</script>