Browse Source

网站设置+友情链接更新

guhongwei 5 years ago
parent
commit
e2b7b114de
5 changed files with 88 additions and 15 deletions
  1. 5 10
      src/layout/site/siteMain.vue
  2. 3 0
      src/router/index.js
  3. 2 0
      src/store/index.js
  4. 43 0
      src/store/site.js
  5. 35 5
      src/views/site/index.vue

+ 5 - 10
src/layout/site/siteMain.vue

@@ -1,16 +1,10 @@
 <template>
   <div id="siteMain">
     <el-row>
-      <el-col :span="24" class="info">
+      <el-col :span="24" class="info" v-if="loading">
         <el-form ref="form" :model="form" label-width="80px">
-          <el-form-item label="网站logo" prop="logo">
-            <upload
-              :limit="1"
-              :data="form.logo"
-              type="banner"
-              :url="`/files/admin/site/banner_${new Date().getTime()}/upload`"
-              @upload="uploadSuccess"
-            ></upload>
+          <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>
@@ -31,6 +25,7 @@ export default {
   name: 'siteMain',
   props: {
     form: null,
+    loading: null,
   },
   components: {
     WangEditor,
@@ -44,7 +39,7 @@ export default {
       this.$set(this.form, `${type}`, data.uri);
     },
     submit() {
-      console.log('保存成功');
+      this.$emit('submitDate', { data: this.form, id: this.form.id });
     },
   },
 };

+ 3 - 0
src/router/index.js

@@ -19,15 +19,18 @@ export default new Router({
     // 站点信息
     {
       path: '/site/index',
+      meta: { title: '网站设置' },
       component: () => import('../views/site/index.vue'),
     },
     // 友情链接管理
     {
       path: '/links/index',
+      meta: { title: '友情链接' },
       component: () => import('../views/links/index.vue'),
     },
     {
       path: '/links/detail',
+      meta: { title: '友情链接' },
       component: () => import('../views/links/detail.vue'),
     },
   ],

+ 2 - 0
src/store/index.js

@@ -1,12 +1,14 @@
 import Vue from 'vue';
 import Vuex from 'vuex';
 import link from './link';
+import site from './site';
 
 Vue.use(Vuex);
 
 export default new Vuex.Store({
   modules: {
     link,
+    site,
   },
   state: {},
   mutations: {},

+ 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/set`,
+  shows: `/api/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,
+};

+ 35 - 5
src/views/site/index.vue

@@ -5,7 +5,7 @@
         <topInfo :topTitle="topTitle"></topInfo>
       </el-col>
       <el-col :span="24" class="main">
-        <siteMain :form="form"></siteMain>
+        <siteMain :form="form" @submitDate="submit" :loading="loading"></siteMain>
       </el-col>
     </el-row>
   </div>
@@ -14,7 +14,8 @@
 <script>
 import topInfo from '@/layout/public/top.vue';
 import siteMain from '@/layout/site/siteMain.vue';
-
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('site');
 export default {
   name: 'index',
   props: {},
@@ -25,10 +26,39 @@ export default {
   data: () => ({
     topTitle: '站点信息管理',
     form: {},
+    loading: true,
   }),
-  created() {},
-  computed: {},
-  methods: {},
+  created() {
+    this.search();
+  },
+  computed: {
+    keyWord() {
+      let meta = this.$route.meta;
+      let main = meta.title || '';
+      return main;
+    },
+  },
+  methods: {
+    ...mapActions(['showInfo', 'create', 'update']),
+    async search() {
+      this.loading = false;
+      const res = await this.showInfo();
+      this.$set(this, `form`, res.data);
+      this.loading = true;
+    },
+    async submit({ id, data }) {
+      let res;
+      let msg;
+      if (id) {
+        res = await this.update(data);
+        msg = `${this.keyWord}修改成功`;
+      } else {
+        res = await this.create(data);
+        msg = `${this.keyWord}添加成功`;
+      }
+      this.$checkRes(res, msg);
+    },
+  },
 };
 </script>