Pārlūkot izejas kodu

更改通用接口调用方式

cyy 2 gadi atpakaļ
vecāks
revīzija
1cd9d5d747

+ 2 - 2
src/main.js

@@ -16,7 +16,7 @@ import store from "./store";
 import "./errorLog"; // error log 错误日志
 import "./errorLog"; // error log 错误日志
 import i18n from "./i18n"; // Internationalization 国际化
 import i18n from "./i18n"; // Internationalization 国际化
 import utils from "./utils/util"; // utils 帮助类
 import utils from "./utils/util"; // utils 帮助类
-import request from "./utils/joinCURD"; // 通用请求
+import common from "./utils/common"; // 通用请求
 import env from "@/env";
 import env from "@/env";
 import ActionUtils from "@/utils/action";
 import ActionUtils from "@/utils/action";
 
 
@@ -25,7 +25,7 @@ import Vant from "vant";
 Vue.use(Vant); // 导入vant
 Vue.use(Vant); // 导入vant
 Vue.prototype.$action = ActionUtils; // 全局action
 Vue.prototype.$action = ActionUtils; // 全局action
 Vue.prototype.$utils = utils; // 全局帮助类
 Vue.prototype.$utils = utils; // 全局帮助类
-Vue.prototype.$request = request; // 通用请求
+Vue.prototype.$common = common; // 通用请求
 // 基础路径
 // 基础路径
 Vue.prototype.$baseUrl = process.env.VUE_APP_PUBLIC_PATH || "/";
 Vue.prototype.$baseUrl = process.env.VUE_APP_PUBLIC_PATH || "/";
 // 当前环境
 // 当前环境

+ 5 - 3
src/store/modules/ibps/modules/user.js

@@ -1,5 +1,5 @@
 import { getUserInfo } from "@/api/oauth2/user";
 import { getUserInfo } from "@/api/oauth2/user";
