疯狂的狮子li
2021-01-06 b36874538051c56d9c76485d4485f7b3c164aad3
Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue

 Conflicts:
 ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
 ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
 ruoyi-generator/src/main/resources/vm/vue/index.vue.vm
 ruoyi-ui/package.json
 ruoyi-ui/src/components/HeaderSearch/index.vue
 ruoyi-ui/src/main.js
 ruoyi-ui/src/views/tool/gen/editTable.vue
 ruoyi-ui/src/views/tool/gen/index.vue
已修改9个文件
已添加2个文件
已删除1个文件
447 ■■■■ 文件已修改
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-generator/src/main/resources/vm/vue/index.vue.vm 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/package.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/components/FileUpload/index.vue 178 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/components/HeaderSearch/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/components/ImageUpload/index.vue 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/components/UploadImage/index.vue 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/main.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/views/tool/gen/editTable.vue 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/views/tool/gen/index.vue 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
@@ -76,8 +76,11 @@
    /** æ—¥æœŸæŽ§ä»¶ */
    public static final String HTML_DATETIME = "datetime";
    /** ä¸Šä¼ æŽ§ä»¶ */
    public static final String HTML_UPLOAD_IMAGE = "uploadImage";
    /** å›¾ç‰‡ä¸Šä¼ æŽ§ä»¶ */
    public static final String HTML_IMAGE_UPLOAD = "imageUpload";
    /** æ–‡ä»¶ä¸Šä¼ æŽ§ä»¶ */
    public static final String HTML_FILE_UPLOAD = "fileUpload";
    /** å¯Œæ–‡æœ¬æŽ§ä»¶ */
    public static final String HTML_EDITOR = "editor";
ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java
@@ -112,10 +112,15 @@
        {
            column.setHtmlType(GenConstants.HTML_SELECT);
        }
        // æ–‡ä»¶å­—段设置上传控件
        // å›¾ç‰‡å­—段设置图片上传控件
        else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
        {
            column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE);
            column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
        }
        // æ–‡ä»¶å­—段设置文件上传控件
        else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
        {
            column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
        }
        // å†…容字段设置富文本控件
        else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm
@@ -153,9 +153,13 @@
        <el-form-item label="${comment}" prop="${field}">
          <el-input v-model="form.${field}" placeholder="请输入${comment}" />
        </el-form-item>
#elseif($column.htmlType == "uploadImage")
#elseif($column.htmlType == "imageUpload")
        <el-form-item label="${comment}">
          <uploadImage v-model="form.${field}"/>
          <imageUpload v-model="form.${field}"/>
        </el-form-item>
#elseif($column.htmlType == "fileUpload")
        <el-form-item label="${comment}">
          <imageUpload v-model="form.${field}"/>
        </el-form-item>
#elseif($column.htmlType == "editor")
        <el-form-item label="${comment}">
