Browse Source

系统配置

yuhaitao14 7 years ago
parent
commit
80b3ab1bfe

+ 21 - 0
shop/src/main/java/com/zskk/shop/controller/UploadController.java

@@ -8,6 +8,10 @@
 
 package com.zskk.shop.controller;
 
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -17,6 +21,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import com.zskk.shop.controller.bean.ControllerResult;
 import com.zskk.shop.exception.ErrorConstant;
+import com.zskk.shop.exception.ZSKKException;
 import com.zskk.shop.service.OssService;
 import com.zskk.shop.utils.SecretUtil;
 
@@ -38,4 +43,20 @@ public class UploadController {
 			return new ControllerResult(ErrorConstant.PARAM_ERROR);
 		}
 	}
+	
+	@RequestMapping("/editupload")
+	@ResponseBody
+	public Map<String, Object> editupload(@RequestParam("file") MultipartFile file){
+		Map<String, Object> result = new HashMap<>();
+		try{
+			byte[] data = file.getBytes();
+			String md5 	= SecretUtil.md5(data);
+			String path = ossService.upload(data, md5);
+			result.put("errno", 0);
+			result.put("data", Arrays.asList(path));
+			return result;
+		}catch (Exception e) {
+			throw new ZSKKException(ErrorConstant.SERVER_ERROR);
+		}
+	}
 }

+ 62 - 0
shop/src/main/java/com/zskk/shop/controller/admin/ShopConfigController.java

@@ -0,0 +1,62 @@
+/**
+* @版权信息 (@copyright Copyright 2017-XXXX JDJR.COM All Right Reserved);
+* @see
+* @author 于海涛 京东金融【技术研发部-证券及营销平台研发部-营销平台研发部】
+* @version 1.0
+* @date 2018年6月20日
+*/
+
+package com.zskk.shop.controller.admin;
+
+import java.util.Set;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.zskk.shop.controller.AbstractController;
+import com.zskk.shop.controller.bean.ControllerResult;
+import com.zskk.shop.exception.ErrorConstant;
+import com.zskk.shop.exception.ZSKKException;
+import com.zskk.shop.service.ShopConfigService;
+
+@Controller
+@RequestMapping("/manage/config")
+public class ShopConfigController extends AbstractController  {
+	
+	@Autowired
+	private ShopConfigService shopConfigService;
+	
+	@RequestMapping("/getAllKeys")
+	@ResponseBody
+	public ControllerResult getAllKeys(){
+		Set<String> keys = shopConfigService.getAllKey();
+		return new ControllerResult(keys);
+	}
+	
+	@RequestMapping("/getAll")
+	@ResponseBody
+	public ControllerResult getAll(){
+		return new ControllerResult(shopConfigService.getAll());
+	}
+	
+	@RequestMapping("/get")
+	@ResponseBody
+	public ControllerResult get(@RequestParam("key") String key){
+		return new ControllerResult(shopConfigService.get(key));
+	}
+	
+	@RequestMapping("/save")
+	@ResponseBody
+	public ControllerResult save(@RequestParam("key") String key, @RequestParam("value") String value){
+		//验证KEY
+		if (!shopConfigService.getAllKey().contains(key)){
+			throw new ZSKKException(ErrorConstant.PARAM_ERROR);
+		}
+		
+		shopConfigService.set(key, value);
+		return new ControllerResult(Boolean.TRUE);
+	}
+}

+ 4 - 0
shop/src/main/java/com/zskk/shop/dao/ShopConfigMapper.java

@@ -8,6 +8,8 @@
 
 package com.zskk.shop.dao;
 
