123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <template>
- <div id="add">
- <el-row>
- <el-col :span="24" class="main animate__animated animate__backInRight">
- <el-col :span="24" class="one">
- <c-search :is_title="true" :is_back="true" @toBack="toBack"></c-search>
- </el-col>
- <el-col :span="24" class="two">
- <data-form :fields="fields" :form="form" :rules="{}" @save="toSave" :span="24">
- <template #type>
- <el-option v-for="i in typeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
- </template>
- <template #place>
- <el-option v-for="i in placeList" :key="i._id" :label="i.label" :value="i.value"></el-option>
- </template>
- <template #is_use>
- <el-option v-for="i in isuseList" :key="i._id" :label="i.label" :value="i.value"></el-option>
- </template>
- <template #img_url="{ item }">
- <c-upload v-model="form[item.model]" url="/files/projectadmin/imgurl/upload" accept="" listType="text" :limit="1"></c-upload>
- </template>
- <template #file_url="{ item }">
- <c-upload v-model="form[item.model]" url="/files/projectadmin/imgurl/upload" accept="" listType="text" :limit="1"></c-upload>
- </template>
- <template #content="{ item }">
- <c-editor v-model="form[item.model]" url="/files/projectadmin/other/upload" />
- </template>
- </data-form>
- </el-col>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import { mapState, createNamespacedHelpers } from 'vuex';
- const { mapActions } = createNamespacedHelpers('news');
- const { mapActions: dictdata } = createNamespacedHelpers('dictdata');
- export default {
- name: 'add',
- props: {},
- components: {},
- data: function () {
- return {
- fields: [
- { label: '新闻类型', model: 'type', type: 'select' },
- { label: '名称', model: 'title' },
- { label: '来源', model: 'origin' },
- { label: '发布时间', model: 'create_time', type: 'date' },
- { label: '简介', model: 'brief', type: 'textarea' },
- { label: '图片', model: 'img_url', custom: true },
- { label: '文件', model: 'file_url', custom: true },
- { label: '内容', model: 'content', custom: true },
- { label: '展示位置', model: 'place', type: 'select' },
- { label: '是否启用', model: 'is_use', type: 'select' },
- ],
- form: {},
- // 是否启用
- isuseList: [],
- // 展示位置
- placeList: [],
- // 新闻类型
- typeList: [],
- };
- },
- async created() {
- await this.searchOther();
- await this.search();
- },
- methods: {
- ...mapActions(['fetch', 'create', 'update']),
- ...dictdata({ dQuery: 'query' }),
- async search() {
- if (this.id) {
- let res = await this.fetch(this.id);
- if (this.$checkRes(res)) {
- this.$set(this, `form`, res.data);
- }
- }
- },
- // 保存信息
- async toSave({ data }) {
- let res;
- if (data.id) res = await this.update(data);
- else res = await this.create(data);
- if (this.$checkRes(res, `维护信息成功`, res.errmsg)) this.toBack();
- },
- // 字典
- async searchOther() {
- let res;
- // 是否启用
- res = await this.dQuery({ type: 'is_use' });
- if (this.$checkRes(res)) {
- this.$set(this, `isuseList`, res.data);
- }
- // 展示位置
- res = await this.dQuery({ type: 'banner_place' });
- if (this.$checkRes(res)) {
- this.$set(this, `placeList`, res.data);
- }
- // 新闻类型
- res = await this.dQuery({ type: 'news_type' });
- if (this.$checkRes(res)) {
- this.$set(this, `typeList`, res.data);
- }
- },
- // 返回
- toBack() {
- window.history.go('-1');
- },
- },
- computed: {
- ...mapState(['user']),
- id() {
- return this.$route.query.id;
- },
- },
- metaInfo() {
- return { title: this.$route.meta.title };
- },
- watch: {
- test: {
- deep: true,
- immediate: true,
- handler(val) {},
- },
- },
- };
- </script>
- <style lang="less" scoped></style>
|