|
@@ -0,0 +1,171 @@
|
|
|
|
+<template>
|
|
|
|
+ <div id="index">
|
|
|
|
+ <el-row>
|
|
|
|
+ <el-col :span="24" class="main">
|
|
|
|
+ <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
|
|
|
|
+ <el-col :span="24" class="container info">
|
|
|
|
+ <el-col :span="24" class="top">
|
|
|
|
+ <el-button type="primary" size="mini" @click="dialog = true">添加</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>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-col>
|
|
|
|
+ </el-row>
|
|
|
|
+ <el-dialog :visible.sync="dialog" title="增加" @close="toClose" :destroy-on-close="true" width="50%">
|
|
|
|
+ <data-form :data="form" :fields="formFields" :rules="rules" @save="turnSave">
|
|
|
|
+ <template #custom="{item,form}">
|
|
|
|
+ <template v-if="item.model == 'pic'">
|
|
|
|
+ <upload :limit="1" :data="form.pic" type="pic" :url="'/files/pic/upload'" @upload="uploadSuccess"></upload>
|
|
|
|
+ </template>
|
|
|
|
+ </template>
|
|
|
|
+ </data-form>
|
|
|
|
+ </el-dialog>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import breadcrumb from '@c/common/breadcrumb.vue';
|
|
|
|
+import dataTable from '@/components/frame/filter-page-table.vue';
|
|
|
|
+import dataForm from '@/components/frame/form.vue';
|
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
|
+import upload from '@/components/frame/uploadone.vue';
|
|
|
|
+const { mapActions: links } = createNamespacedHelpers('links');
|
|
|
|
+export default {
|
|
|
|
+ metaInfo() {
|
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
|
+ },
|
|
|
|
+ name: 'index',
|
|
|
|
+ props: {},
|
|
|
|
+ components: {
|
|
|
|
+ breadcrumb,
|
|
|
|
+ dataTable,
|
|
|
|
+ dataForm,
|
|
|
|
+ upload,
|
|
|
|
+ },
|
|
|
|
+ data: function() {
|
|
|
|
+ return {
|
|
|
|
+ opera: [
|
|
|
|
+ {
|
|
|
|
+ label: '修改',
|
|
|
|
+ icon: 'el-icon-edit',
|
|
|
|
+ method: 'edit',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: '删除',
|
|
|
|
+ icon: 'el-icon-delete',
|
|
|
|
+ method: 'delete',
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ fields: [
|
|
|
|
+ { label: '名称', prop: 'title', filter: 'input' },
|
|
|
|
+ { label: '链接地址', prop: 'url' },
|
|
|
|
+ { label: '图片', prop: 'pic' },
|
|
|
|
+ ],
|
|
|
|
+ list: [],
|
|
|
|
+ total: 0,
|
|
|
|
+ // 增加
|
|
|
|
+ dialog: false,
|
|
|
|
+ formFields: [
|
|
|
|
+ { label: '名称', required: true, model: 'title' },
|
|
|
|
+ { label: '图片', required: false, model: 'pic', custom: true },
|
|
|
|
+ { label: '链接地址', required: false, model: 'url' },
|
|
|
|
+ ],
|
|
|
|
+ form: {},
|
|
|
|
+ rules: {
|
|
|
|
+ title: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ created() {
|
|
|
|
+ this.search();
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ ...links(['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);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 修改
|
|
|
|
+ async toEdit({ data }) {
|
|
|
|
+ let res = await this.fetch(data.id);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$set(this, `form`, res.data);
|
|
|
|
+ this.dialog = true;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 删除
|
|
|
|
+ async toDelete({ data }) {
|
|
|
|
+ this.$confirm('您确定要删除此信息吗?', '提示', {
|
|
|
|
+ confirmButtonText: '确定',
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
+ type: 'warning',
|
|
|
|
+ })
|
|
|
|
+ .then(async () => {
|
|
|
|
+ const res = await this.delete(data.id);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: '删除数据成功',
|
|
|
|
+ type: 'success',
|
|
|
|
+ });
|
|
|
|
+ this.search();
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch(() => {});
|
|
|
|
+ },
|
|
|
|
+ // 增加
|
|
|
|
+ // 保存
|
|
|
|
+ async turnSave({ data }) {
|
|
|
|
+ if (data.id) {
|
|
|
|
+ let res = await this.update(data);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: '修改数据成功',
|
|
|
|
+ type: 'success',
|
|
|
|
+ });
|
|
|
|
+ this.dialog = false;
|
|
|
|
+ this.search();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ let res = await this.create(data);
|
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: '添加数据成功',
|
|
|
|
+ type: 'success',
|
|
|
|
+ });
|
|
|
|
+ this.dialog = false;
|
|
|
|
+ this.search();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 取消增加
|
|
|
|
+ toClose() {
|
|
|
|
+ this.form = {};
|
|
|
|
+ this.dialog = false;
|
|
|
|
+ },
|
|
|
|
+ // 图片
|
|
|
|
+ uploadSuccess({ type, data }) {
|
|
|
|
+ this.$set(this.form, `${type}`, data.uri);
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ ...mapState(['user']),
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="less" scoped>
|
|
|
|
+.main {
|
|
|
|
+ .info {
|
|
|
|
+ .top {
|
|
|
|
+ text-align: right;
|
|
|
|
+ margin: 15px 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</style>
|