diff --git a/docker-compose.yml b/docker-compose.yml index 5aef4a68a..3a3284950 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -100,7 +100,7 @@ services: appstore: container_name: "dootask-appstore-${APP_ID}" privileged: true - image: "dootask/appstore:0.0.1" + image: "dootask/appstore:0.0.2" volumes: - shared_data:/usr/share/dootask - /var/run/docker.sock:/var/run/docker.sock diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index eb2e51fb7..715c444fc 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -96,7 +96,7 @@ server { proxy_pass http://appstore:8080/; } - include /var/www/docker/appstore/configs/*/nginx.conf; + include /var/www/docker/appstore/config/*/nginx.conf; } include /var/www/docker/nginx/conf.d/*.conf; diff --git a/resources/assets/js/components/MicroApps/index.vue b/resources/assets/js/components/MicroApps/index.vue index 96cba68e2..f2786de85 100644 --- a/resources/assets/js/components/MicroApps/index.vue +++ b/resources/assets/js/components/MicroApps/index.vue @@ -4,18 +4,18 @@ v-for="(app, key) in apps" :key="key" v-model="app.isOpen" - :ref="`ref-${app.name}`" + :ref="`ref-${app.id}`" :size="1200" :transparent="app.transparent" :autoDarkTheme="app.autoDarkTheme" - :beforeClose="async () => { await onBeforeClose(app.name) }"> + :beforeClose="async () => { await onBeforeClose(app.id) }"> name == e.detail.name); + const app = this.apps.find(({id}) => id == e.detail.name); if (app) { app.isLoading = false } @@ -181,11 +181,11 @@ export default { /** * 应用数据 - * @param name + * @param id * @returns {*} */ - appData(name) { - const app = this.apps.find(item => item.name == name); + appData(id) { + const app = this.apps.find(item => item.id == id); if (!app) { return {}; } @@ -225,10 +225,10 @@ export default { methods: { close: (destroy = false) => { - this.closeMicroApp(name, destroy) + this.closeMicroApp(id, destroy) }, back: () => { - this.closeByName(name) + this.closeById(id) }, nextZIndex: () => { if (typeof window.modalTransferIndex === 'number') { @@ -256,12 +256,12 @@ export default { let appConfig = {} if (config.url) { appConfig = { - name: `url-${await $A.getSHA256Hash(config.url)}`, + id: `url-${await $A.getSHA256Hash(config.url)}`, url: config.url, } delete config.url } else { - const app = this.apps.find(item => item.name == name); + const app = this.apps.find(item => item.id == id); if (!app) { $A.modalError("应用不存在"); return @@ -271,14 +271,14 @@ export default { appConfig.transparent = true appConfig.keepAlive = false - const apps = (await $A.IDBArray("cacheMicroApps")).filter(item => item.name != appConfig.name); + const apps = (await $A.IDBArray("cacheMicroApps")).filter(item => item.id != appConfig.id); apps.length > 50 && apps.splice(0, 10) apps.push(appConfig) await $A.IDBSet("cacheMicroApps", apps); await this.$store.dispatch('openChildWindow', { name: `single-apps-${$A.randomString(6)}`, - path: `/single/apps/${appConfig.name}`, + path: `/single/apps/${appConfig.id}`, force: false, config }); @@ -329,11 +329,11 @@ export default { * @param config */ async observeMicroApp(config) { - const app = this.apps.find(({name}) => name == config.name); + const app = this.apps.find(({id}) => id == config.id); if (app) { // 更新微应用 if (app.url != config.url) { - await microApp.unmountApp(app.name, {destroy: true}) + await microApp.unmountApp(app.id, {destroy: true}) app.isLoading = true } Object.assign(app, config) @@ -348,31 +348,31 @@ export default { }, /** - * 通过名称关闭微应用 - * @param name + * 通过ID关闭微应用 + * @param id */ - closeByName(name) { + closeById(id) { try { - this.$refs[`ref-${name}`][0].onClose() + this.$refs[`ref-${id}`][0].onClose() } catch (e) { - this.closeMicroApp(name) + this.closeMicroApp(id) } }, /** * 关闭微应用 - * @param name + * @param id * @param destroy */ - closeMicroApp(name, destroy) { - const app = this.apps.find(item => item.name == name); + closeMicroApp(id, destroy) { + const app = this.apps.find(item => item.id == id); if (!app) { return; } app.isOpen = false if (destroy) { - microApp.unmountApp(app.name, {destroy: true}) + microApp.unmountApp(app.id, {destroy: true}) } }, @@ -386,14 +386,14 @@ export default { /** * 关闭之前判断 - * @param name + * @param id * @returns {Promise} */ - onBeforeClose(name) { + onBeforeClose(id) { return new Promise(resolve => { - microApp.forceSetData(name, {type: 'beforeClose'}, array => { + microApp.forceSetData(id, {type: 'beforeClose'}, array => { if (!array?.find(item => item === true)) { - if (name === 'appstore') { + if (id === 'appstore') { this.$store.dispatch("updateMicroAppsStatus"); } if ($A.isSubElectron) { @@ -414,7 +414,7 @@ export default { return new Promise(resolve => { const app = this.apps.findLast(item => item.isOpen) if (app) { - this.closeByName(app.name) + this.closeById(app.id) } else { resolve() } diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index a037910a7..f4c2ab009 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -1201,14 +1201,6 @@ export default { case 'microApp': this.$store.dispatch("openMicroApp", params); break; - case 'appstore': - this.$store.dispatch("openMicroApp", { - name: 'appstore', - url: 'appstore/internal', - disableScopecss: true, - autoDarkTheme: false, - }); - break; } }, diff --git a/resources/assets/js/pages/manage/application.vue b/resources/assets/js/pages/manage/application.vue index a9310c2ca..24e4c2a74 100644 --- a/resources/assets/js/pages/manage/application.vue +++ b/resources/assets/js/pages/manage/application.vue @@ -15,22 +15,6 @@ {{ t == 'base' ? $L('常用') : $L('管理员') }} - -
-
- -

{{ $L('应用商店') }}

-
-
- item.name === name); + const app = (await $A.IDBArray("cacheMicroApps")).reverse().find(item => item.id === id); if (!app) { $A.modalError("应用不存在"); return } - this.$refs.app.observeMicroApp(app) + await this.$refs.app.observeMicroApp(app) } } diff --git a/resources/assets/js/routes.js b/resources/assets/js/routes.js index c848a5aff..1244eab96 100755 --- a/resources/assets/js/routes.js +++ b/resources/assets/js/routes.js @@ -155,7 +155,7 @@ export default [ }, { name: 'single-apps', - path: '/single/apps/:appName', + path: '/single/apps/:appId', component: () => import('./pages/single/apps.vue') }, { diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 13ea53ee0..ec5f19520 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -1117,8 +1117,8 @@ export default { 'callAt', 'cacheEmojis', 'cacheDialogs', + 'microAppsIds', 'microAppsMenus', - 'microAppsNames', ], json: [ 'userInfo' @@ -4646,7 +4646,7 @@ export default { * 打开微应用 * @param state * @param data - * - name 应用名称 + * - id 应用ID * - url 应用地址 * - props 传递参数 * - transparent 是否透明模式 (true/false),默认 false @@ -4662,7 +4662,7 @@ export default { return } const config = { - name: data.app_name || data.name, + id: data.id, url: $A.mainUrl(data.url), props: $A.isJson(data.props) ? data.props : {}, transparent: typeof data.transparent == 'boolean' ? data.transparent : false, @@ -4670,15 +4670,15 @@ export default { keepAlive: typeof data.keepAlive == 'boolean' ? data.keepAlive : true, disableScopecss: typeof data.disableScopecss == 'boolean' ? data.disableScopecss : false } - if (!config.name) { + if (!config.id) { return } - if (!state.microAppsNames.includes(config.name)) { - $A.modalWarning(`应用「${config.name}」未安装`); + if (!state.microAppsIds.includes(config.id)) { + $A.modalWarning(`应用「${config.id}」未安装`); return; } if (data.key) { - config.name += `_${data.key}` + config.id += `_${data.key}` } emitter.emit('observeMicroApp:open', config); }, @@ -4695,7 +4695,7 @@ export default { resolve(false) return } - resolve(!!state.microAppsNames.includes(appName)) + resolve(!!state.microAppsIds.includes(appName)) }) }, @@ -4711,8 +4711,7 @@ export default { } }) if (code === 200) { - commit("microApps/menus", data.menus || []) - commit("microApps/names", data.names || []) + commit("microApps/data", data|| []) } }, } diff --git a/resources/assets/js/store/mutations.js b/resources/assets/js/store/mutations.js index 5419b131c..2f9e4f298 100644 --- a/resources/assets/js/store/mutations.js +++ b/resources/assets/js/store/mutations.js @@ -300,13 +300,28 @@ export default { }, // 微应用管理 - 'microApps/menus': function(state, data) { - state.microAppsMenus = data - $A.IDBSave("microAppsMenus", state.microAppsMenus) - }, - - 'microApps/names': function(state, data) { - state.microAppsNames = [...data, 'appstore'] - $A.IDBSave("microAppsNames", state.microAppsNames) + 'microApps/data': function(state, data) { + data.unshift({ + id: 'appstore', + menu_items: [{ + id: 'appstore', + location: "application/admin", + label: $A.L("应用商店"), + icon: $A.mainUrl("images/application/appstore.svg"), + url: 'appstore/internal', + disableScopecss: true, + autoDarkTheme: false, + }] + }) + const ids = []; + const menus = []; + data.forEach((item) => { + ids.push(item.id); + if (item.menu_items) { + menus.push(...item.menu_items.map(m => Object.assign(m, {id: item.id}))); + } + }) + $A.IDBSave("microAppsIds", state.microAppsIds = ids); + $A.IDBSave("microAppsMenus", state.microAppsMenus = menus); }, } diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index b214ef782..5986ae413 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -262,6 +262,6 @@ export default { longpressData: {type: '', data: null, element: null}, // 微应用数据 + microAppsIds: [], microAppsMenus: [], - microAppsNames: ['appstore'], };