|
@@ -0,0 +1,192 @@
|
|
|
+<template>
|
|
|
+ <div id="index">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="main">
|
|
|
+ <span v-if="display == 'list'">
|
|
|
+ <el-col :span="24" class="top">
|
|
|
+ <el-button type="primary" size="mini" @click="add()">添加</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="list">
|
|
|
+ <data-table :fields="fields" :opera="opera" :data="list" :total="total" @edit="toEdit" @delete="toDelete" @query="search"></data-table>
|
|
|
+ </el-col>
|
|
|
+ </span>
|
|
|
+ <span v-else>
|
|
|
+ <el-col :span="24" class="top">
|
|
|
+ <el-button type="primary" size="mini" @click="back()">返回</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24" class="detail">
|
|
|
+ <el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
|
+ <el-form-item label="名称" prop="title">
|
|
|
+ <el-input v-model="form.title" placeholder="请输入信息名称"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="作者" prop="publish">
|
|
|
+ <el-input v-model="form.publish" placeholder="请输入信息作者"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="信息来源" prop="orgin">
|
|
|
+ <el-input v-model="form.orgin" placeholder="请输入信息来源"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="发布时间">
|
|
|
+ <el-date-picker type="date" placeholder="请选择" value-format="yyyy-MM-dd" v-model="form.publish_time"></el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="图片">
|
|
|
+ <upload :limit="1" :data="form.picture" type="picture" :url="'/files/picture/upload'" @upload="uploadSuccess"></upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="内容">
|
|
|
+ <wang-editor v-model="form.content" placeholder="请输入信息内容"></wang-editor>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="附件">
|
|
|
+ <uploadfile
|
|
|
+ :limit="1"
|
|
|
+ :data="form.filepath"
|
|
|
+ type="filepath"
|
|
|
+ listType=""
|
|
|
+ :url="'/files/filepath/upload'"
|
|
|
+ @upload="uploadSuccess"
|
|
|
+ @delete="uploadDelete"
|
|
|
+ ></uploadfile>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="drawerSave">保存</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-col>
|
|
|
+ </span>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import dataTable from '@/components/data-table.vue';
|
|
|
+import WangEditor from '@/components/wang-editor.vue';
|
|
|
+import upload from '@/components/uploadone.vue';
|
|
|
+import uploadfile from '@/components/uploaddock.vue';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: scienceNews } = createNamespacedHelpers('scienceNews');
|
|
|
+export default {
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+ name: 'index',
|
|
|
+ props: {},
|
|
|
+ components: {
|
|
|
+ dataTable,
|
|
|
+ WangEditor,
|
|
|
+ upload,
|
|
|
+ uploadfile,
|
|
|
+ },
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ display: 'list',
|
|
|
+ opera: [
|
|
|
+ {
|
|
|
+ label: '修改',
|
|
|
+ icon: 'el-icon-edit',
|
|
|
+ method: 'edit',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ icon: 'el-icon-delete',
|
|
|
+ method: 'delete',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ fields: [
|
|
|
+ { label: '标题', prop: 'title', filter: 'input' },
|
|
|
+ { label: '作者', prop: 'publish' },
|
|
|
+ { label: '来源', prop: 'orgin' },
|
|
|
+ { label: '时间', prop: 'publish_time' },
|
|
|
+ ],
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ form: {},
|
|
|
+ rules: {
|
|
|
+ title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
|
|
|
+ orgin: [{ required: true, message: '请输入来源', trigger: 'blur' }],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ await this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...scienceNews(['query', 'fetch', 'create', 'update', 'delete']),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ let res = await this.query({ skip, limit, ...info });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `list`, res.data);
|
|
|
+ this.$set(this, `total`, res.total);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 添加
|
|
|
+ add() {
|
|
|
+ this.display = 'detail';
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ back() {
|
|
|
+ this.form = {};
|
|
|
+ this.display = 'list';
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
+ // 保存
|
|
|
+ async drawerSave() {
|
|
|
+ let data = this.form;
|
|
|
+ if (data.id) {
|
|
|
+ let res = await this.update(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$message({
|
|
|
+ message: '修改信息成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.uid = this.user.uid;
|
|
|
+ let res = await this.create(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$message({
|
|
|
+ message: '创建信息成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ this.back();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 修改
|
|
|
+ toEdit({ data }) {
|
|
|
+ this.$set(this, 'form', data);
|
|
|
+ this.display = 'detail';
|
|
|
+ },
|
|
|
+ // 删除
|
|
|
+ async toDelete({ data }) {
|
|
|
+ const res = await this.delete(data.id);
|
|
|
+ if (this.$checkRes(res, '删除成功', res.errmsg || '删除失败')) this.search();
|
|
|
+ },
|
|
|
+ // 图片
|
|
|
+ uploadSuccess({ type, data }) {
|
|
|
+ console.log(type, data.name);
|
|
|
+ this.$set(this.form, `${type}`, data.uri);
|
|
|
+ if (type == 'filepath') {
|
|
|
+ this.$set(this.form, `filepathname`, data.name);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 删除图片
|
|
|
+ uploadDelete(index) {
|
|
|
+ this.$set(this.form, `filepath`, null);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ },
|
|
|
+ watch: {},
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped>
|
|
|
+.main {
|
|
|
+ padding: 0 18px 0 0;
|
|
|
+ .top {
|
|
|
+ text-align: right;
|
|
|
+ padding: 10px 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|