|
@@ -0,0 +1,134 @@
|
|
|
+<template>
|
|
|
+ <div id="detail">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="main">
|
|
|
+ <el-col :span="24" class="top">
|
|
|
+ <el-button type="primary" size="mini" @click="back">返回</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="down" v-loading="loading">
|
|
|
+ <data-form :data="form" :fields="fields" :rules="{}" @save="toSave" v-if="!loading" :useEnter="false">
|
|
|
+ <template #custom="{item,form}">
|
|
|
+ <template v-if="item.model == 'filepath'">
|
|
|
+ <upload
|
|
|
+ :limit="1"
|
|
|
+ :data="form.filepath"
|
|
|
+ listType=""
|
|
|
+ type="filepath"
|
|
|
+ :url="'/files/filepath/upload'"
|
|
|
+ @upload="uploadSuccess"
|
|
|
+ @delete="uploadDelete"
|
|
|
+ ></upload>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="item.model == 'is_show'">
|
|
|
+ <el-switch v-model="form.is_show" active-color="#13ce66" inactive-color="#ff4949" active-text="展示" inactive-text="不展示"> </el-switch>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ <template #radios="{item}">
|
|
|
+ <template v-if="item.model === 'is_show'">
|
|
|
+ <el-radio :label="false">不展示</el-radio>
|
|
|
+ <el-radio :label="true">展示</el-radio>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </el-col>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import dataForm from '@common/src/components/frame/form.vue';
|
|
|
+import upload from '@common/src/components/frame/upload.vue';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: mapdimension } = createNamespacedHelpers('dimension');
|
|
|
+export default {
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+ name: 'detail',
|
|
|
+ props: {},
|
|
|
+ components: { dataForm, upload },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ fields: [
|
|
|
+ { label: '是否展示', model: 'is_show', type: 'radio' },
|
|
|
+ { label: '信息标题', model: 'title' },
|
|
|
+ { label: '发布时间', model: 'publish_time', type: 'date' },
|
|
|
+ { label: '信息来源', model: 'origin' },
|
|
|
+ { label: '信息简介', model: 'brief', type: 'textarea' },
|
|
|
+ { label: '内容', model: 'content', type: 'editor' },
|
|
|
+ { label: '附件文件', model: 'filepath', custom: true },
|
|
|
+ ],
|
|
|
+ form: {},
|
|
|
+ loading: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ if (this.id) {
|
|
|
+ await this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapdimension(['fetch', 'update', 'create']),
|
|
|
+ async search() {
|
|
|
+ this.loading = true;
|
|
|
+ let res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `form`, res.data);
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 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: '/dimension' });
|
|
|
+ },
|
|
|
+ // 图片上传
|
|
|
+ uploadSuccess({ type, data }) {
|
|
|
+ this.$set(this.form, `${type}`, { url: data.uri, name: data.name });
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ uploadDelete(data) {
|
|
|
+ this.$set(this.form, `${data.type}`, {});
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {},
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.main {
|
|
|
+ .top {
|
|
|
+ text-align: right;
|
|
|
+ margin: 0 0 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|