@@ -244,8 +248,13 @@
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
import UploadImage from '@/components/UploadImage';
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
import ImageUpload from '@/components/ImageUpload';
#break
#end
#end
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
import FileUpload from '@/components/FileUpload';
#break
#end
#end
@@ -260,8 +269,14 @@
  name: "${BusinessName}",
  components: {
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
    UploadImage,
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
    ImageUpload,
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
    FileUpload,
#break
#end
#end
ruoyi-generator/src/main/resources/vm/vue/index.vue.vm
@@ -185,9 +185,13 @@
        <el-form-item label="${comment}" prop="${field}">
          <el-input v-model="form.${field}" placeholder="请输入${comment}" />
        </el-form-item>
#elseif($column.htmlType == "uploadImage")
#elseif($column.htmlType == "imageUpload")
        <el-form-item label="${comment}">
          <uploadImage v-model="form.${field}"/>
          <imageUpload v-model="form.${field}"/>
        </el-form-item>
#elseif($column.htmlType == "fileUpload")
        <el-form-item label="${comment}">
          <fileUpload v-model="form.${field}"/>
        </el-form-item>
#elseif($column.htmlType == "editor")
        <el-form-item label="${comment}">
@@ -274,8 +278,14 @@
<script>
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
import UploadImage from '@/components/UploadImage';
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
import ImageUpload from '@/components/ImageUpload';
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
import FileUpload from '@/components/FileUpload';
#break
#end
#end
@@ -290,8 +300,14 @@
  name: "${BusinessName}",
  components: {
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
    UploadImage,
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
    ImageUpload,
#break
#end
#end
#foreach($column in $columns)
#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
    FileUpload,
#break
#end
#end
ruoyi-ui/package.json
@@ -44,7 +44,7 @@
    "element-ui": "2.14.1",
    "file-saver": "2.0.4",
    "fuse.js": "6.4.3",
    "highlight.js": "10.4.1",
    "highlight.js": "9.18.5",
    "js-beautify": "1.13.0",
    "js-cookie": "2.2.1",
    "jsencrypt": "3.0.0-rc.1",
@@ -69,8 +69,8 @@
    "eslint": "7.15.0",
    "eslint-plugin-vue": "7.2.0",
    "lint-staged": "10.5.3",
    "sass": "1.30.0",
    "runjs": "4.4.2",
    "sass": "1.32.0",
    "sass-loader": "10.1.0",
    "script-ext-html-webpack-plugin": "2.1.5",
    "svg-sprite-loader": "5.1.1",
ruoyi-ui/src/components/FileUpload/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,178 @@
<template>
  <div class="upload-file">
    <el-upload
      :action="uploadFileUrl"
      :before-upload="handleBeforeUpload"
      :file-list="fileList"
      :limit="1"
      :on-error="handleUploadError"
      :on-exceed="handleExceed"
      :on-success="handleUploadSuccess"
      :show-file-list="false"
      :headers="headers"
      class="upload-file-uploader"
      ref="upload"
    >
      <!-- ä¸Šä¼ æŒ‰é’® -->
      <el-button size="mini" type="primary">选取文件</el-button>
      <!-- ä¸Šä¼ æç¤º -->
      <div class="el-upload__tip" slot="tip" v-if="showTip">
        è¯·ä¸Šä¼ 
        <template v-if="fileSize"> å¤§å°ä¸è¶…过 <b style="color: #f56c6c">{{ fileSize }}MB</b> </template>
        <template v-if="fileType"> æ ¼å¼ä¸º <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
        çš„æ–‡ä»¶
      </div>
    </el-upload>
    <!-- æ–‡ä»¶åˆ—表 -->
    <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
      <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in list">
        <el-link :href="file.url" :underline="false" target="_blank">
          <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
        </el-link>
        <div class="ele-upload-list__item-content-action">
          <el-link :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
        </div>
      </li>
    </transition-group>
  </div>
</template>
<script>
import { getToken } from "@/utils/auth";
export default {
  props: {
    // å€¼
    value: [String, Object, Array],
    // å¤§å°é™åˆ¶(MB)
    fileSize: {
      type: Number,
      default: 5,
    },
    // æ–‡ä»¶ç±»åž‹, ä¾‹å¦‚['png', 'jpg', 'jpeg']
    fileType: {
      type: Array,
      default: () => ["doc", "xls", "ppt", "txt", "pdf"],
    },
    // æ˜¯å¦æ˜¾ç¤ºæç¤º
    isShowTip: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // ä¸Šä¼ çš„图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      fileList: [],
    };
  },
  computed: {
    // æ˜¯å¦æ˜¾ç¤ºæç¤º
    showTip() {
      return this.isShowTip && (this.fileType || this.fileSize);
    },
    // åˆ—表
    list() {
      let temp = 1;
      if (this.value) {
        // é¦–先将值转为数组
        const list = Array.isArray(this.value) ? this.value : [this.value];
        // ç„¶åŽå°†æ•°ç»„转为对象数组
        return list.map((item) => {
          if (typeof item === "string") {
            item = { name: item, url: item };
          }
          item.uid = item.uid || new Date().getTime() + temp++;
          return item;
        });
      } else {
        return [];
      }
    },
  },
  methods: {
    // ä¸Šä¼ å‰æ ¡æ£€æ ¼å¼å’Œå¤§å°
    handleBeforeUpload(file) {
      // æ ¡æ£€æ–‡ä»¶ç±»åž‹
      if (this.fileType) {
        let fileExtension = "";
        if (file.name.lastIndexOf(".") > -1) {
          fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
        }
        const isTypeOk = this.fileType.some((type) => {
          if (file.type.indexOf(type) > -1) return true;
          if (fileExtension && fileExtension.indexOf(type) > -1) return true;
          return false;
        });
        if (!isTypeOk) {
          this.$message.error(`文件格式不正确, è¯·ä¸Šä¼ ${this.fileType.join("/")}格式文件!`);
          return false;
        }
      }
      // æ ¡æ£€æ–‡ä»¶å¤§å°
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      return true;
    },
    // æ–‡ä»¶ä¸ªæ•°è¶…出
    handleExceed() {
      this.$message.error(`只允许上传单个文件`);
    },
    // ä¸Šä¼ å¤±è´¥
    handleUploadError(err) {
      this.$message.error("上传失败, è¯·é‡è¯•");
    },
    // ä¸Šä¼ æˆåŠŸå›žè°ƒ
    handleUploadSuccess(res, file) {
      this.$message.success("上传成功");
      this.$emit("input", res.url);
    },
    // åˆ é™¤æ–‡ä»¶
    handleDelete(index) {
      this.fileList.splice(index, 1);
      this.$emit("input", '');
    },
    // èŽ·å–æ–‡ä»¶åç§°
    getFileName(name) {
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
      } else {
        return "";
      }
    }
  },
  created() {
    this.fileList = this.list;
  },
};
</script>
<style scoped lang="scss">
.upload-file-uploader {
  margin-bottom: 5px;
}
.upload-file-list .el-upload-list__item {
  border: 1px solid #e4e7ed;
  line-height: 2;
  margin-bottom: 10px;
  position: relative;
}
.upload-file-list .ele-upload-list__item-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: inherit;
}
.ele-upload-list__item-content-action .el-link {
  margin-right: 10px;
}
</style>
ruoyi-ui/src/components/HeaderSearch/index.vue
@@ -20,7 +20,7 @@
<script>
// fuse is a lightweight fuzzy-search module
// make search results more in line with expectations
import Fuse from 'fuse.js'
import Fuse from 'fuse.js/dist/fuse.min.js'
import path from 'path'
export default {
ruoyi-ui/src/components/ImageUpload/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,100 @@
<template>
  <div class="component-upload-image">
    <el-upload
      :action="uploadImgUrl"
      list-type="picture-card"
      :on-success="handleUploadSuccess"
      :before-upload="handleBeforeUpload"
      :on-error="handleUploadError"
      name="file"
      :show-file-list="false"
      :headers="headers"
      style="display: inline-block; vertical-align: top"
    >
      <el-image v-if="!value" :src="value">
        <div slot="error" class="image-slot">
          <i class="el-icon-plus" />
        </div>
      </el-image>
      <div v-else class="image">
        <el-image :src="value" :style="`width:150px;height:150px;`" fit="fill"/>
        <div class="mask">
          <div class="actions">
            <span title="预览" @click.stop="dialogVisible = true">
              <i class="el-icon-zoom-in" />
            </span>
            <span title="移除" @click.stop="removeImage">
              <i class="el-icon-delete" />
            </span>
          </div>
        </div>
      </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible" title="预览" width="800" append-to-body>
      <img :src="value" style="display: block; max-width: 100%; margin: 0 auto;">
    </el-dialog>
  </div>
</template>
<script>
import { getToken } from "@/utils/auth";
export default {
  data() {
    return {
      dialogVisible: false,
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // ä¸Šä¼ çš„图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
    };
  },
  props: {
    value: {
      type: String,
      default: "",
    },
  },
  methods: {
    removeImage() {
      this.$emit("input", "");
    },
    handleUploadSuccess(res) {
      this.$emit("input", res.url);
      this.loading.close();
    },
    handleBeforeUpload() {
      this.loading = this.$loading({
        lock: true,
        text: "上传中",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    handleUploadError() {
      this.$message({
        type: "error",
        message: "上传失败",
      });
      this.loading.close();
    },
  },
  watch: {},
};
</script>
<style scoped lang="scss">
.image {
  position: relative;
  .mask {
    opacity: 0;
    position: absolute;
    top: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    transition: all 0.3s;
  }
  &:hover .mask {
    opacity: 1;
  }
}
</style>
ruoyi-ui/src/components/UploadImage/index.vue
ÎļþÒÑɾ³ý
ruoyi-ui/src/main.js
@@ -20,9 +20,6 @@
import Pagination from "@/components/Pagination";
// è‡ªå®šä¹‰è¡¨æ ¼å·¥å…·æ‰©å±•
import RightToolbar from "@/components/RightToolbar"
// ä»£ç é«˜äº®æ’ä»¶
import hljs from 'highlight.js'
import 'highlight.js/styles/github-gist.css'
// å…¨å±€æ–¹æ³•挂载
Vue.prototype.getDicts = getDicts
@@ -52,7 +49,6 @@
Vue.component('RightToolbar', RightToolbar)
Vue.use(permission)
Vue.use(hljs.vuePlugin);
/**
 * If you don't want to use mock-server
ruoyi-ui/src/views/tool/gen/editTable.vue
@@ -90,7 +90,8 @@
                <el-option label="单选框" value="radio" />
                <el-option label="复选框" value="checkbox" />
                <el-option label="日期控件" value="datetime" />
                <el-option label="上传控件" value="uploadImage" />
                <el-option label="图片上传" value="imageUpload" />
                <el-option label="文件上传" value="fileUpload" />
                <el-option label="富文本控件" value="editor" />
              </el-select>
            </template>
ruoyi-ui/src/views/tool/gen/index.vue
@@ -169,7 +169,7 @@
          :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))"
          :key="key"
        >
        <highlightjs autodetect :code="value" />
        <pre><code class="hljs" v-html="highlightedCode(value, key)"></code></pre>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
@@ -181,6 +181,14 @@
import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
import importTable from "./importTable";
import { downLoadZip } from "@/utils/zipdownload";
import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css";
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("vue", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascript"));
hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"));
export default {
  name: "Gen",
@@ -294,6 +302,13 @@
        this.preview.open = true;
      });
    },
    /** é«˜äº®æ˜¾ç¤º */
    highlightedCode(code, key) {
      const vmName = key.substring(key.lastIndexOf("/") + 1, key.indexOf(".vm"));
      var language = vmName.substring(vmName.indexOf(".") + 1, vmName.length);
      const result = hljs.highlight(language, code || "", true);
      return result.value || '&nbsp;';
    },
    // å¤šé€‰æ¡†é€‰ä¸­æ•°æ®
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tableId);