guhongwei 4 vuotta sitten
vanhempi
commit
b057dd677f
3 muutettua tiedostoa jossa 137 lisäystä ja 9 poistoa
  1. 2 0
      src/store/index.js
  2. 43 0
      src/store/site.js
  3. 92 9
      src/views/site/index.vue

+ 2 - 0
src/store/index.js

@@ -4,6 +4,7 @@ import * as ustate from './user/state';
 import * as umutations from './user/mutations';
 import login from './login';
 import link from './link';
+import site from './site';
 
 Vue.use(Vuex);
 
@@ -14,5 +15,6 @@ export default new Vuex.Store({
   modules: {
     login,
     link,
+    site,
   },
 });

+ 43 - 0
src/store/site.js

@@ -0,0 +1,43 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  site: `/api/setting/set`,
+  shows: `/api/setting/set/show`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.site}`, { skip, limit, ...info });
+    return res;
+  },
+  async showInfo({ commit }, { ...info } = {}) {
+    const res = await this.$axios.$get(`${api.shows}`, { ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.site}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.site}/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.site}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.site}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 92 - 9
src/views/site/index.vue

@@ -1,31 +1,114 @@
 <template>
-  <div id="index">
+  <div id="detail">
     <el-row>
-      <el-col :span="24">
-        <p>index</p>
+      <el-col :span="24" class="main">
+        <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
+        <el-col :span="24" class="container">
+          <el-col :span="24" class="list" v-if="loading">
+            <el-form ref="form" :model="form" label-width="80px">
+              <el-form-item label="网站logo" prop="logourl">
+                <upload :limit="1" :data="form.logourl" type="logourl" :url="'/files/links/upload'" @upload="uploadSuccess"></upload>
+              </el-form-item>
+              <el-form-item label="联系方式" prop="content">
+                <wang-editor v-model="form.content" placeholder="请输入联系方式"></wang-editor>
+              </el-form-item>
+              <el-form-item>
+                <el-button type="primary" @click="submit()">保存</el-button>
+              </el-form-item>
+            </el-form>
+          </el-col>
+        </el-col>
       </el-col>
     </el-row>
   </div>
 </template>
 
 <script>
+import wangEditor from '@c/frame/wang-editor.vue';
+import upload from '@c/frame/uploadone.vue';
+import breadcrumb from '@c/common/breadcrumb.vue';
 import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('site');
 export default {
   metaInfo() {
     return { title: this.$route.meta.title };
   },
-  name: 'index',
+  name: 'detail',
   props: {},
-  components: {},
+  components: {
+    breadcrumb,
+    upload,
+    wangEditor,
+  },
   data: function() {
-    return {};
+    return {
+      form: {},
+      loading: false,
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...mapActions(['showInfo', 'create', 'update']),
+    // 查询列表
+    async search() {
+      this.loading = false;
+      let res = await this.showInfo();
+      let object = JSON.parse(JSON.stringify(res.data));
+      if (object) {
+        this.$set(this, `form`, res.data);
+      }
+      this.loading = true;
+    },
+    async submit() {
+      let data = this.form;
+      let res;
+      let msg;
+      if (data.id) {
+        res = await this.update(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '修改成功',
+            type: 'success',
+          });
+        } else {
+          this.$message({
+            message: res.errmsg,
+            type: 'error',
+          });
+        }
+      } else {
+        res = await this.create(data);
+        if (this.$checkRes(res)) {
+          this.$message({
+            message: '添加成功',
+            type: 'success',
+          });
+        } else {
+          this.$message({
+            message: res.errmsg,
+            type: 'error',
+          });
+        }
+      }
+      this.search();
+    },
+    uploadSuccess({ type, data }) {
+      this.$set(this.form, `${type}`, data.uri);
+    },
   },
-  created() {},
-  methods: {},
   computed: {
     ...mapState(['user']),
   },
 };
 </script>
 
-<style lang="less" scoped></style>
+<style lang="less" scoped>
+.main {
+  .top {
+    text-align: right;
+    margin: 15px 0;
+  }
+}
+</style>