|
@@ -0,0 +1,135 @@
|
|
|
+<template>
|
|
|
+ <div id="detail">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="main">
|
|
|
+ <el-col :span="24" class="back">
|
|
|
+ <el-button type="primary" size="mini" @click="back">返回</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="detail">
|
|
|
+ <data-form :data="form" :fields="formFields" :rules="rules" @save="toSave">
|
|
|
+ <template #options="{item}">
|
|
|
+ <template v-if="item.model === 'type'">
|
|
|
+ <el-option v-for="(i, index) in typeList" :key="`type${index}`" :label="i.name" :value="i.name"></el-option>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <template #custom="{item,form}">
|
|
|
+ <template v-if="item.model == 'img_url'">
|
|
|
+ <e-upload url="/files/img_url/upload" :limit="1" v-model="form.img_url" type="img_url" @upload="upload" @delete="onDelete"></e-upload>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="item.model == 'file_url'">
|
|
|
+ <e-upload url="/files/file_url/upload" :limit="1" v-model="form.file_url" type="file_url" @upload="upload" @delete="onDelete"></e-upload>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </el-col>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import _ from 'lodash';
|
|
|
+import dataForm from '@common/src/components/frame/form.vue';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: interview } = createNamespacedHelpers('interview');
|
|
|
+export default {
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+ name: 'detail',
|
|
|
+ props: {},
|
|
|
+ components: {
|
|
|
+ dataForm,
|
|
|
+ },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ formFields: [
|
|
|
+ { label: '信息类型', model: 'type', type: 'select' },
|
|
|
+ { label: '信息标题', model: 'title' },
|
|
|
+ { label: '信息来源', model: 'origin' },
|
|
|
+ { label: '发布时间', model: 'create_time', type: 'date' },
|
|
|
+ { label: '图片文件', model: 'img_url', custom: true },
|
|
|
+ { label: '视频文件', model: 'file_url', custom: true },
|
|
|
+ { label: '信息内容', model: 'content', type: 'editor' },
|
|
|
+ ],
|
|
|
+ form: {
|
|
|
+ img_url: [],
|
|
|
+ file_url: [],
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ type: [{ required: true, message: '请选择' }],
|
|
|
+ title: [{ required: true, message: '请输入信息标题' }],
|
|
|
+ origin: [{ required: true, message: '请输入信息来源' }],
|
|
|
+ publish_time: [{ required: true, message: '请输入发布时间' }],
|
|
|
+ },
|
|
|
+ typeList: [{ name: '科普场馆' }, { name: '科普体验' }, { name: '科普解读' }, { name: '黑科技' }],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ if (this.id) await this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...interview(['fetch', 'create', 'update']),
|
|
|
+ // 查询详情
|
|
|
+ async search() {
|
|
|
+ let res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `form`, res.data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交
|
|
|
+ async toSave({ data }) {
|
|
|
+ if (data.id) {
|
|
|
+ let res = await this.update(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$message({
|
|
|
+ message: '信息修改成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.user_id = this.user.id;
|
|
|
+ let res = await this.create(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$message({
|
|
|
+ message: '信息创建成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back() {
|
|
|
+ this.$router.push({ path: '/universal' });
|
|
|
+ },
|
|
|
+ upload({ type, data }) {
|
|
|
+ let file = _.cloneDeep(this.form[type]);
|
|
|
+ let newData = [{ name: data.name, url: data.uri }];
|
|
|
+ file.push(...newData);
|
|
|
+ this.$set(this.form, `${type}`, file);
|
|
|
+ },
|
|
|
+ onDelete(data) {
|
|
|
+ const index = this.form[data.type].findIndex(f => _.isEqual(f, data.file));
|
|
|
+ this.form[data.type].splice(index, 1);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {},
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.main {
|
|
|
+ .back {
|
|
|
+ text-align: right;
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|