Pārlūkot izejas kodu

feature:修改代码生成模版

ZZH-wl 2 gadi atpakaļ
vecāks
revīzija
a4d6254513
9 mainītis faili ar 61 papildinājumiem un 99 dzēšanām
  1. 1 1
      .env.development
  2. 5 2
      .env.production
  3. 1 1
      prettier.config.js
  4. 2 1
      src/main.js
  5. 12 27
      src/utils/index.js
  6. 12 31
      src/utils/micro_request.js
  7. 19 23
      template/api.hbs
  8. 2 2
      template/edit.hbs
  9. 7 11
      template/index.hbs

+ 1 - 1
.env.development

@@ -8,4 +8,4 @@ VUE_APP_MicroSrvProxy_API=http://127.0.0.1:9981/
 VUE_APP_AdminPath=dashoo.opms.admin-0.0.1
 
 # 业务接口微服务名称
-VUE_APP_ParentPath=dashoo.opms.parent-0.0.1
+VUE_APP_ParentPath=dashoo.opms.parent-0.0.1

+ 5 - 2
.env.production

@@ -1,8 +1,11 @@
 # 租户码
 VUE_APP_TENANT=default
+
+# GateWay地址
+VUE_APP_MicroSrvProxy_API=http://127.0.0.1:9981/
+
 # 登录验证微服务名称
 VUE_APP_AdminPath=dashoo.opms.admin-0.0.1
-VUE_APP_MicroSrvProxy_API=http://127.0.0.1:9981/
 
 # 业务接口微服务名称
-VUE_APP_ParentPath=dashoo.opms.parent-0.0.1
+VUE_APP_ParentPath=dashoo.opms.parent-0.0.1

+ 1 - 1
prettier.config.js