-import common from "@/utils/joinCURD";
+import common from "@/utils/common";
 
 
 export default {
 export default {
   namespaced: true,
   namespaced: true,
@@ -162,7 +162,8 @@ export default {
         ? `'%${first}%'`
         ? `'%${first}%'`
         : "%%";
         : "%%";
       const sql = `select users.id_ as userId, users.name_ as userName, ifnull(users.mobile_, '') as phone, ifnull(group_concat(distinct positions.id_ order by positions.id_ separator ','), '') as positionId, ifnull(group_concat(distinct positions.name_ order by positions.id_ separator ','), '') as positions, ifnull(group_concat(distinct roles.id_ order by roles.role_note_ asc separator ','), '') as roleId, ifnull(group_concat(distinct roles.name_ order by roles.role_note_ asc separator ','), '') as roles, (select ifnull(people.qian_zi_tu_wen_, '') from t_ryjbqk as people where people.parent_id_ = users.id_) as signatureId, (select ifnull(files.file_name_, '') from ibps_file_attachment as files where files.id_ = signatureId) as signatureName from ibps_party_employee as users left join (select ur.user_id_, r.role_note_, group_concat(distinct r.id_ order by r.id_ separator ',') as id_, group_concat(distinct r.name_ order by r.id_ separator ',') as name_ from ibps_party_user_role as ur join ibps_party_role as r on ur.role_id_ = r.id_ group by ur.user_id_) as roles on users.id_ = roles.user_id_ left join ibps_party_entity as positions on find_in_set(positions.id_, users.positions_) where exists (select 1 from ibps_party_entity as entity where find_in_set(entity.id_, users.positions_) and (entity.path_ like ${params})) group by users.id_`;
       const sql = `select users.id_ as userId, users.name_ as userName, ifnull(users.mobile_, '') as phone, ifnull(group_concat(distinct positions.id_ order by positions.id_ separator ','), '') as positionId, ifnull(group_concat(distinct positions.name_ order by positions.id_ separator ','), '') as positions, ifnull(group_concat(distinct roles.id_ order by roles.role_note_ asc separator ','), '') as roleId, ifnull(group_concat(distinct roles.name_ order by roles.role_note_ asc separator ','), '') as roles, (select ifnull(people.qian_zi_tu_wen_, '') from t_ryjbqk as people where people.parent_id_ = users.id_) as signatureId, (select ifnull(files.file_name_, '') from ibps_file_attachment as files where files.id_ = signatureId) as signatureName from ibps_party_employee as users left join (select ur.user_id_, r.role_note_, group_concat(distinct r.id_ order by r.id_ separator ',') as id_, group_concat(distinct r.name_ order by r.id_ separator ',') as name_ from ibps_party_user_role as ur join ibps_party_role as r on ur.role_id_ = r.id_ group by ur.user_id_) as roles on users.id_ = roles.user_id_ left join ibps_party_entity as positions on find_in_set(positions.id_, users.positions_) where exists (select 1 from ibps_party_entity as entity where find_in_set(entity.id_, users.positions_) and (entity.path_ like ${params})) group by users.id_`;
-      common("sql", sql)
+      common
+        .request("sql", sql)
         .then(res => {
         .then(res => {
           const { data = [] } = res.variables || {};
           const { data = [] } = res.variables || {};
           dispatch("ibps/param/setUserList", data, {
           dispatch("ibps/param/setUserList", data, {
@@ -185,7 +186,8 @@ export default {
         : "";
         : "";
       // const sql = `select id_ as positionId, name_ as positionName, path_ as path, depth_ as depth, sn_ as sn from ibps_party_entity where party_type_ = 'position'${params} order by depth_ asc, sn_ asc`
       // const sql = `select id_ as positionId, name_ as positionName, path_ as path, depth_ as depth, sn_ as sn from ibps_party_entity where party_type_ = 'position'${params} order by depth_ asc, sn_ asc`
       const sql = `select pe.id_ as positionId, pe.name_ as positionName, pe.path_ as path, pe.depth_ as depth, pe.sn_ as sn, ifnull(r.name_, '') as manager, ifnull(r.id_, '') as managerId from ibps_party_entity as pe left join (select em.id_, em.positions_, em.name_ from ibps_party_employee as em left join ibps_party_user_role as ur on em.id_ = ur.user_id_ left join ibps_party_role as pr on pr.id_ = ur.role_id_ where role_alias_ in ('zhsfzr', 'syszr', 'zhglzzc')) as r on find_in_set(pe.id_, r.positions_) > 0 where pe.party_type_ = 'position'${params} group by pe.id_ order by pe.depth_ asc, pe.sn_ asc,pe.id_ asc`;
       const sql = `select pe.id_ as positionId, pe.name_ as positionName, pe.path_ as path, pe.depth_ as depth, pe.sn_ as sn, ifnull(r.name_, '') as manager, ifnull(r.id_, '') as managerId from ibps_party_entity as pe left join (select em.id_, em.positions_, em.name_ from ibps_party_employee as em left join ibps_party_user_role as ur on em.id_ = ur.user_id_ left join ibps_party_role as pr on pr.id_ = ur.role_id_ where role_alias_ in ('zhsfzr', 'syszr', 'zhglzzc')) as r on find_in_set(pe.id_, r.positions_) > 0 where pe.party_type_ = 'position'${params} group by pe.id_ order by pe.depth_ asc, pe.sn_ asc,pe.id_ asc`;
-      common("sql", sql)
+      common
+        .request("sql", sql)
         .then(res => {
         .then(res => {
           console.log(res, "sqlsqlsql");
           console.log(res, "sqlsqlsql");
           const { data = [] } = res.variables || {};
           const { data = [] } = res.variables || {};

+ 237 - 0
src/utils/common.js

@@ -0,0 +1,237 @@
+// 通用工具类,定义通用函数及常用接口
+import { mapValues } from "lodash";
+import { encryptByAes } from "@/utils/encrypt";
+// import { preview } from '@/business/platform/form/utils/custom/preview'
+import request from "./joinCURD";
+import pinyin4js from "pinyin4js";
+import { snapshoot } from "@/api/platform/file/attachment";
+import { getNextIdByAlias } from "@/api/platform/system/identity";
+import { save as sendMsg } from "@/api/platform/message/innerMessage";
+import { save as saveNews } from "@/api/platform/system/news";
+import { bpmTaskSave } from "@/api/platform/bpmn/bpmTask";
+// import { onlyOfficeToPdf } from '@/api/platform/form/seal'
+import { downloadFile as download } from "@/business/platform/file/utils";
+// import { removeFormData } from '@/api/platform/data/dataTemplate'
+// 引入工具类
+import Utils from "@/utils/util";
+import ActionUtils from "@/utils/action";
+
+// base64解码
+const decode = str =>
+  decodeURIComponent(
+    window
+      .atob(str)
+      .split("")
+      .map(c => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
+      .join("")
+  );
+
+// 下载
+export const downloadByBlob = (o, name) => {
+  if (!(o instanceof Blob)) {
+    return;
+  }
+
+  if (window.navigator.msSaveBlob) {
+    window.navigator.msSaveBlob(o, name);
+  } else {
+    const URL = window.URL || window.webkitURL || window;
+    const e = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
+    e.href = URL.createObjectURL(o);
+    e.download = name;
+
+    if (document.all) {
+      e.click();
+    } else {
+      const ev = document.createEvent("MouseEvents");
+      ev.initMouseEvent(
+        "click",
+        true,
+        false,
+        window,
+        0,
+        0,
+        0,
+        0,
+        false,
+        false,
+        false,
+        false,
+        0,
+        null
+      );
+      e.dispatchEvent(ev);
+    }
+  }
+};
+
+// 获取当前时间
+export const getDateNow = (length = 10, formatType) => {
+  if (formatType === "string") {
+    return new Date(new Date().getTime() + 28800000)
+      .toJSON()
+      .slice(0, length)
+      .replace(/[-:T]/g, "");
+  }
+  return new Date(new Date().getTime() + 28800000)
+    .toJSON()
+    .slice(0, length)
+    .replace("T", " ");
+};
+
+// 获取指定值后的日期
+export const getDate = (type, value, date) => {
+  const d = date || getDateNow(19);
+  if (
+    typeof type !== "string" ||
+    !Number.isInteger(value) ||
+    typeof d !== "string"
+  ) {
+    console.log("参数类型错误");
+    return null;
+  }
+  const now = new Date(d);
+  const D = {
+    day: value * 24 * 60 * 60 * 1000,
+    hour: value * 60 * 60 * 1000,
+    minute: value * 60 * 1000,
+    second: value * 1000
+  };
+  const year = now.getFullYear();
+  const month = now.getMonth();
+  const day = now.getDate();
+  const hour = now.getHours();
+  const minute = now.getMinutes();
+  const second = now.getSeconds();
+
+  switch (type) {
+    case "year": {
+      const isLeapYear = new Date(year + value, 1, 29).getDate() === 29;
+      return new Date(
+        year + value,
+        isLeapYear && month === 1 && day === 29 ? 1 : month,
+        isLeapYear && month === 1 && day === 29 ? 29 : day,
+        hour,
+        minute,
+        second
+      );
+    }
+    case "month": {
+      let newYear = year;
+      let newMonth = month + value;
+      if (newMonth < 0) {
+        newYear -= Math.ceil(Math.abs(newMonth) / 12);
+        newMonth = 12 - (Math.abs(newMonth) % 12);
+      } else if (newMonth > 11) {
+        newYear += Math.floor(newMonth / 12);
+        newMonth = newMonth % 12;
+      }
+      const isLeapMonth = new Date(newYear, newMonth + 1, 0).getDate() === 29;
+      return new Date(
+        newYear,
+        isLeapMonth && month === 1 && day === 29 ? 1 : newMonth,
+        isLeapMonth && month === 1 && day === 29 ? 29 : day,
+        hour,
+        minute,
+        second
+      );
+    }
+    case "day":
+    case "hour":
+    case "minute":
+    case "second":
+      return new Date(now.getTime() + D[type]);
+    default:
+      console.log("无效的日期类型");
+      return null;
+  }
+};
+
+// 时间格式化
+export const getFormatDate = (type, length, date = new Date()) => {
+  const now = new Date(new Date(date).getTime());
+  // eslint-disable-next-line
+  if (now == "Invalid Date") {
+    console.log("非法日期,无法格式化");
+    return date;
+  }
+  const year = now.getFullYear();
+  const month = now.getMonth() + 1;
+  const day = now.getDate();
+  const hours = now.getHours();
+  const minutes = now.getMinutes();
+  const seconds = now.getSeconds();
+  // 补零
+  const padZero = num => {
+    return num.toString().padStart(2, "0");
+  };
+  // 默认返回String类型
+  let result = `${year}-${padZero(month)}-${padZero(day)} ${padZero(
+    hours
+  )}:${padZero(minutes)}:${padZero(seconds)}`;
+  switch (type) {
+    case "string":
+      result = `${year}-${padZero(month)}-${padZero(day)} ${padZero(
+        hours
+      )}:${padZero(minutes)}:${padZero(seconds)}`;
+      break;
+    case "cn":
+      result = `${year}年${padZero(month)}月${padZero(day)}日 ${padZero(
+        hours
+      )}时${padZero(minutes)}分${padZero(seconds)}秒`;
+      break;
+    case "number":
+      result = `${year}${padZero(month)}${padZero(day)}${padZero(
+        hours
+      )}${padZero(minutes)}${padZero(seconds)}`;
+      break;
+    default:
+      break;
+  }
+  return result.slice(0, length || result.length);
+};
+
+/**
+ * 替换对象中的null为空字符串
+ * @param  {Object} obj 目标对象
+ */
+export const replaceNullWithEmpty = obj => {
+  function replaceValue(value) {
+    if (value === null) {
+      return "";
+    } else if (typeof value === "object") {
+      if (Array.isArray(value)) {
+        return value.map(item => replaceValue(item));
+      } else {
+        return mapValues(value, v => replaceValue(v));
+      }
+    } else {
+      return value;
+    }
+  }
+  return replaceValue(obj);
+};
+
+export default {
+  // preview,
+  request,
+  pinyin4js,
+  snapshoot,
+  getNextIdByAlias,
+  decode,
+  encryptByAes,
+  downloadByBlob,
+  sendMsg,
+  saveNews,
+  bpmTaskSave,
+  getDate,
+  getDateNow,
+  getFormatDate,
+  // onlyOfficeToPdf,
+  generateUUID: Utils.guid,
+  download,
+  // removeFormData,
+  replaceNullWithEmpty,
+  Utils,
+  ActionUtils
+};

+ 0 - 9
src/views/platform/my/index.vue

@@ -125,15 +125,6 @@ export default {
       return pos.join(',')
       return pos.join(',')
     }
     }
   },
   },
-  // created(){
-  //   const sql = `select a.ID_ as ID_, a.NAME_ as NAME_, b.path_ as PATH_ FROM ibps_party_position a, ibps_party_entity b where a.id_ = b.id_`
-  //   console.log(this, 'thisthis')
-  //   this.$request('sql', sql).then((res) => {
-  //     console.log(this.info, res, 'resresresresresresres')
-  //     this.positionList = res.variables.data || []
-  //     // resolve()
-  //   })
-  // },
   methods: {
   methods: {
     userInfo() {
     userInfo() {
       this.$router.push({ name: 'userInfo' })
       this.$router.push({ name: 'userInfo' })