123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <template>
- <div id="index">
- <el-row>
- <el-col :span="24" class="main animate__animated animate__backInRight">
- <span v-show="view === 'list'">
- <el-col :span="24" class="one"> <span>首页广告图标设置</span> </el-col>
- <el-col :span="24" class="two">
- <search-1 :form="searchForm" :typeList="typeList" @onSubmit="search" @toReset="toClose"></search-1>
- </el-col>
- <el-col :span="24" class="thr">
- <el-button type="primary" size="mini" @click="toAdd()">新增</el-button>
- </el-col>
- <el-col :span="24" class="four">
- <data-table
- :select="true"
- :selected="selected"
- @handleSelect="handleSelect"
- :fields="fields"
- :opera="opera"
- @query="search"
- :data="list"
- :total="total"
- @edit="toEdit"
- @del="toDel"
- >
- </data-table>
- </el-col>
- </span>
- <detail v-if="view === 'info'" :id="id" @toBack="toBack"></detail>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- const _ = require('lodash');
- import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
- const { mapActions } = createNamespacedHelpers('indexModule');
- const { mapActions: dictData } = createNamespacedHelpers('dictData');
- export default {
- name: 'index',
- props: {},
- components: {
- search1: () => import('./parts/search-1.vue'),
- detail: () => import('./detail.vue'),
- },
- data: function () {
- const that = this;
- return {
- view: 'list',
- // 列表
- opera: [
- { label: '修改', method: 'edit' },
- { label: '删除', method: 'del', confirm: true, type: 'danger' },
- ],
- fields: [
- { label: '名称', model: 'name' },
- {
- label: '跳转类型',
- model: 'to_type',
- format: (i) => {
- let data = that.typeList.find((f) => f.value == i);
- if (data) return data.label;
- else return '暂无';
- },
- },
- { label: '跳转到', model: 'to' },
- {
- label: '是否正在使用',
- model: 'status',
- format: (i) => {
- let data = that.statusList.find((f) => f.value == i);
- if (data) return data.label;
- else return '暂无';
- },
- },
- ],
- list: [],
- total: 0,
- // 查询
- searchForm: {},
- // 多选值
- selected: [],
- // 类型列表
- typeList: [],
- // 是否使用
- statusList: [],
- id: '',
- };
- },
- async created() {
- await this.searchOther();
- await this.search();
- },
- methods: {
- ...dictData({ dictQuery: 'query' }),
- ...mapActions(['query', 'fetch', 'create', 'update', 'delete']),
- // 查询
- async search({ skip = 0, limit = this.$limit, ...info } = {}) {
- const condition = _.cloneDeep(this.searchForm);
- let res = await this.query({ skip, limit, ...condition, ...info });
- if (this.$checkRes(res)) {
- this.$set(this, 'list', res.data);
- this.$set(this, 'total', res.total);
- }
- },
- // 新增
- toAdd() {
- let id = '';
- this.$set(this, `id`, id);
- this.$set(this, `view`, 'info');
- },
- // 修改
- async toEdit({ data }) {
- this.$set(this, `id`, data.id);
- this.$set(this, `view`, 'info');
- },
- toBack() {
- this.view = 'list';
- },
- // 删除
- async toDel({ data }) {
- let res = await this.delete(data._id);
- if (this.$checkRes(res)) {
- this.$message({ type: `success`, message: `刪除信息成功` });
- this.search();
- }
- },
- // 重置
- toClose() {
- this.searchForm = {};
- this.search();
- },
- // 多选
- handleSelect(data) {
- this.$set(this, `selected`, data);
- },
- // 查询其他信息
- async searchOther() {
- let res;
- // 类型
- res = await this.dictQuery({ code: 'to_type' });
- if (this.$checkRes(res)) {
- this.$set(this, `typeList`, res.data);
- }
- res = await this.dictQuery({ code: 'status' });
- if (this.$checkRes(res)) {
- this.$set(this, `statusList`, res.data);
- }
- },
- },
- computed: {
- ...mapState(['user']),
- },
- metaInfo() {
- return { title: this.$route.meta.title };
- },
- watch: {
- test: {
- deep: true,
- immediate: true,
- handler(val) {},
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .main {
- .one {
- margin: 0 0 10px 0;
- span:nth-child(1) {
- font-size: 20px;
- font-weight: 700;
- margin-right: 10px;
- }
- }
- .two {
- margin: 0 0 10px 0;
- }
- .thr {
- margin: 0 0 10px 0;
- }
- }
- </style>
|