@@ -1,5 +1,5 @@
 module.exports = {
-  printWidth: 80,
+  printWidth: 120,
   tabWidth: 2,
   useTabs: false,
   semi: false,

+ 2 - 1
src/main.js

@@ -5,12 +5,13 @@ import store from './store'
 import router from './router'
 import '@/vab'
 
-import { parseTime, translateDataToTree } from '@/utils'
+import { parseTime, translateDataToTree, resetForm } from '@/utils'
 import dictApi from '@/api/system/dict'
 
 Vue.prototype.parseTime = parseTime
 Vue.prototype.translateDataToTree = translateDataToTree
 Vue.prototype.getDicts = dictApi.getDictDataByType
+Vue.prototype.resetForm = resetForm
 
 Vue.config.productionTip = false
 new Vue({

+ 12 - 27
src/utils/index.js

@@ -75,17 +75,7 @@ export function formatTime(time, option) {
   if (option) {
     return parseTime(time, option)
   } else {
-    return (
-      d.getMonth() +
-      1 +
-      '月' +
-      d.getDate() +
-      '日' +
-      d.getHours() +
-      '时' +
-      d.getMinutes() +
-      '分'
-    )
+    return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
   }
 }
 
@@ -101,11 +91,7 @@ export function paramObj(url) {
   }
   return JSON.parse(
     '{"' +
-      decodeURIComponent(search)
-        .replace(/"/g, '\\"')
-        .replace(/&/g, '","')
-        .replace(/=/g, '":"')
-        .replace(/\+/g, ' ') +
+      decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"').replace(/\+/g, ' ') +
       '"}'
   )
 }
@@ -117,16 +103,10 @@ export function paramObj(url) {
  */
 export function translateDataToTree(data) {
   const parent = data.filter(
-    (value) =>
-      value.parentId === 'undefined' ||
-      value.parentId === null ||
-      value.parentId === 0
+    (value) => value.parentId === 'undefined' || value.parentId === null || value.parentId === 0
   )
   const children = data.filter(
-    (value) =>
-      value.parentId !== 'undefined' &&
-      value.parentId !== null &&
-      value.parentId !== 0
+    (value) => value.parentId !== 'undefined' && value.parentId !== null && value.parentId !== 0
   )
   const translator = (parent, children) => {
     parent.forEach((parent) => {
@@ -135,9 +115,7 @@ export function translateDataToTree(data) {
           const temp = JSON.parse(JSON.stringify(children))
           temp.splice(index, 1)
           translator([current], temp)
-          typeof parent.children !== 'undefined'
-            ? parent.children.push(current)
-            : (parent.children = [current])
+          typeof parent.children !== 'undefined' ? parent.children.push(current) : (parent.children = [current])
         }
       })
     })
@@ -279,3 +257,10 @@ export function shuffle(array) {
   }
   return array
 }
+
+// 表单重置
+export function resetForm(refName) {
+  if (this.$refs[refName]) {
+    this.$refs[refName].resetFields()
+  }
+}

+ 12 - 31
src/utils/micro_request.js

@@ -77,10 +77,7 @@ service.postRequest = function postRequest(basePath, srvName, funcName, data) {
   var base_Path = ''
   if (basePath == process.env.VUE_APP_FOSHAN_PATH) {
     base_Path = process.env.VUE_APP_MicroSrvProxy_foshan_API + basePath
-  } else if (
-    basePath == process.env.VUE_APP_AdminPath ||
-    process.env.VUE_APP_ParentPath
-  ) {
+  } else if (basePath == process.env.VUE_APP_AdminPath || process.env.VUE_APP_ParentPath) {
     base_Path = process.env.VUE_APP_MicroSrvProxy_API + basePath
   } else {
     base_Path = process.env.VUE_APP_MicroSrvProxy_API + basePath
@@ -99,12 +96,7 @@ service.postRequest = function postRequest(basePath, srvName, funcName, data) {
   })
 }
 // 发出请求并要求把客户端信息传输给后端(IP和User-Agent)
-service.postRequestWithClientInfo = function postRequest(
-  basePath,
-  srvName,
-  funcName,
-  data
-) {
+service.postRequestWithClientInfo = function postRequest(basePath, srvName, funcName, data) {
   if (data == undefined) {
     let nullParam = { nullparam: 0 }
     data = nullParam
@@ -124,12 +116,7 @@ service.postRequestWithClientInfo = function postRequest(
 }
 
 // Excel文件下载(服务端生成文件流)
-service.downloadExcel = function downloadExcel(
-  basePath,
-  srvName,
-  funcName,
-  data
-) {
+service.downloadExcel = function downloadExcel(basePath, srvName, funcName, data) {
   if (data == undefined) {
     let nullParam = {
       nullparam: 0,
@@ -137,9 +124,9 @@ service.downloadExcel = function downloadExcel(
     data = nullParam
   }
   var base_Path = ''
-  if (basePath == process.env.VUE_APP_FOSHAN_PATH) {
-    base_Path = process.env.VUE_APP_MicroSrvProxy_foshan_API + basePath
-  } else if (basePath == process.env.VUE_APP_AdminPath) {
+  if (basePath == process.env.VUE_APP_AdminPath) {
+    base_Path = process.env.VUE_APP_MicroSrvProxy_API + basePath
+  } else if (basePath == process.env.VUE_APP_ParentPath) {
     base_Path = process.env.VUE_APP_MicroSrvProxy_API + basePath
   }
   service.request({
@@ -162,15 +149,11 @@ function processResponse(res) {
   // 获取错误信息
   const message = errorCode[code] || res.data.msg || errorCode['default']
   if (code === 401) {
-    MessageBox.confirm(
-      '登录状态已过期,您可以继续留在该页面,或者重新登录',
-      '系统提示',
-      {
-        confirmButtonText: '重新登录',
-        cancelButtonText: '取消',
-        type: 'warning',
-      }
-    ).then(() => {
+    MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
+      confirmButtonText: '重新登录',
+      cancelButtonText: '取消',
+      type: 'warning',
+    }).then(() => {
       store.dispatch('user/logout').then(() => {
         if (process.env.SSO_LOGIN) {
           sessionStorage.removeItem('SSO_Token')
@@ -212,9 +195,7 @@ function downLoadBlobFile(res, mimeType) {
   })
   // //从response的headers中获取filename, 后端response.setHeader('Content-disposition', 'attachment filename=xxxx.docx') 设置的文件名
   var patt = new RegExp('filename=([^]+\\.[^\\.]+)*')
-  var contentDisposition = decodeURI(
-    res.headers['content-disposition'] || res.headers['Content-Disposition']
-  )
+  var contentDisposition = decodeURI(res.headers['content-disposition'] || res.headers['Content-Disposition'])
   var result = patt.exec(contentDisposition)
   var fileName = 'data.xlsx'
   if (result != undefined) {

+ 19 - 23
template/api.hbs

@@ -1,25 +1,21 @@
-import request from '@/utils/request'
+import micro_request from '@/utils/micro_request'
 
-export function getList(params) {
-  return request({
-    url: '/{{ name }}/getList',
-    method: 'get',
-    params,
-  })
-}
-
-export function doEdit(data) {
-  return request({
-    url: '/{{ name }}/doEdit',
-    method: 'post',
-    data,
-  })
-}
-
-export function doDelete(data) {
-  return request({
-    url: '/{{ name }}/doDelete',
-    method: 'post',
-    data,
-  })
+const basePath = process.env.VUE_APP_AdminPath
+export default {
+  // 获取列表
+  getList(query) {
+    return micro_request.postRequest(basePath, '{{ properCase name }}', 'GetList', query)
+  },
+  getEntityById(query) {
+    return micro_request.postRequest(basePath, '{{ properCase name }}', 'GetEntityById', query)
+  },
+  doAdd(query) {
+    return micro_request.postRequest(basePath, '{{ properCase name }}', 'Create', query)
+  },
+  doEdit(query) {
+    return micro_request.postRequest(basePath, '{{ properCase name }}', 'UpdateById', query)
+  },
+  doDelete(query) {
+    return micro_request.postRequest(basePath, '{{ properCase name }}', 'DeleteByIds', query)
+  },
 }

+ 2 - 2
template/edit.hbs

@@ -18,7 +18,7 @@
 </template>
 
 <script>
-  import { doEdit } from '@/api/{{moduleName}}/{{ camelCase name }}'
+  import {{ camelCase name }}Api from '@/api/{{moduleName}}/{{ camelCase name }}'
 
   export default {
     name: '{{ properCase name }}Edit',
@@ -53,7 +53,7 @@
       save() {
         this.$refs['form'].validate(async (valid) => {
           if (valid) {
-            const { msg } = await doEdit(this.form)
+            const { msg } = await {{ camelCase name }}Api.doEdit(this.form)
             this.$baseMessage(msg, 'success')
             this.$emit('fetch-data')
             this.close()

+ 7 - 11
template/index.hbs

@@ -18,8 +18,7 @@
       v-loading="listLoading"
       :data="list"
       :height="height"
-      @selection-change="setSelectRows"
-    >
+      @selection-change="setSelectRows">
       <el-table-column align="center" show-overflow-tooltip type="selection" />
       <el-table-column
         v-for="(item, index) in finallyColumns"
@@ -29,9 +28,7 @@
         :prop="item.prop"
         show-overflow-tooltip
         :sortable="item.sortable"
-        :width="item.width"
-      >
-      </el-table-column>
+        :width="item.width" />
 
       <el-table-column align="center" label="操作" width="85">
         <template #default="{ row }">
@@ -47,14 +44,13 @@
       :page-size="queryForm.pageSize"
       :total="total"
       @current-change="handleCurrentChange"
-      @size-change="handleSizeChange"
-    />
+      @size-change="handleSizeChange" />
     <edit ref="edit" @fetch-data="fetchData" />
   </div>
 </template>
 
 <script>
-  import { getList, doDelete } from '@/api/{{moduleName}}/{{ camelCase name }}'
+  import {{ camelCase name }}Api from '@/api/{{moduleName}}/{{ camelCase name }}'
   import Edit from './components/{{ properCase name }}Edit'
   import TableTool from '@/components/table/TableTool'
 
@@ -102,7 +98,7 @@
       handleDelete(row) {
         if (row.id) {
           this.$baseConfirm('你确定要删除当前项吗', null, async () => {
-            const { msg } = await doDelete({ ids: [row.id] })
+            const { msg } = await {{ camelCase name }}Api.doDelete({ ids: [row.id] })
             this.$baseMessage(msg, 'success')
             await this.fetchData()
           })
@@ -110,7 +106,7 @@
           if (this.selectRows.length > 0) {
             const ids = this.selectRows.map((item) => item.id)
             this.$baseConfirm('你确定要删除选中项吗', null, async () => {
-              const { msg } = await doDelete({ ids })
+              const { msg } = await {{ camelCase name }}Api.doDelete({ ids })
               this.$baseMessage(msg, 'success')
               await this.fetchData()
             })
@@ -134,7 +130,7 @@
       },
       async fetchData() {
         this.listLoading = true
-        const { data } = await getList(this.queryForm)
+        const { data } = await {{ camelCase name }}Api.getList(this.queryForm)
         const { list, total } = data
         this.list = list
         this.total = total