猜你想问接口联调

master
wujingling0908 2 weeks ago
parent 86bd523a3d
commit 497c5196f8
  1. 5
      src/components/abstract.vue
  2. 641
      src/utils/index.js

@ -47,6 +47,9 @@ const businessHandle = () => {
}); });
} }
} }
const toDetail = (record) => {
console.log(window);
}
onMounted(async () => { onMounted(async () => {
businessHandle() businessHandle()
}) })
@ -72,7 +75,7 @@ onMounted(async () => {
</div> </div>
</div> </div>
</div> </div>
<div class="btn" :style="{ background: item.btnBg }">{{ item.btnText }}</div> <div class="btn" :style="{ background: item.btnBg }" @click="toDetail(item)">{{ item.btnText }}</div>
</div> </div>
</div> </div>
</div> </div>

@ -1,15 +1,16 @@
// import Vue from 'vue' // import Vue from 'vue'
import router from '@/router' import router from '@/router'
import store from '@/store'
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import utils from '@/utils/utils';
import wx from 'weixin-js-sdk';
import { useAppStore } from '@/store/app.js'
/** /**
* 获取uuid * 获取uuid
*/ */
export function getUUID() { export function getUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16) return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
}) })
} }
/** /**
@ -17,7 +18,7 @@ export function getUUID() {
* @param {*} key * @param {*} key
*/ */
export function isAuth(key) { export function isAuth(key) {
return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false return JSON.parse(sessionStorage.getItem('permissions') || '[]').indexOf(key) !== -1 || false
} }
/** /**
@ -27,53 +28,53 @@ export function isAuth(key) {
* @param {*} pid * @param {*} pid
*/ */
export function treeDataTranslate(data, id = 'id', pid = 'parentId') { export function treeDataTranslate(data, id = 'id', pid = 'parentId') {
var res = [] var res = []
var temp = {} var temp = {}
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
temp[data[i][id]] = data[i] temp[data[i][id]] = data[i]
} }
for (var k = 0; k < data.length; k++) { for (var k = 0; k < data.length; k++) {
if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) { if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
if (!temp[data[k][pid]]['children']) { if (!temp[data[k][pid]]['children']) {
temp[data[k][pid]]['children'] = [] temp[data[k][pid]]['children'] = []
} }
if (!temp[data[k][pid]]['_level']) { if (!temp[data[k][pid]]['_level']) {
temp[data[k][pid]]['_level'] = 1 temp[data[k][pid]]['_level'] = 1
} }
data[k]['_level'] = temp[data[k][pid]]._level + 1; data[k]['_level'] = temp[data[k][pid]]._level + 1;
temp[data[k][pid]]['children'].push(data[k]) temp[data[k][pid]]['children'].push(data[k])
} else { } else {
res.push(data[k]) res.push(data[k])
}
} }
return res }
return res
} }
export function toTreeArry(data) { export function toTreeArry(data) {
const result = [] const result = []
data.forEach(item => { data.forEach(item => {
const loop = data => { const loop = data => {
let child = data.children; let child = data.children;
if (child) { // 是否有子节点,有则继续遍历下一级,无则是叶子节点 if (child) { // 是否有子节点,有则继续遍历下一级,无则是叶子节点
for (let i = 0; i < child.length; i++) { for (let i = 0; i < child.length; i++) {
loop(child[i]) loop(child[i])
}
} else {
result.push(data)
}
} }
} else {
result.push(data)
}
}
loop(item) loop(item)
}) })
// console.log(JSON.stringify(result)) // console.log(JSON.stringify(result))
return result; return result;
} }
@ -91,31 +92,31 @@ export function toTreeArry(data) {
*/ */
export function listToTree(oldArr) { export function listToTree(oldArr) {
// 删除 所有 children,以防止多次调用 // 删除 所有 children,以防止多次调用
oldArr.forEach(function (item) { oldArr.forEach(function (item) {
item.checked = false; item.checked = false;
delete item.children; delete item.children;
}); });
oldArr.forEach(element => { oldArr.forEach(element => {
let parentId = element.parentId; let parentId = element.parentId;
if (parentId !== 0) { if (parentId !== 0) {
oldArr.forEach(ele => { oldArr.forEach(ele => {
if (ele.menuId == parentId) { //当内层循环的ID== 外层循环的parendId时,(说明有children),需要往该内层id里建个children并push对应的数组; if (ele.menuId == parentId) { //当内层循环的ID== 外层循环的parendId时,(说明有children),需要往该内层id里建个children并push对应的数组;
if (!ele.children) { if (!ele.children) {
ele.children = []; ele.children = [];
} }
// ele.children.push(element); // ele.children.push(element);
(ele.children || (ele.children = [])).push(element); (ele.children || (ele.children = [])).push(element);
}
});
} }
}); });
// console.log(oldArr) //此时的数组是在原基础上补充了children; }
oldArr = oldArr.filter(ele => ele.parentId === 0); //这一步是过滤,按树展开,将多余的数组剔除; });
// console.log(JSON.stringify(oldArr)) // console.log(oldArr) //此时的数组是在原基础上补充了children;
return oldArr; oldArr = oldArr.filter(ele => ele.parentId === 0); //这一步是过滤,按树展开,将多余的数组剔除;
// console.log(JSON.stringify(oldArr))
return oldArr;
} }
@ -126,33 +127,33 @@ export function listToTree(oldArr) {
* @param {*} parentId * @param {*} parentId
*/ */
export function toTree(data) { export function toTree(data) {
// 删除 所有 children,以防止多次调用 // 删除 所有 children,以防止多次调用
data.forEach(function (item) { data.forEach(function (item) {
item.checked = false; item.checked = false;
delete item.children; delete item.children;
}); });
// 将数据存储为 以 menuId 为 KEY 的 map 索引数据列 // 将数据存储为 以 menuId 为 KEY 的 map 索引数据列
var map = {}; var map = {};
data.forEach(function (item) { data.forEach(function (item) {
map[item.menuId] = item; map[item.menuId] = item;
}); });
var val = []; var val = [];
data.forEach(function (item) { data.forEach(function (item) {
// 以当前遍历项,的parentId,去map对象中找到索引的id // 以当前遍历项,的parentId,去map对象中找到索引的id
var parent = map[item.parentId]; var parent = map[item.parentId];
// 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中 // 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
if (parent) { if (parent) {
(parent.children || (parent.children = [])).push(item); (parent.children || (parent.children = [])).push(item);
} else { } else {
item.children = []; item.children = [];
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级 //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
val.push(item); val.push(item);
} }
}); });
// console.log(JSON.stringify(val)) // console.log(JSON.stringify(val))
return val; return val;
} }
@ -160,39 +161,39 @@ export function toTree(data) {
* 判断tree是不是最后一级 * 判断tree是不是最后一级
*/ */
export function isTail(data) { export function isTail(data) {
const child = data.children; const child = data.children;
return !child || child.length == 0; return !child || child.length == 0;
} }
/** /**
* 把tree树的最后一级的父类children改为menuOptionsList * 把tree树的最后一级的父类children改为menuOptionsList
*/ */
export function changeChildenName(data) { export function changeChildenName(data) {
const child = data.children; const child = data.children;
if (!!child && child.length > 0) { if (!!child && child.length > 0) {
if (isTail(child[0])) { if (isTail(child[0])) {
data.menuOptionsList = child; data.menuOptionsList = child;
data.children = []; data.children = [];
return; return;
}
child.forEach(changeChildenName);
} }
child.forEach(changeChildenName);
}
} }
//根据最后一个找到整个家族 //根据最后一个找到整个家族
export function familyTree(arr, parentId) { export function familyTree(arr, parentId) {
var temp = []; var temp = [];
var forFn = function (arr, parentId) { var forFn = function (arr, parentId) {
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var item = arr[i]; var item = arr[i];
if (item.menuId == parentId) { if (item.menuId == parentId) {
temp.push(item); temp.push(item);
forFn(arr, item.parentId); forFn(arr, item.parentId);
} }
} }
}; };
forFn(arr, parentId); forFn(arr, parentId);
return temp; return temp;
} }
@ -200,20 +201,20 @@ export function familyTree(arr, parentId) {
* 树转list * 树转list
*/ */
export function treeToList(tree) { export function treeToList(tree) {
for (var i in tree) { for (var i in tree) {
var node = tree[i]; var node = tree[i];
list = []; //结果lsit list = []; //结果lsit
if (node.children.length !== 0) { //遍历树的第一层,只有一个根结点 if (node.children.length !== 0) { //遍历树的第一层,只有一个根结点
//第一层加入到list中,因为根结点模块设置为虚拟结点,所以不用加入 //第一层加入到list中,因为根结点模块设置为虚拟结点,所以不用加入
/*list.push({ /*list.push({
id: node.id, id: node.id,
name: node.title, name: node.title,
parentId:node.parentId parentId:node.parentId
});*/ });*/
toListDF(node.children, list, node.menuId); //遍历子树,并加入到list中. toListDF(node.children, list, node.menuId); //遍历子树,并加入到list中.
}
} }
return list; }
return list;
} }
/** /**
@ -224,28 +225,27 @@ export function treeToList(tree) {
* @params parentId:当前遍历节点的父级节点id,初始为null(因为根节点无parentId) * @params parentId:当前遍历节点的父级节点id,初始为null(因为根节点无parentId)
**/ **/
export function toListDF(tree, list, parentId) { export function toListDF(tree, list, parentId) {
for (var i in tree) { //遍历最上层 for (var i in tree) { //遍历最上层
//将当前树放入list中 //将当前树放入list中
var node = tree[i]; var node = tree[i];
list.push({ list.push({
menuId: node.menuId, menuId: node.menuId,
name: node.title, name: node.title,
parentId: parentId parentId: parentId
}); });
//如果有子结点,再遍历子结点 //如果有子结点,再遍历子结点
if (node.children.length !== 0) { if (node.children.length !== 0) {
toListDF(node.children, list, node.menuId) //递归 toListDF(node.children, list, node.menuId) //递归
}
} }
}
} }
/** /**
* 清除登录信息 * 清除登录信息
*/ */
export function clearLoginInfo() { export function clearLoginInfo() {
// Vue.cookie.delete('token') // Vue.cookie.delete('token')
store.commit('resetStore') router.options.isAddDynamicMenuRoutes = false
router.options.isAddDynamicMenuRoutes = false
} }
@ -258,19 +258,19 @@ export function clearLoginInfo() {
*/ */
export function _debounce(fn, delay) { export function _debounce(fn, delay) {
var delay = delay || 500; var delay = delay || 500;
var timer; var timer;
return function () { return function () {
var th = this; var th = this;
var args = arguments; var args = arguments;
if (timer) { if (timer) {
clearTimeout(timer); clearTimeout(timer);
} }
timer = setTimeout(function () { timer = setTimeout(function () {
timer = null; timer = null;
fn.apply(th, args); fn.apply(th, args);
}, delay); }, delay);
}; };
} }
/** /**
@ -281,24 +281,24 @@ export function _debounce(fn, delay) {
* @constructor * @constructor
*/ */
export function _throttle(fn, interval) { export function _throttle(fn, interval) {
var last; var last;
var timer; var timer;
var interval = interval || 500; var interval = interval || 500;
return function () { return function () {
var th = this; var th = this;
var args = arguments; var args = arguments;
var now = +new Date(); var now = +new Date();
if (last && now - last < interval) { if (last && now - last < interval) {
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(function () { timer = setTimeout(function () {
last = now; last = now;
fn.apply(th, args); fn.apply(th, args);
}, interval); }, interval);
} else { } else {
last = now; last = now;
fn.apply(th, args); fn.apply(th, args);
}
} }
}
} }
/** /**
@ -308,98 +308,281 @@ export function _throttle(fn, interval) {
* @constructor * @constructor
*/ */
export function isJSON(str) { export function isJSON(str) {
if (typeof (str) === 'string') { if (typeof (str) === 'string') {
try { try {
var obj = JSON.parse(str); var obj = JSON.parse(str);
if (typeof (obj) === 'object' && obj) { if (typeof (obj) === 'object' && obj) {
return true; return true;
} else { } else {
return false; return false;
} }
} catch (e) { } catch (e) {
return false; return false;
}
} }
}
} }
//监听页面显示隐藏方法 //监听页面显示隐藏方法
//显示隐藏页面 //显示隐藏页面
export function getHiddenProp() { export function getHiddenProp() {
var prefixes = ['webkit', 'moz', 'ms', 'o']; var prefixes = ['webkit', 'moz', 'ms', 'o'];
// if 'hidden' is natively supported just return it // if 'hidden' is natively supported just return it
if ('hidden' in document) return 'hidden'; if ('hidden' in document) return 'hidden';
// otherwise loop over all the known prefixes until we find one // otherwise loop over all the known prefixes until we find one
for (var i = 0; i < prefixes.length; i++) { for (var i = 0; i < prefixes.length; i++) {
if ((prefixes[i] + 'Hidden') in document) if ((prefixes[i] + 'Hidden') in document)
return prefixes[i] + 'Hidden'; return prefixes[i] + 'Hidden';
} }
// otherwise it's not supported // otherwise it's not supported
return null; return null;
} }
export function getVisibilityState() { export function getVisibilityState() {
var prefixes = ['webkit', 'moz', 'ms', 'o']; var prefixes = ['webkit', 'moz', 'ms', 'o'];
if ('visibilityState' in document) return 'visibilityState'; if ('visibilityState' in document) return 'visibilityState';
for (var i = 0; i < prefixes.length; i++) { for (var i = 0; i < prefixes.length; i++) {
if ((prefixes[i] + 'VisibilityState') in document) if ((prefixes[i] + 'VisibilityState') in document)
return prefixes[i] + 'VisibilityState'; return prefixes[i] + 'VisibilityState';
} }
// otherwise it's not supported // otherwise it's not supported
return null; return null;
} }
export function isHidden() { export function isHidden() {
var prop = getHiddenProp(); var prop = getHiddenProp();
if (!prop) return false; if (!prop) return false;
return document[prop]; return document[prop];
} }
//本地显示图片 //本地显示图片
export function getHost() { export function getHost() {
var protocol = window.location.protocol; var protocol = window.location.protocol;
var host = window.location.host; var host = window.location.host;
var hostName = ''; var hostName = '';
if (host.indexOf("localhost") >= 0) { if (host.indexOf("localhost") >= 0) {
hostName = `https://ssp-dev.trace.com.cn` hostName = `https://ssp-dev.trace.com.cn`
} else { } else {
hostName = `..` hostName = `..`
} }
return hostName; return hostName;
} }
export function Encrypt(Okey, Oiv, payload) { export function Encrypt(Okey, Oiv, payload) {
const key = CryptoJS.enc.Utf8.parse(Okey); const key = CryptoJS.enc.Utf8.parse(Okey);
const iv = CryptoJS.enc.Utf8.parse(Oiv); const iv = CryptoJS.enc.Utf8.parse(Oiv);
let srcs = CryptoJS.enc.Utf8.parse(payload) let srcs = CryptoJS.enc.Utf8.parse(payload)
const encrypted = CryptoJS.AES.encrypt(srcs, key, { iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }) const encrypted = CryptoJS.AES.encrypt(srcs, key, { iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
const base64str = CryptoJS.enc.Base64.stringify(encrypted.ciphertext) const base64str = CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
// return encrypted.ciphertext.toString().toUpperCase(); // return encrypted.ciphertext.toString().toUpperCase();
return base64str return base64str
} }
export function Decryption(Okey, Oiv, value) { export function Decryption(Okey, Oiv, value) {
const key = CryptoJS.enc.Utf8.parse(Okey); const key = CryptoJS.enc.Utf8.parse(Okey);
const iv = CryptoJS.enc.Utf8.parse(Oiv); const iv = CryptoJS.enc.Utf8.parse(Oiv);
const decrypt = CryptoJS.AES.decrypt(value, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); const decrypt = CryptoJS.AES.decrypt(value, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
return CryptoJS.enc.Utf8.stringify(decrypt); return CryptoJS.enc.Utf8.stringify(decrypt);
} }
export function DecryptionECB(keyECB, valueECB) { export function DecryptionECB(keyECB, valueECB) {
const key = CryptoJS.enc.Utf8.parse(keyECB); const key = CryptoJS.enc.Utf8.parse(keyECB);
const decrypt = CryptoJS.AES.decrypt(valueECB, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); const decrypt = CryptoJS.AES.decrypt(valueECB, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
return CryptoJS.enc.Utf8.stringify(decrypt); return CryptoJS.enc.Utf8.stringify(decrypt);
} }
export function isSit() { export function isSit() {
return window.location.host.includes('sit') return window.location.host.includes('sit')
} }
export function isDev() { export function isDev() {
return window.location.host.includes('localhost') || window.location.host.includes('172.16') return window.location.host.includes('localhost') || window.location.host.includes('172.16')
} }
export function isProd() { export function isProd() {
return window.location.host.includes('sxznjh.trace.com.cn') || window.location.host.includes('ssp.trace.com.cn') || window.location.host.includes('dev.trace.com.cn') return window.location.host.includes('sxznjh.trace.com.cn') || window.location.host.includes('ssp.trace.com.cn') || window.location.host.includes('dev.trace.com.cn')
}
export function jumpOpenLink(url) {
utils.AppToHttpHtml(url);
}
export function jumpOpenWeb(type, url, urlType) {
console.log('chat-content', type, url);
var params = {};
if (type === "YY_0000") {
//保单管家
params = {
idnum: "1",
ownerId: useAppStore().userInfo.encryptPid,
openid: useAppStore().userInfo.sourceUserId,
};
//置换密匙
const completeURL = handleURL(url, params)
Post("semantic/getYdbqTicket", { url: completeURL, userId: useAppStore().userId }).then(res => {
console.log(res)
if (res.code === 0) {
//data空表示开关关闭
if (res.data === "" || res.data === null || res.data === undefined) {
utils.openWxPage(url, params);
} else {
const ticketParam = {
accessTicket: res.data
}
utils.openWxPage(url, ticketParam);
}
} else {
Toast("网络异常,请重试")
}
})
} else if (type === "YY_ydbq") {
//移动保全页面
params = {
mobile: useAppStore().userInfo.phone,
pid: useAppStore().userInfo.encryptPid,
openid: useAppStore().userInfo.sourceUserId,
};
//置换密匙
const completeURL = handleURL(url, params)
Post("semantic/getYdbqTicket", { url: completeURL, userId: useAppStore().userId }).then(res => {
console.log(res)
if (res.code === 0) {
//data空表示开关关闭
if (res.data === "" || res.data === null || res.data === undefined) {
utils.openWxPage(url, params);
} else {
const ticketParam = {
accessTicket: res.data
}
utils.openWxPage(url, ticketParam);
}
} else {
Toast("网络异常,请重试")
}
})
} else if (type === "YY_APP_H5") {
//在app内部页面打开h5(带参形式)
params = {
mobile: useAppStore().userInfo.phone,
pid: useAppStore().userInfo.encryptPid,
};
utils.AppOpenH5(url, params);
} else if (type === "ydbq_2") {
// 给付系统
params = {
url: url,
generateType: type,
userId: useAppStore().userId,
};
return utils.openSpecPage(params);
} else if (type === "YY_CMD") {
// 查门店
const newUrl = url + `&idnum=1&openId=${useAppStore().userInfo.sourceUserId}&entryOpenid=${useAppStore().userInfo.entryOpenid}`
//置换密匙
Post("semantic/getYdbqTicket", { url: newUrl, userId: useAppStore().userId, isCmd: "1" }).then(res => {
console.log(res)
if (res.code === 0) {
//data空表示开关关闭
if (res.data === "" || res.data === null || res.data === undefined) {
return jumpOpenLink(newUrl);
} else {
const ticketUrl = url + `&accessTicket=${res.data}`
return jumpOpenLink(ticketUrl);
}
} else {
Toast("网络异常,请重试")
}
})
} else if (type === "YY_lsjl") {
// 跳转历史记录
const openid = utils.getUrlParams().openid
router.push({
name: "history",
query: {
ht: useAppStore().source,
openid: openid,
tokenExist: useAppStore().tokenExist,
isWX: useAppStore().isWX,
lostChatInfoNum: useAppStore().lostChatInfoNum,
param: utils.getUrlParams().param
},
});
return
} else if (type === "YY_kjmyd") {
utils.useTechSdk()
return
} else if (type === "YY_hfhz") {
// 回访回执
const param = { certNum: "1", systemSource: "yykf", userId: useAppStore().userId }
Post("semantic/xdhfCreateToken", param).then(res => {
const entryptedId = useAppStore().userInfo.versionHFHZ
params = {
sessionToken: res.data,
holderId: encodeURI(entryptedId),
holderType: 'a',
hzhfSystemSource: '0803',
ishwFlag: '1',
isqshzFlag: '1',
}
utils.openWxPage(url, params);
})
} else if (type === "YY_1v1") {
// 1v1专属服务
post("thirdPartyAuth/getExclusiveServicesToken").then(res => {
if (res.code === 0) {
if (res.data) {
params = {
sour: 'yykf',
omoSource: useAppStore().userInfo.source,
omoSourceName: encodeURIComponent(useAppStore().userInfo.sourceName),
token: res.data
}
utils.openWxPage(url, params);
}
} else {
Toast("网络异常,请重试")
}
})
} else if (type === "YY_yzsfx") {
// 一站式复效
Post("semantic/getYzsUrl", { userId: useAppStore().userId, bqType: url, urlType }).then(res => {
if (res.code === 0) {
if (res.data) {
let yUrl = res.data
utils.openWxPage(yUrl, '');
}
} else {
Toast("网络异常,请重试")
}
})
} else if (type === "YY_GWXCX") {
//官微小程序
const path = url;
wx.miniProgram.navigateTo({
url: path
});
} else if (type === "YY_GWXCX_HOME") {
//官微小程序首页
const path = url;
console.log('path', path, wx.miniProgram.reLaunch)
wx.miniProgram.reLaunch({
url: path
});
}
}
export function handleURL(url, params) {
let flag = url.indexOf("?") != -1 ? true : false
let urlPar = '';
if (params) {
Object.getOwnPropertyNames(params).forEach((item, index) => {
if (index === 0 && !flag) {
urlPar += `?${item}=${params[item]}`;
} else {
urlPar += `&${item}=${params[item]}`
}
});
}
return url + urlPar
} }
Loading…
Cancel
Save