|
@@ -0,0 +1,116 @@
|
|
|
+<template>
|
|
|
+ <div id="index">
|
|
|
+ <template v-if="view === 'list'">
|
|
|
+ <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search" @edit="toEdit" @delete="toDelete" operaWidth="auto">
|
|
|
+ <template #btn>
|
|
|
+ <el-button type="primary" size="mini" @click="toAdd">添加</el-button>
|
|
|
+ </template>
|
|
|
+ </data-table>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <detail v-model="form" @back="view = 'list'" @save="toSave" />
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import detail from './detail.vue';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: news } = createNamespacedHelpers('news');
|
|
|
+export default {
|
|
|
+ name: 'index',
|
|
|
+ props: {},
|
|
|
+ components: { detail },
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ view: 'list',
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ fields: [
|
|
|
+ { label: '标题', model: 'title' },
|
|
|
+ { label: '来源', model: 'origin' },
|
|
|
+ { label: '时间', model: 'create_time' },
|
|
|
+ { label: '类型', model: 'type', format: (i) => (i === '0' ? '国内新闻' : '健康咨询') },
|
|
|
+ ],
|
|
|
+ opera: [
|
|
|
+ {
|
|
|
+ label: '编辑',
|
|
|
+ method: 'edit',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ type: 'danger',
|
|
|
+ method: 'delete',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ form: {
|
|
|
+ img: [],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...news(['query', 'create', 'update', 'delete']),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ const res = await this.query({ skip, limit, ...info });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
+ this.$set(this, `total`, res.total);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toSave(data) {
|
|
|
+ let dup = _.cloneDeep(data);
|
|
|
+ let res;
|
|
|
+ if (dup._id) res = await this.update(dup);
|
|
|
+ else res = await this.create(dup);
|
|
|
+ if (this.$checkRes(res, '操作成功', res.errmsg || '操作失败')) {
|
|
|
+ this.search();
|
|
|
+ this.view = 'list';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toDelete({ data }) {
|
|
|
+ this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ .then(async () => {
|
|
|
+ const res = await this.delete(data._id);
|
|
|
+ if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) {
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ },
|
|
|
+ async toAdd() {
|
|
|
+ this.formInit();
|
|
|
+ this.view = 'detail';
|
|
|
+ },
|
|
|
+ toEdit({ data }) {
|
|
|
+ console.log(data);
|
|
|
+ this.$set(this, 'form', _.cloneDeep(data));
|
|
|
+ this.view = 'detail';
|
|
|
+ },
|
|
|
+ formInit() {
|
|
|
+ const form = {
|
|
|
+ img: [],
|
|
|
+ };
|
|
|
+ this.$set(this, `form`, form);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped></style>
|