Browse Source

Merge branches 'gva_workflow' and 'master' of https://github.com/flipped-aurora/gin-vue-admin into gva_workflow

 Conflicts:
	web/package.json
QM303176530 4 years ago
parent
commit
9f5b14bd52

+ 0 - 3
README-en.md

@@ -374,6 +374,3 @@ If you find this project useful, you can buy author a glass of juice :tropical_d
 
 If you use this project for commercial purposes, please comply with the Apache2.0 agreement and retain the author's technical support statement.
 
-## 11.Links
-
-A high performance web and rpc framework, with powerful code generator. [go-zero](https://github.com/tal-tech/go-zero)

+ 0 - 4
README.md

@@ -364,7 +364,3 @@ swag init
 ## 10. 商用注意事项
 
 如果您将此项目用于商业用途,请遵守Apache2.0协议并保留作者技术支持声明。
-
-## 11. 友情推荐
-
-内置强大代码生成器的高性能微服务框架 [go-zero](https://github.com/tal-tech/go-zero)

+ 1 - 1
server/api/v1/sys_user.go

@@ -130,7 +130,7 @@ func tokenNext(c *gin.Context, user model.SysUser) {
 			response.FailWithMessage("jwt作废失败", c)
 			return
 		}
-		if err := service.SetRedisJWT(jwtStr, user.Username); err != nil {
+		if err := service.SetRedisJWT(token, user.Username); err != nil {
 			response.FailWithMessage("设置登录状态失败", c)
 			return
 		}

+ 1 - 1
server/core/server.go

@@ -29,7 +29,7 @@ func RunWindowsServer() {
 
 	fmt.Printf(`
 	欢迎使用 Gin-Vue-Admin
-	当前版本:V2.3.2
+	当前版本:V2.3.3
 	默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
 	默认前端文件运行地址:http://127.0.0.1:8080
 `, address)

+ 4 - 10
web/package-lock.json

@@ -4480,12 +4480,11 @@
             "integrity": "sha1-8OAD2cqef1nHpQiUXXsu+aBKVC8="
         },
         "axios": {
-            "version": "0.19.0",
-            "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
-            "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
+            "version": "0.19.2",
+            "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
+            "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
             "requires": {
-                "follow-redirects": "1.5.10",
-                "is-buffer": "^2.0.2"
+                "follow-redirects": "1.5.10"
             },
             "dependencies": {
                 "debug": {
@@ -4504,11 +4503,6 @@
                         "debug": "=3.1.0"
                     }
                 },
-                "is-buffer": {
-                    "version": "2.0.3",
-                    "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
-                    "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
-                },
                 "ms": {
                     "version": "2.0.0",
                     "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

+ 3 - 3
web/package.json

@@ -3,13 +3,13 @@
     "version": "0.1.0",
     "private": true,
     "scripts": {
-        "serve": "vue-cli-service serve",
+        "serve": "start https://www.gin-vue-admin.com && vue-cli-service serve",
         "build": "vue-cli-service build",
         "lint": "vue-cli-service lint"
     },
     "dependencies": {
         "@moefe/vue-aplayer": "^2.0.0-beta.5",
-        "axios": "^0.19.0",
+        "axios": "^0.19.2",
         "core-js": "^3.6.5",
         "echarts": "^4.7.0",
         "element-ui": "^2.12.0",
@@ -65,4 +65,4 @@
         "> 1%",
         "last 2 versions"
     ]
-}
+}

+ 2 - 1
web/public/index.html

@@ -3,6 +3,7 @@
 
 <head>
     <meta charset="utf-8">
+    <meta name="renderer" content="webkit">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
@@ -17,4 +18,4 @@
     <!-- built files will be auto injected -->
 </body>
 
-</html>
+</html>

+ 15 - 14
web/src/api/system.js

@@ -7,10 +7,10 @@ import service from "@/utils/request";
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
 // @Router /system/getSystemConfig [post]
 export const getSystemConfig = () => {
-  return service({
-    url: "/system/getSystemConfig",
-    method: "post",
-  });
+    return service({
+        url: "/system/getSystemConfig",
+        method: "post",
+    });
 };
 
 // @Tags system
@@ -21,11 +21,11 @@ export const getSystemConfig = () => {
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
 // @Router /system/setSystemConfig [post]
 export const setSystemConfig = (data) => {
-  return service({
-    url: "/system/setSystemConfig",
-    method: "post",
-    data,
-  });
+    return service({
+        url: "/system/setSystemConfig",
+        method: "post",
+        data,
+    });
 };
 
 // @Tags system
@@ -35,8 +35,9 @@ export const setSystemConfig = (data) => {
 // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
 // @Router /system/getServerInfo [post]
 export const getSystemState = () => {
-  return service({
-    url: "/system/getServerInfo",
-    method: "post",
-  });
-};
+    return service({
+        url: "/system/getServerInfo",
+        method: "post",
+        donNotShowLoading: true
+    });
+};

+ 100 - 0
web/src/components/upload/image.vue

@@ -0,0 +1,100 @@
+<!--
+  <div>
+    带压缩的上传
+    <upload-image v-model="imageUrl" :fileSize="512" />
+    已上传文件 {{ imageUrl }}
+  </div>
+
+
+-->
+
+<template>
+  <div>
+    <el-upload
+      class="image-uploader"
+      :action="`${path}/fileUploadAndDownload/upload`"
+      :show-file-list="false"
+      :on-success="handleImageSuccess"
+      :before-upload="beforeImageUpload"
+      :multiple="false"
+    >
+      <img v-if="imageUrl" :src="imageUrl" class="image" />
+      <i v-else class="el-icon-plus image-uploader-icon"></i>
+    </el-upload>
+  </div>
+</template>
+<script>
+const path = process.env.VUE_APP_BASE_API;
+import ImageCompress from "@/utils/image.js";
+export default {
+  name: "upload-image",
+  model: {
+    prop: "imageUrl",
+    event: "change",
+  },
+  props: {
+    imageUrl: {
+      type: String,
+      default: "",
+    },
+    fileSize: {
+      type: Number,
+      default: 2048, // 2M 超出后执行压缩
+    },
+    maxWH: {
+      type: Number,
+      default: 1920, // 图片长宽上限
+    },
+  },
+  data() {
+    return {
+      path: path,
+    };
+  },
+  methods: {
+    beforeImageUpload(file) {
+      let isRightSize = file.size / 1024 < this.fileSize;
+      if (!isRightSize) {
+        // 压缩
+        let compress = new ImageCompress(file, this.fileSize, this.maxWH);
+        return compress.compress();
+      }
+      return isRightSize;
+    },
+    handleImageSuccess(res) {
+      // this.imageUrl = URL.createObjectURL(file.raw);
+      const {  data } = res;
+      if (data.file) {
+        this.$emit("change", data.file.url);
+      }
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.image-uploader {
+  border: 1px dashed #d9d9d9;
+  width: 180px;
+  border-radius: 6px;
+  cursor: pointer;
+  position: relative;
+  overflow: hidden;
+}
+.image-uploader {
+  border-color: #409eff;
+}
+.image-uploader-icon {
+  font-size: 28px;
+  color: #8c939d;
+  width: 178px;
+  height: 178px;
+  line-height: 178px;
+  text-align: center;
+}
+.image {
+  width: 178px;
+  height: 178px;
+  display: block;
+}
+</style>

+ 1 - 1
web/src/main.js

@@ -66,7 +66,7 @@ Vue.prototype.$echarts = echarts;
 
 console.log(`
        欢迎使用 Gin-Vue-Admin
-       当前版本:V2.3.2
+       当前版本:V2.3.3
        默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
        默认前端文件运行地址:http://127.0.0.1:8080
 `)

+ 94 - 0
web/src/utils/image.js

@@ -0,0 +1,94 @@
+export default class ImageCompress {
+    constructor(file, fileSize, maxWH = 1920) {
+        this.file = file
+        this.fileSize = fileSize
+        this.maxWH = maxWH // 最大长宽
+    }
+
+    compress() {
+        // 压缩
+        const fileType = this.file.type
+        const fileSize = this.file.size / 1024
+        return new Promise(resolve => {
+            const reader = new FileReader();
+            reader.readAsDataURL(this.file);
+            reader.onload = () => {
+                const canvas = document.createElement('canvas');
+                const img = document.createElement('img');
+                img.src = reader.result;
+                img.onload = () => {
+                    const ctx = canvas.getContext('2d');
+                    let _dWH = this.dWH(img.width, img.height, this.maxWH)
+                    canvas.width = _dWH.width
+                    canvas.height = _dWH.height
+
+                    // 清空后, 重写画布
+                    ctx.clearRect(0, 0, canvas.width, canvas.height)
+                    ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
+
+                    let newImgData = canvas.toDataURL(fileType, 0.90)
+
+                    // 压缩宽高后的图像大小
+                    let newImgSize = this.fileSizeKB(newImgData)
+
+                    if (newImgSize > this.fileSize) {
+                        console.log('图片尺寸太大!' + fileSize + " >> " + newImgSize)
+                    }
+
+                    let blob = this.dataURLtoBlob(newImgData, fileType)
+                    let nfile = new File([blob], this.file.name);
+                    resolve(nfile)
+                };
+            };
+        });
+    }
+
+    /*
+     * 长宽等比缩小
+     * 图像的一边(长或宽)为最大目标值
+     * */
+    dWH(srcW, srcH, dMax) {
+
+        let defaults = {
+            width: srcW,
+            height: srcH
+        }
+        if (Math.max(srcW, srcH) > dMax) {
+            if (srcW > srcH) {
+                defaults.width = dMax
+                defaults.height = Math.round(srcH * (dMax / srcW))
+                return defaults
+            } else {
+                defaults.height = dMax
+                defaults.width = Math.round(srcW * (dMax / srcH))
+                return defaults
+            }
+        } else {
+            return defaults
+        }
+    }
+
+    fileSizeKB(dataURL) {
+        let sizeKB = 0
+        sizeKB = Math.round((dataURL.split(',')[1].length * 3 / 4) / 1024)
+        return sizeKB
+    }
+
+    /*
+     * 转为Blob
+     * */
+    dataURLtoBlob(dataURL, fileType) {
+        let byteString = atob(dataURL.split(',')[1])
+        let mimeString = dataURL.split(',')[0].split(':')[1].split(';')[0]
+        let ab = new ArrayBuffer(byteString.length)
+        let ia = new Uint8Array(ab)
+        for (let i = 0; i < byteString.length; i++) {
+            ia[i] = byteString.charCodeAt(i)
+        }
+        if (fileType) {
+            mimeString = fileType
+        }
+        return new Blob([ab], { type: mimeString, lastModifiedDate: new Date() })
+    }
+
+}

+ 4 - 1
web/src/utils/request.js

@@ -30,7 +30,10 @@ const closeLoading = () => {
     //http request 拦截器
 service.interceptors.request.use(
     config => {
-        showLoading()
+        console.log(config)
+        if (!config.donNotShowLoading) {
+            showLoading()
+        }
         const token = store.getters['user/token']
         const user = store.getters['user/userInfo']
         config.data = JSON.stringify(config.data);

+ 36 - 19
web/src/view/example/upload/upload.vue

@@ -1,23 +1,33 @@
 <template>
   <div v-loading.fullscreen.lock="fullscreenLoading">
     <div class="upload">
-      <el-upload
-        :action="`${path}/fileUploadAndDownload/upload`"
-        :before-upload="checkFile"
-        :headers="{ 'x-token': token }"
-        :on-error="uploadError"
-        :on-success="uploadSuccess"
-        :show-file-list="false"
-      >
-        <el-button size="small" type="primary">点击上传</el-button>
-        <div class="el-upload__tip" slot="tip">
-          只能上传jpg/png文件,且不超过500kb
-        </div>
-      </el-upload>
+      <el-row>
+        <el-col :span="12">
+          <el-upload
+            :action="`${path}/fileUploadAndDownload/upload`"
+            :before-upload="checkFile"
+            :headers="{ 'x-token': token }"
+            :on-error="uploadError"
+            :on-success="uploadSuccess"
+            :show-file-list="false"
+          >
+            <el-button size="small" type="primary">点击上传</el-button>
+            <div class="el-upload__tip" slot="tip">
+              只能上传jpg/png文件,且不超过500kb
+            </div>
+          </el-upload>
+        </el-col>
+        <el-col :span="12">
+          带压缩的上传, (512(k)为压缩限制)
+          <upload-image v-model="imageUrl" :fileSize="512" :maxWH="1080" />
+          已上传文件 {{ imageUrl }}
+        </el-col>
+      </el-row>
+
       <el-table :data="tableData" border stripe>
         <el-table-column label="预览" width="100">
           <template slot-scope="scope">
-            <CustomPic picType="file" :picSrc="scope.row.url"/>
+            <CustomPic picType="file" :picSrc="scope.row.url" />
           </template>
         </el-table-column>
         <el-table-column label="日期" prop="UpdatedAt" width="180">
@@ -30,7 +40,11 @@
           prop="name"
           width="180"
         ></el-table-column>
-        <el-table-column label="链接" prop="url" min-width="300"></el-table-column>
+        <el-table-column
+          label="链接"
+          prop="url"
+          min-width="300"
+        ></el-table-column>
         <el-table-column label="标签" prop="tag" width="100">
           <template slot-scope="scope">
             <el-tag
@@ -72,26 +86,29 @@ import infoList from "@/components/mixins/infoList";
 import { getFileList, deleteFile } from "@/api/fileUploadAndDownload";
 import { downloadImage } from "@/utils/downloadImg";
 import { formatTimeToStr } from "@/utils/data";
-import CustomPic from '@/components/customPic'
+import CustomPic from "@/components/customPic";
+import UploadImage from "@/components/upload/image.vue";
 export default {
   name: "Upload",
   mixins: [infoList],
   components: {
-		CustomPic
-	},
+    CustomPic,
+    UploadImage,
+  },
   data() {
     return {
       fullscreenLoading: false,
       listApi: getFileList,
       path: path,
       tableData: [],
+      imageUrl: "",
     };
   },
   computed: {
     ...mapGetters("user", ["userInfo", "token"]),
   },
   filters: {
-    formatDate: function(time) {
+    formatDate: function (time) {
       if (time != null && time != "") {
         var date = new Date(time);
         return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");

+ 1 - 1
web/src/view/superAdmin/menu/menu.vue

@@ -232,7 +232,7 @@ export default {
   methods: {
     addParameter(form) {
       if (!form.parameters){
-        form.parameters = []
+        this.$set(form,"parameters",[])
       }
       form.parameters.push({
         type: "query",