+import java.util.List;
+
 import com.zskk.shop.dao.entry.ShopConfig;
 
 public interface ShopConfigMapper {
@@ -16,4 +18,6 @@ public interface ShopConfigMapper {
 	public int update(ShopConfig shopConfig);
 	
 	public ShopConfig query(String key);
+	
+	public List<ShopConfig> queryAll();
 }

+ 25 - 0
shop/src/main/java/com/zskk/shop/service/ShopConfigService.java

@@ -8,6 +8,12 @@
 
 package com.zskk.shop.service;
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -22,9 +28,28 @@ public class ShopConfigService {
 	 */
 	public static final String KEY_EQUIPMENT_INFO = "equipment_info";
 	
+	private Set<String> ALL_KEYS = new HashSet<>();
+	
+	@PostConstruct
+	public void init(){
+		ALL_KEYS.add(KEY_EQUIPMENT_INFO);
+	}
+	
 	@Autowired
 	private ShopConfigMapper shopConfigMapper;
 	
+	/**
+	 * 获取全部KEY
+	 * @return
+	 */
+	public Set<String> getAllKey(){
+		return ALL_KEYS;
+	}
+	
+	public List<ShopConfig> getAll(){
+		return shopConfigMapper.queryAll();
+	}
+	
 	/**
 	 * 获取KEY
 	 * @param key

+ 9 - 5
shop/src/main/resource/mapper/ShopConfigMapper.xml

@@ -2,16 +2,20 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.zskk.shop.dao.ShopConfigMapper">
 	<insert id="add" parameterType="com.zskk.shop.dao.entry.ShopConfig">
-		insert into shop_config(key, description, value, ctime)
+		insert into shop_config(`key`, description, `value`, ctime)
 		values(#{key}, #{description}, #{value}, #{ctime})
 	</insert>
 	<update id="update" parameterType="com.zskk.shop.dao.entry.ShopConfig">
-		update shop_config description=#{description}, value=#{description}
-		where key=#{key}
+		update shop_config set`value`=#{value}
+		where `key`=#{key}
 	</update>
-	<select id="queyr" parameterType="com.zskk.shop.dao.entry.ShopConfig">
+	<select id="query" resultType="com.zskk.shop.dao.entry.ShopConfig">
+		select *
+		from shop_config
+		where `key`=#{key}
+	</select>
+	<select id="queryAll" resultType="com.zskk.shop.dao.entry.ShopConfig">
 		select *
 		from shop_config
-		where key=#{key}
 	</select>
 </mapper>

+ 2 - 1
shop/static/manager/package.json

@@ -14,7 +14,8 @@
     "axios": "^0.18.0",
     "element-ui": "^2.2.0",
     "vue": "^2.5.2",
-    "vue-router": "^3.0.1"
+    "vue-router": "^3.0.1",
+    "wangeditor": "^3.1.1"
   },
   "devDependencies": {
     "autoprefixer": "^7.1.2",

+ 8 - 4
shop/static/manager/src/api/index.js

@@ -80,8 +80,12 @@ export default {
     bindPackage: (params, vue) => post(`${serverPath}manage/bindPackage`, params, vue),
     setGoodLabels: (params, vue) => post(`${serverPath}manage/setGoodLabels`, params, vue),
     setRecommand: (params, vue) => post(`${serverPath}manage/setRecommand`, params, vue),
-    getuser: (params, vue) => post(`${serverPath}/manage/muser/getuser`, params, vue),
-    getAllFaq: (params, vue) => post(`${serverPath}/manage/faq/all`, params, vue),
-    geFaq: (params, vue) => post(`${serverPath}/manage/faq/get`, params, vue),
-    saveFaq: (params, vue) => post(`${serverPath}/manage/faq/save`, params, vue),
+    getuser: (params, vue) => post(`${serverPath}manage/muser/getuser`, params, vue),
+    getAllFaq: (params, vue) => post(`${serverPath}manage/faq/all`, params, vue),
+    geFaq: (params, vue) => post(`${serverPath}manage/faq/get`, params, vue),
+    saveFaq: (params, vue) => post(`${serverPath}manage/faq/save`, params, vue),
+
+    getSysConfig: (params, vue) => post(`${serverPath}manage/config/get`, params, vue),
+    saveSysConfig: (params, vue) => post(`${serverPath}manage/config/save`, params, vue),
+    getAllSysConfig: (params, vue) => post(`${serverPath}manage/config/getAll`, params, vue),
 }

+ 1 - 0
shop/static/manager/src/components/Sidebar.vue

@@ -43,6 +43,7 @@ export default {
       items.push({ icon: '', index: '/sysLabelManager', title: '系统标签'})
       items.push({ icon: '', index: '/manageUser', title: '用户管理'})
       items.push({ icon: '', index: '/faqManage', title: '常见问题'})
+      items.push({ icon: '', index: '/sysConfig', title: '系统配置'})
       this.items  = items
       for (var i in items){
           var item = items[i]

+ 84 - 0
shop/static/manager/src/components/page/config/EditShopConfig.vue

@@ -0,0 +1,84 @@
+<template>
+    <div>
+        <div class="config_button">
+            <el-button type="primary" @click="save">保存</el-button>
+            <el-button @click="goBack">取消</el-button>
+        </div>
+        <div id="bar" class="bar">
+        </div>
+        <div id="editor" class="editor">
+        </div>
+
+    </div>
+</template>
+<script>
+var E = require('wangeditor')
+export default {
+  data() {
+    return {
+      key: '',
+      value: ''
+    }
+  },
+  methods: {
+    save: function() {
+        var that = this
+      var param = {
+        key: this.key,
+        value: this.value
+      }
+      this.$http.saveSysConfig(param, this).then(res => {
+        if (res.code === 0) {
+          this.$message({
+            message: '操作成功',
+            type: 'success',
+            duration: 1000,
+            onClose: function() {
+              that.$router.push('/sysLabelManager')
+            }
+          })
+        }
+      })
+    },
+    goBack: function() {
+      this.$router.back()
+    }
+  },
+  mounted: function() {
+    var that = this
+    var editor = new E('#bar', '#editor')
+    editor.customConfig.uploadImgShowBase64 = true
+    //editor.customConfig.uploadImgServer = process.env.SERVER_PATH + 'editupload'
+    //editor.customConfig.uploadFileName = 'file'
+    editor.customConfig.onchange = function(html) {
+      that.value = html
+    }
+    editor.create()
+
+    var key = this.$route.query.key
+    this.key = key
+
+    this.$http.getSysConfig({ key: key }, this).then(res => {
+      if (res.code === 0) {
+        editor.txt.html(res.obj)
+      }
+    })
+  }
+}
+</script>
+
+<style>
+.bar {
+  background-color: #f1f1f1;
+  border: 1px solid #ccc;
+}
+.editor {
+  border: 1px solid #ccc;
+  border-top: none;
+  height: 700px;
+}
+
+.config_button {
+  margin-bottom: 20px;
+}
+</style>

+ 45 - 0
shop/static/manager/src/components/page/config/ShopConfigManager.vue

@@ -0,0 +1,45 @@
+<template>
+    <el-table :data="items">
+        <el-table-column label="KEY" prop="key"></el-table-column>
+        <el-table-column label="名称" prop="description">
+        </el-table-column>
+        <el-table-column label="操作">
+            <template slot-scope="scope">
+                <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
+                <el-button type="text" size="small" @click="goEdit(scope.row)">预览</el-button>
+                <el-button type="text" size="small" @click="goEdit(scope.row)">发布</el-button>
+            </template>
+        </el-table-column>
+    </el-table>
+</template>
+<script>
+export default {
+  data: function() {
+    return {
+      items: []
+    }
+  },
+  methods: {
+    goEdit: function(row) {
+      this.$router.push({ path: '/editSysConfig', query: { key: row.key } })
+    }
+  },
+  mounted: function() {
+    this.$http.getAllSysConfig({}, this).then(res => {
+      if (res.code === 0) {
+        this.items = res.obj
+      }
+    })
+  }
+}
+</script>
+
+<style>
+    .online {
+        color: #67c23a
+    }
+    .offline {
+        color: #f56c6c;
+    }
+</style>
+

+ 6 - 5
shop/static/manager/src/main.js

@@ -7,6 +7,7 @@ import ElementUI from 'element-ui'
 import 'element-ui/lib/theme-chalk/index.css'
 import http from './api'
 
+
 Vue.use(ElementUI)
 Vue.prototype.$http = http
 
@@ -14,8 +15,8 @@ Vue.config.productionTip = false
 
 /* eslint-disable no-new */
 new Vue({
-  el: '#app',
-  router,
-  components: { App },
-  template: '<App/>'
-})
+    el: '#app',
+    router,
+    components: { App },
+    template: '<App/>'
+})

+ 9 - 1
shop/static/manager/src/router/index.js

@@ -53,13 +53,21 @@ export default new Router({
                 {
                     path: '/editFAQ',
                     component: resolve => require(['../components/page/faq/EditFAQ'], resolve)
+                },
+                {
+                    path: '/sysConfig',
+                    component: resolve => require(['../components/page/config/ShopConfigManager'], resolve)
+                },
+                {
+                    path: '/editSysConfig',
+                    component: resolve => require(['../components/page/config/EditShopConfig'], resolve)
                 }
             ]
         },
         {
             path: '/demo',
             name: 'demo',
-            component: resolve => require(['../components/page/ManageUser'], resolve)
+            component: resolve => require(['../components/page/config/EditShopConfig'], resolve)
         }
     ]
 })