mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 12:42:51 +00:00
no message
This commit is contained in:
parent
1c5b856800
commit
3018f3653c
@ -1,46 +1,53 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div class="micro-app-wrapper">
|
||||||
|
<template v-for="app in apps">
|
||||||
<div
|
<div
|
||||||
v-if="appConfig.transparent"
|
v-if="app.transparent"
|
||||||
v-transfer-dom
|
v-transfer-dom
|
||||||
:data-transfer="true">
|
:data-transfer="true">
|
||||||
<micro-app
|
<micro-app
|
||||||
v-if="appConfig.isOpen"
|
v-if="app.isOpen"
|
||||||
:name="appConfig.appName"
|
:name="app.appName"
|
||||||
:url="appConfig.appUrl"
|
:url="app.appUrl"
|
||||||
:keep-alive="appConfig.keepAlive"
|
:keep-alive="app.keepAlive"
|
||||||
:data="appData"
|
:data="appData(app.appName)"
|
||||||
@created="created"
|
@created="created"
|
||||||
@beforemount="beforemount"
|
@beforemount="beforemount"
|
||||||
@mounted="mounted"
|
@mounted="mounted"
|
||||||
@unmount="unmount"
|
@unmount="unmount"
|
||||||
@error="error"/>
|
@error="error"/>
|
||||||
|
<div v-if="app.isLoading" class="micro-app-loader spinner">
|
||||||
|
<Loading/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DrawerOverlay
|
<DrawerOverlay
|
||||||
v-else
|
v-else
|
||||||
v-model="appConfig.isOpen"
|
v-model="app.isOpen"
|
||||||
modal-class="micro-app-modal"
|
modal-class="micro-app-modal"
|
||||||
drawer-class="micro-app-drawer"
|
drawer-class="micro-app-drawer"
|
||||||
placement="right"
|
placement="right"
|
||||||
:beforeClose="onBeforeClose"
|
:beforeClose="async () => { await onBeforeClose(app.appName) }"
|
||||||
:size="1200">
|
:size="1200">
|
||||||
<template>
|
<template>
|
||||||
<micro-app
|
<micro-app
|
||||||
v-if="appConfig.isOpen"
|
v-if="app.isOpen"
|
||||||
:name="appConfig.appName"
|
:name="app.appName"
|
||||||
:url="appConfig.appUrl"
|
:url="app.appUrl"
|
||||||
:keep-alive="appConfig.keepAlive"
|
:keep-alive="app.keepAlive"
|
||||||
:data="appData"
|
:data="appData(app.appName)"
|
||||||
@created="created"
|
@created="created"
|
||||||
@beforemount="beforemount"
|
@beforemount="beforemount"
|
||||||
@mounted="mounted"
|
@mounted="mounted"
|
||||||
@unmount="unmount"
|
@unmount="unmount"
|
||||||
@error="error"/>
|
@error="error"/>
|
||||||
<div v-if="loadIng > 0" class="micro-app-loading">
|
<div v-if="app.isLoading" class="micro-app-loader">
|
||||||
<Loading/>
|
<Loading/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</DrawerOverlay>
|
</DrawerOverlay>
|
||||||
</template>
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.micro-app-modal {
|
.micro-app-modal {
|
||||||
@ -55,15 +62,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.micro-app-loading {
|
.micro-app-loader {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
|
&.spinner {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 9999;
|
||||||
|
background-color: rgba(255, 255, 255, 0.6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@ -80,8 +93,6 @@ import DrawerOverlay from "./DrawerOverlay/index.vue";
|
|||||||
import emitter from "../store/events";
|
import emitter from "../store/events";
|
||||||
import TransferDom from "../directives/transfer-dom";
|
import TransferDom from "../directives/transfer-dom";
|
||||||
|
|
||||||
const appMaps = new Map();
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MicroApps",
|
name: "MicroApps",
|
||||||
directives: {TransferDom},
|
directives: {TransferDom},
|
||||||
@ -89,8 +100,7 @@ export default {
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loadIng: 0,
|
apps: [],
|
||||||
appConfig: {},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -109,7 +119,11 @@ export default {
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
userToken(token) {
|
userToken(token) {
|
||||||
!token && microApp.unmountAllApps({destroy: true})
|
if (token) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.apps = [];
|
||||||
|
microApp.unmountAllApps({destroy: true})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -118,9 +132,61 @@ export default {
|
|||||||
'userInfo',
|
'userInfo',
|
||||||
'themeName',
|
'themeName',
|
||||||
]),
|
]),
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
// 元素被创建
|
||||||
|
created() {
|
||||||
|
},
|
||||||
|
|
||||||
|
// 即将渲染
|
||||||
|
beforemount() {
|
||||||
|
},
|
||||||
|
|
||||||
|
// 已经渲染完成
|
||||||
|
mounted(e) {
|
||||||
|
this.finish(e)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 已经卸载
|
||||||
|
unmount() {
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载出错
|
||||||
|
error(e) {
|
||||||
|
this.finish(e)
|
||||||
|
$A.modalError({
|
||||||
|
language: false,
|
||||||
|
title: this.$L('应用加载失败'),
|
||||||
|
content: e.detail.error,
|
||||||
|
onOk: () => {
|
||||||
|
this.closeMicroApp(e.detail.name, true)
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载结束
|
||||||
|
finish(e) {
|
||||||
|
const app = this.apps.find(({appName}) => appName == e.detail.name);
|
||||||
|
if (app) {
|
||||||
|
app.isLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用数据
|
||||||
|
* @param name
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
appData(name) {
|
||||||
|
const app = this.apps.find(({appName}) => appName == name);
|
||||||
|
if (!app) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
appData() {
|
|
||||||
return {
|
return {
|
||||||
|
type: 'init',
|
||||||
|
|
||||||
instance: {
|
instance: {
|
||||||
Vue,
|
Vue,
|
||||||
store,
|
store,
|
||||||
@ -135,7 +201,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
initialData: {
|
initialData: {
|
||||||
...this.appConfig.initialData,
|
...app.initialData,
|
||||||
|
|
||||||
systemInfo: window.systemInfo,
|
systemInfo: window.systemInfo,
|
||||||
baseUrl: $A.mainUrl(),
|
baseUrl: $A.mainUrl(),
|
||||||
@ -156,7 +222,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleClose: (destroy = false) => {
|
handleClose: (destroy = false) => {
|
||||||
this.closeMicroApp(destroy)
|
this.closeMicroApp(name, destroy)
|
||||||
},
|
},
|
||||||
|
|
||||||
nextModalIndex: () => {
|
nextModalIndex: () => {
|
||||||
@ -178,115 +244,79 @@ export default {
|
|||||||
this.$store.dispatch('openWebTabWindow', url);
|
this.$store.dispatch('openWebTabWindow', url);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// 元素被创建
|
|
||||||
created(e) {
|
|
||||||
this.stateChange(e)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 即将渲染
|
|
||||||
beforemount() {
|
|
||||||
},
|
|
||||||
|
|
||||||
// 已经渲染完成
|
|
||||||
mounted(e) {
|
|
||||||
this.stateChange(e, true)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 已经卸载
|
|
||||||
unmount() {
|
|
||||||
},
|
|
||||||
|
|
||||||
// 加载出错
|
|
||||||
error(e) {
|
|
||||||
this.stateChange(e, true)
|
|
||||||
$A.modalError({
|
|
||||||
language: false,
|
|
||||||
title: this.$L('应用加载失败'),
|
|
||||||
content: e.detail.error,
|
|
||||||
onOk: () => {
|
|
||||||
this.closeMicroApp(true)
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// 加载状态变化
|
|
||||||
stateChange(e, end = false) {
|
|
||||||
const appConfig = appMaps.get(e.detail.name)
|
|
||||||
if (appConfig?.isLoading) {
|
|
||||||
if (end) {
|
|
||||||
if (appConfig.transparent) {
|
|
||||||
this.$store.dispatch('hiddenSpinner');
|
|
||||||
} else {
|
|
||||||
this.loadIng--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (appConfig.transparent) {
|
|
||||||
this.$store.dispatch('showSpinner');
|
|
||||||
} else {
|
|
||||||
this.loadIng++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开微应用
|
* 打开微应用
|
||||||
* @param appConfig
|
* @param config
|
||||||
|
* - appName 微应用名称
|
||||||
|
* - appUrl 微应用地址
|
||||||
|
* - initialData 初始化数据
|
||||||
|
* - transparent 是否透明模式 (true/false),默认 false
|
||||||
|
* - keepAlive 是否开启微应用保活 (true/false),默认 true
|
||||||
*/
|
*/
|
||||||
openMicroApp(appConfig) {
|
openMicroApp(config) {
|
||||||
// 处理数据
|
// 处理数据
|
||||||
appConfig = Object.assign({
|
config.appName = config.appName || 'micro-app'
|
||||||
appName: 'micro-app', // 微应用唯一标识名称
|
config.appUrl = config.appUrl || null
|
||||||
appUrl: null, // 微应用的入口URL地址
|
config.initialData = $A.isJson(config.initialData) ? config.initialData : {}
|
||||||
initialData: {}, // 初始化时传递给微应用的数据对象
|
config.transparent = typeof config.transparent == 'boolean' ? config.transparent : false
|
||||||
|
config.keepAlive = typeof config.keepAlive == 'boolean' ? config.keepAlive : true
|
||||||
transparent: false, // 是否透明模式(true/false),默认不透明
|
|
||||||
keepAlive: true, // 是否开启微应用保活(true/false),默认开启
|
|
||||||
|
|
||||||
isLoading: true, // 私有参数,是否显示加载状态(true/false)
|
|
||||||
isOpen: false, // 私有参数,是否打开微应用(true/false)
|
|
||||||
}, appConfig);
|
|
||||||
|
|
||||||
// 判断处理
|
// 判断处理
|
||||||
const lastConfig = appMaps.get(appConfig.appName)
|
const app = this.apps.find(({appName}) => appName == config.appName);
|
||||||
if (lastConfig) {
|
if (app) {
|
||||||
if (lastConfig.displayMode != appConfig.displayMode || lastConfig.appUrl != appConfig.appUrl) {
|
// 更新微应用
|
||||||
microApp.unmountApp(appConfig.appName, {destroy: true})
|
if (app.appUrl != config.appUrl) {
|
||||||
} else {
|
microApp.unmountApp(app.appName, {destroy: true})
|
||||||
appConfig.isLoading = false;
|
app.isLoading = true
|
||||||
}
|
}
|
||||||
|
for (let key in config) {
|
||||||
|
app[key] = config[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新数据
|
|
||||||
appMaps.set(appConfig.appName, this.appConfig = appConfig);
|
|
||||||
|
|
||||||
// 打开微应用
|
|
||||||
this.$nextTick(_ => {
|
this.$nextTick(_ => {
|
||||||
this.appConfig.isOpen = true
|
app.isOpen = true
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// 新建微应用
|
||||||
|
config.isLoading = true
|
||||||
|
config.isOpen = false
|
||||||
|
this.apps.push(config)
|
||||||
|
this.$nextTick(_ => {
|
||||||
|
config.isOpen = true
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭微应用
|
* 关闭微应用
|
||||||
|
* @param name
|
||||||
* @param destroy
|
* @param destroy
|
||||||
*/
|
*/
|
||||||
closeMicroApp(destroy) {
|
closeMicroApp(name, destroy) {
|
||||||
this.appConfig.isOpen = false
|
const app = this.apps.find(({appName}) => appName == name);
|
||||||
|
if (!app) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.isOpen = false
|
||||||
if (destroy) {
|
if (destroy) {
|
||||||
microApp.unmountApp(this.appConfig.appName, {destroy: true})
|
microApp.unmountApp(app.appName, {destroy: true})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭之前判断
|
* 关闭之前判断
|
||||||
|
* @param name
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
onBeforeClose() {
|
onBeforeClose(name) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
microApp.forceSetData(name, {type: 'beforeClose'}, array => {
|
||||||
|
if (!array?.find(item => item === true)) {
|
||||||
resolve()
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
4
resources/assets/js/functions/common.js
vendored
4
resources/assets/js/functions/common.js
vendored
@ -1723,7 +1723,7 @@ const timezone = require("dayjs/plugin/timezone");
|
|||||||
keyName = '__state:' + key + '__';
|
keyName = '__state:' + key + '__';
|
||||||
}
|
}
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
return this.__loadFromlSession(key, '', keyName);
|
return this.__loadFromSession(key, '', keyName);
|
||||||
} else {
|
} else {
|
||||||
this.__savaToSession(key, value, keyName);
|
this.__savaToSession(key, value, keyName);
|
||||||
}
|
}
|
||||||
@ -1744,7 +1744,7 @@ const timezone = require("dayjs/plugin/timezone");
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
__loadFromlSession(key, def, keyName) {
|
__loadFromSession(key, def, keyName) {
|
||||||
try {
|
try {
|
||||||
if (typeof keyName === 'undefined') keyName = '__seller__';
|
if (typeof keyName === 'undefined') keyName = '__seller__';
|
||||||
let seller = window.sessionStorage.getItem(keyName);
|
let seller = window.sessionStorage.getItem(keyName);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user