Commit 3c6e4a64 authored by danfuman's avatar danfuman

Merge branch 'V20230915' of http://192.168.60.201/root/dsk-operate-sys into V20230915

parents 0e651e38 16949549
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: thy * @Author: thy
* @Date: 2023-11-08 09:28:17 * @Date: 2023-11-08 09:28:17
* @LastEditors: thy * @LastEditors: thy
* @LastEditTime: 2023-11-17 09:36:01 * @LastEditTime: 2023-11-28 16:04:07
* @Description: file content * @Description: file content
* @FilePath: \dsk-operate-ui\src\utils\iframeTools.js * @FilePath: \dsk-operate-ui\src\utils\iframeTools.js
*/ */
...@@ -31,22 +31,26 @@ class IframeTools { ...@@ -31,22 +31,26 @@ class IframeTools {
* @returns * @returns
*/ */
constructor(subSystemIframe, pluginDomain = process.env.VUE_APP_SUB_SYSTEM_ADDRESS) { constructor(subSystemIframe, pluginDomain = process.env.VUE_APP_SUB_SYSTEM_ADDRESS) {
try { return new Promise(async (resolve, reject) => {
const query = getUrlSearchQuery(); try {
if (!query.url) return Message.warning("缺少子系统目标地址"); const query = getUrlSearchQuery();
// 传入的iframeUrl不是一个合法地址 if (!query.url) return Message.warning("缺少子系统目标地址");
if (!isUrl(pluginDomain)) return Message.warning("子系统源地址不合法"); // 传入的iframeUrl不是一个合法地址
// 未获取到子系统节点 if (!isUrl(pluginDomain)) return Message.warning("子系统源地址不合法");
if (!subSystemIframe) return Message.warning("未获取到子系统节点"); // 未获取到子系统节点
this.queryParams = query; if (!subSystemIframe) return Message.warning("未获取到子系统节点");
this.pluginDomain = pluginDomain; this.queryParams = query;
this.subSystemIframe = subSystemIframe; this.pluginDomain = pluginDomain;
this.isOuter = query.isOuter && typeof JSON.parse(query.isOuter) == "boolean" ? JSON.parse(query.isOuter) : false; this.subSystemIframe = subSystemIframe;
// 是一个合法地址 初始化 先替换域名地址 再获取令牌并 拼接 // 是否外部打开
this.init(); this.isOuter = query.isOuter && typeof JSON.parse(query.isOuter) == "boolean" ? JSON.parse(query.isOuter) : false;
} catch (error) { // 是一个合法地址 初始化 先替换域名地址 再获取令牌并 拼接
throw new Error(error); await this.init();
} resolve(this);
} catch (error) {
reject(error)
}
});
} }
/** /**
......
import Interaction from "./interaction";
import Router from "./router";
export default {
"interaction": new Interaction(),
"router": new Router(),
};
\ No newline at end of file
class Interaction {
actionName = "interaction";
constructor() {
}
}
export default Interaction;
\ No newline at end of file
class Router {
actionName = "router"
constructor() {
}
}
export default Router;
\ No newline at end of file
/*
* @Author: thy
* @Date: 2023-11-28 18:09:11
* @LastEditors: thy
* @LastEditTime: 2023-11-29 10:48:22
* @Description: file content
* @FilePath: \dsk-operate-ui\src\utils\postMessageBridge\bridge\eventCenter.js
*/
import { v4 } from "uuid";
/**
* 事件回调 调度中心
*/
class EventCenter {
//事件回调储存栈
_eventHandlerMap = new Map();
constructor() {
}
/**
* 根据回调ID获取事件回调储存中的回调
* @param {string} handlerId
*/
getTargetHandler(handlerId) {
return this._eventHandlerMap.get(handlerId);
}
/**
* 注册事件回调到 事件储存中
* @param {Promise} promiseCallBack
*/
registerHandler(promiseCallBack) {
return new Promise((resolve, reject) => {
if (Object.prototype.toString.call(promiseCallBack) !== "[object Promise]") return console.warn("传入的回调类型不是一个promise实例");
const uid = v4();
this._eventHandlerMap.set(uid, promiseCallBack);
resolve(uid);
});
}
/**
* 根据回调ID卸载事件回调储存中的回调
* @param {string} handlerId
*/
writeOffHandler(handlerId) {
return this._eventHandlerMap.delete(handlerId);
}
/**
* 根据回调ID 执行事件回调储存中的回调 并卸载
* @param {string} handlerId
*/
executeHandler(handlerId) {
return new Promise((resolve, reject) => {
try {
const currentCallBack = this.getTargetHandler(handlerId);
if (!currentCallBack) return reject("执行回调错误,未找到对应回调");
// 执行回调
} catch (error) {
}
});
}
}
export default EventCenter;
\ No newline at end of file
...@@ -2,44 +2,87 @@ ...@@ -2,44 +2,87 @@
* @Author: thy * @Author: thy
* @Date: 2023-10-26 14:56:41 * @Date: 2023-10-26 14:56:41
* @LastEditors: thy * @LastEditors: thy
* @LastEditTime: 2023-10-31 09:28:26 * @LastEditTime: 2023-11-29 14:25:31
* @Description: file content * @Description: file content
* @FilePath: \dsk-operate-ui\src\utils\postMessageBridge\bridge\index.js * @FilePath: \dsk-operate-ui\src\utils\postMessageBridge\bridge\index.js
*/ */
import EventCenter from "./eventCenter";
import action from "@/utils/postMessageBridge/action";
import { normalToPromise } from "@/utils/postMessageBridge/tools";
class PostMessageBridge { class PostMessageBridge {
// 当前系统 // 当前系统
_currenySystem = null; _currentSystem = null;
// 当前系统域
_currentOriginUrl = null;
// 目标系统 // 目标系统
_targetSystem = null; _targetSystem = null;
// 目标域 // 目标域
_targetOriginUrl = null; _targetOriginUrl = null;
// 事件调度中心 // 事件调度中心
_eventHandlers = new Map(); _eventCenter = null;
// 触发的行为
_actionMap = null;
/** /**
* *
* @param {{ * @param {{
* currenySystem : Window || undefined; * currentSystem : Window || undefined;
* currentOriginUrl : string;
* targetSystem : Window || undefined; * targetSystem : Window || undefined;
* targetOriginUrl : string || undefined; * targetOriginUrl : string || undefined;
* }} options * }} options
*/ */
constructor(options) { constructor(options) {
this._currenySystem = options.currenySystem; return new Promise(async (resolve, reject) => {
this._targetSystem = options.targetSystem; try {
this._targetOriginUrl = options.targetOriginUrl || "*"; this._currentSystem = options.currentSystem;
this._currentOriginUrl = options.currentOriginUrl || location.origin;
this._targetSystem = options.targetSystem;
this._targetOriginUrl = options.targetOriginUrl || "*";
await this.init();
resolve(this);
} catch (error) {
reject(error);
}
});
} }
/** /**
* 订阅消息 * 通信初始化
* @param {{
* id : string;
* method : string;
* params : object;
* }} messageEvent
*/ */
receiveMessage(messageEvent) { async init() {
try {
this._eventCenter = new EventCenter();
this._actionMap = action;
this._currentSystem.addEventListener("message", this.messageListener, false);
} catch (error) {
console.log(error);
}
} }
}
\ No newline at end of file /**
* 触发message 时执行的函数
* @param {MessageEvent} event
* @returns
*/
messageListener(event) {
new Promise(async (resolve, reject) => {
try {
const { data, origin, source } = event;
if (origin !== this._currentOriginUrl) return;
const { id, action, methodName, params } = data;
if (!id) return;
// promise化
const result = normalToPromise(this._actionMap[action][methodName]);
resolve(result);
} catch (error) {
console.log(error);
reject(error);
}
});
};
}
export default PostMessageBridge;
\ No newline at end of file
export { default as PostMessageBridge } from "./bridge";
\ No newline at end of file
/**
* 普通函数包装为promise风格函数
* @param {Function} fn
* @returns {Promise<any>} 返回一个promise
*/
export const normalToPromise = (fn) => {
const tag = Object.prototype.toString.call(fn);
if (tag !== "[object Function]" || tag !== "[object AsyncFunction]") return fn;
return (...args) => {
try {
const result = fn(...args);
return Promise.resolve(result);
} catch (error) {
return Promise.reject(error);
}
};
};
\ No newline at end of file
...@@ -221,10 +221,11 @@ ...@@ -221,10 +221,11 @@
this.addtips() this.addtips()
} }
let j = 0 let j = 0
for(var i=1;i<=7;i++){ for(let i=1;i<=7;i++){
let isSelf = document.getElementById('inputxt'+i).contains(event.target) // 这个是自己的区域 let isSelf = document.getElementById('inputxt'+i).contains(event.target) // 这个是自己的区域
if(isSelf) { if(isSelf) {
this.nowedit = i this.nowedit = i
break;
}else { }else {
j++; j++;
} }
...@@ -254,13 +255,13 @@ ...@@ -254,13 +255,13 @@
break; break;
case 7 : case 7 :
// param = {'constructionPhone':this.xmsldata.constructionPhone} // param = {'constructionPhone':this.xmsldata.constructionPhone}
this.isphone(1,this.xmsldata.constructionPhone) this.isphone(2,this.xmsldata.constructionPhone)
break; break;
} }
if(this.nowedit!=6 && this.nowedit!=7) if(this.nowedit!=6 && this.nowedit!=7) {
this.editXMSL(param) this.editXMSL(param)
}
} }
this.nowedit = -1
} }
}) })
}, },
...@@ -276,8 +277,7 @@ ...@@ -276,8 +277,7 @@
this.spanWidth = 'width:'+wid this.spanWidth = 'width:'+wid
}); });
}, },
editXMSL(param){ async editXMSL(param){
this.nowedit = -1
if(this.isDisabled == true) if(this.isDisabled == true)
return false return false
if(param.projectStage){//修改项目阶段 if(param.projectStage){//修改项目阶段
...@@ -286,17 +286,17 @@ ...@@ -286,17 +286,17 @@
}else{ }else{
let params = param let params = param
params.id = this.id params.id = this.id
editXMNR(JSON.stringify(params)).then(res=>{ const res = await editXMNR(JSON.stringify(params));
if (res.code == 200){ if (res.code == 200){
if(!param.projectStage){ if(!param.projectStage){
// this.$message.success('修改成功!') // this.$message.success('修改成功!')
} }
}else{ }else{
this.$message.error(res.msg) this.$message.error(res.msg)
this.getXMSL() await this.getXMSL()
} }
}) }
} this.nowedit = -1;
}, },
//验证电话号码 //验证电话号码
isphone(type,value){ isphone(type,value){
...@@ -352,7 +352,7 @@ ...@@ -352,7 +352,7 @@
}, },
getXMSL(){ getXMSL(){
getXMSL(this.id).then(result=> { return getXMSL(this.id).then(result=> {
this.xmjd = !result.data.projectStage?'待添加':result.data.projectStage this.xmjd = !result.data.projectStage?'待添加':result.data.projectStage
if(result.data.labelList == null || result.data.labelList == "" || result.data.labelList == undefined){ if(result.data.labelList == null || result.data.labelList == "" || result.data.labelList == undefined){
this.tipslit = [] this.tipslit = []
......
...@@ -22,6 +22,11 @@ export default { ...@@ -22,6 +22,11 @@ export default {
url: { url: {
type: String, type: String,
default: "" default: ""
},
// 100%模式
layout: {
type: Boolean,
default: false
} }
}, },
watch: { watch: {
......
<template> <template>
<div class="subsystem-iframe-container"> <div class="subsystem-iframe-container">
<iframe-com-ins ref="subsystemIframeContainer" :iframeStyles="urlQueryParams.iframeStyles" :styles="urlQueryParams.styles" <iframe-com-ins ref="subsystemIframeContainer" :iframeStyles="urlQueryParams.iframeStyles" :styles="urlQueryParams.styles"
:url="urlQueryParams.url"></iframe-com-ins> :url="urlQueryParams.url" :layout="urlQueryParams.layout"></iframe-com-ins>
</div> </div>
</template> </template>
<script> <script>
import IframeComIns from "./components/IframeComIns"; import IframeComIns from "./components/IframeComIns";
import IframeTools from "@/utils/iframeTools"; import IframeTools from "@/utils/iframeTools";
import { PostMessageBridge } from "@/utils/postMessageBridge";
export default { export default {
name: "subsystemIframeContainer", name: "subsystemIframeContainer",
components: { components: {
...@@ -15,12 +16,13 @@ export default { ...@@ -15,12 +16,13 @@ export default {
data() { data() {
return { return {
urlQueryParams: {}, urlQueryParams: {},
iframeToolsIns: {} iframeToolsIns: {},
messageBridgeIns: {}
}; };
}, },
//可访问data属性 //可访问data属性
created() { created() {
this.Init(); this.init();
}, },
beforeDestroy() { beforeDestroy() {
if (this.iframeToolsIns) { if (this.iframeToolsIns) {
...@@ -33,10 +35,20 @@ export default { ...@@ -33,10 +35,20 @@ export default {
}, },
//方法集 //方法集
methods: { methods: {
async Init() { async init() {
await this.$nextTick(); await this.$nextTick();
const dom = this.$refs["subsystemIframeContainer"].$el.querySelector("iframe"); const dom = this.$refs["subsystemIframeContainer"].$el.querySelector("iframe");
const iframeTools = new IframeTools(dom); // 初始化iframe工具
const iframeTools = await new IframeTools(dom);
// 初始化iframe通信工具
console.dir(iframeTools);
const messageBridge = await new PostMessageBridge({
currenySystem: window,
targetSystem: iframeTools.subSystemIframe?.contentWindow,
targetOriginUrl: process.env.VUE_APP_SUB_SYSTEM_ADDRESS
});
console.log(messageBridge);
this.messageBridgeIns = messageBridge;
this.iframeToolsIns = iframeTools; this.iframeToolsIns = iframeTools;
this.urlQueryParams = iframeTools.queryParams; this.urlQueryParams = iframeTools.queryParams;
console.log(this.urlQueryParams); console.log(this.urlQueryParams);
...@@ -52,5 +64,6 @@ export default { ...@@ -52,5 +64,6 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden;
} }
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment