mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-19 16:22:52 +00:00
feat: 更新微应用菜单配置,统一使用类型字段替代URL类型字段
This commit is contained in:
parent
8c23192eeb
commit
d77406951d
@ -309,13 +309,13 @@ class Setting extends AbstractModel
|
|||||||
}
|
}
|
||||||
$location = trim($menu['location'] ?? 'application');
|
$location = trim($menu['location'] ?? 'application');
|
||||||
$label = trim($menu['label'] ?? $fallbackLabel);
|
$label = trim($menu['label'] ?? $fallbackLabel);
|
||||||
$urlType = strtolower(trim($menu['url_type'] ?? 'iframe'));
|
$type = strtolower(trim($menu['type'] ?? 'iframe'));
|
||||||
$payload = [
|
$payload = [
|
||||||
'location' => $location,
|
'location' => $location,
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
'icon' => Base::newTrim($menu['icon'] ?? ''),
|
'icon' => Base::newTrim($menu['icon'] ?? ''),
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'url_type' => $urlType,
|
'type' => $type,
|
||||||
'keep_alive' => isset($menu['keep_alive']) ? (bool)$menu['keep_alive'] : true,
|
'keep_alive' => isset($menu['keep_alive']) ? (bool)$menu['keep_alive'] : true,
|
||||||
'disable_scope_css' => (bool)($menu['disable_scope_css'] ?? false),
|
'disable_scope_css' => (bool)($menu['disable_scope_css'] ?? false),
|
||||||
'auto_dark_theme' => isset($menu['auto_dark_theme']) ? (bool)$menu['auto_dark_theme'] : true,
|
'auto_dark_theme' => isset($menu['auto_dark_theme']) ? (bool)$menu['auto_dark_theme'] : true,
|
||||||
|
|||||||
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Module\Base;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class UpdateSettingMicroappMenuType extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$row = Setting::whereName('microapp_menu')->first();
|
||||||
|
if (!$row) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$data = Base::string2array($row->setting);
|
||||||
|
if (empty($data) || !is_array($data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = false;
|
||||||
|
foreach ($data as $appIndex => $app) {
|
||||||
|
if (!is_array($app)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$menuItems = [];
|
||||||
|
if (isset($app['menu_items']) && is_array($app['menu_items'])) {
|
||||||
|
$menuItems = $app['menu_items'];
|
||||||
|
} elseif (isset($app['menu']) && is_array($app['menu'])) {
|
||||||
|
$menuItems = [$app['menu']];
|
||||||
|
}
|
||||||
|
if (empty($menuItems)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newMenuItems = [];
|
||||||
|
foreach ($menuItems as $menu) {
|
||||||
|
if (!is_array($menu)) {
|
||||||
|
$newMenuItems[] = $menu;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isset($menu['type']) && isset($menu['url_type'])) {
|
||||||
|
$menu['type'] = $menu['url_type'];
|
||||||
|
unset($menu['url_type']);
|
||||||
|
$changed = true;
|
||||||
|
} elseif (isset($menu['url_type'])) {
|
||||||
|
unset($menu['url_type']);
|
||||||
|
$changed = true;
|
||||||
|
}
|
||||||
|
$newMenuItems[] = $menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($app['menu_items']) && is_array($app['menu_items'])) {
|
||||||
|
$data[$appIndex]['menu_items'] = $newMenuItems;
|
||||||
|
} elseif (isset($app['menu']) && is_array($app['menu'])) {
|
||||||
|
$data[$appIndex]['menu'] = $newMenuItems[0] ?? $app['menu'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($changed) {
|
||||||
|
$row->updateInstance(['setting' => $data]);
|
||||||
|
$row->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
// No-op: do not revert settings payload.
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -235,7 +235,7 @@ export default {
|
|||||||
|
|
||||||
name: app.name,
|
name: app.name,
|
||||||
url: app.url,
|
url: app.url,
|
||||||
urlType: app.url_type,
|
type: app.type,
|
||||||
|
|
||||||
userId: this.userId,
|
userId: this.userId,
|
||||||
userToken: this.userToken,
|
userToken: this.userToken,
|
||||||
@ -405,13 +405,13 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 如果是 blank 链接,则在新窗口打开
|
// 如果是 blank 链接,则在新窗口打开
|
||||||
if (/_blank$/i.test(config.url_type)) {
|
if (/_blank$/i.test(config.type)) {
|
||||||
await this.inlineBlank(config)
|
await this.inlineBlank(config)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是外部链接,则在新窗口打开
|
// 如果是外部链接,则在新窗口打开
|
||||||
if (config.url_type === 'external') {
|
if (config.type === 'external') {
|
||||||
await this.externalWindow(config)
|
await this.externalWindow(config)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -461,7 +461,7 @@ export default {
|
|||||||
...config,
|
...config,
|
||||||
|
|
||||||
// 新窗口强制参数
|
// 新窗口强制参数
|
||||||
url_type: config.url_type.replace(/_blank$/, ''),
|
type: config.type.replace(/_blank$/, ''),
|
||||||
transparent: true,
|
transparent: true,
|
||||||
keep_alive: false,
|
keep_alive: false,
|
||||||
};
|
};
|
||||||
@ -621,7 +621,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isIframe(app.url_type)) {
|
if (this.isIframe(app.type)) {
|
||||||
const before = app.onBeforeClose();
|
const before = app.onBeforeClose();
|
||||||
if (before && before.then) {
|
if (before && before.then) {
|
||||||
before.then(() => {
|
before.then(() => {
|
||||||
@ -685,7 +685,7 @@ export default {
|
|||||||
if (!app) {
|
if (!app) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.isIframe(app.url_type)) {
|
if (this.isIframe(app.type)) {
|
||||||
app.postMessage({
|
app.postMessage({
|
||||||
type: 'MICRO_APP_MENU_CLICK',
|
type: 'MICRO_APP_MENU_CLICK',
|
||||||
message: action
|
message: action
|
||||||
@ -743,7 +743,7 @@ export default {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
shouldRenderIFrame(app) {
|
shouldRenderIFrame(app) {
|
||||||
return app.url && this.isIframe(app.url_type) && (app.isOpen || app.keep_alive);
|
return app.url && this.isIframe(app.type) && (app.isOpen || app.keep_alive);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -752,7 +752,7 @@ export default {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
shouldRenderMicro(app) {
|
shouldRenderMicro(app) {
|
||||||
return app.url && !this.isIframe(app.url_type) && (app.isOpen || this.closings.includes(app.name));
|
return app.url && !this.isIframe(app.type) && (app.isOpen || this.closings.includes(app.name));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -184,8 +184,8 @@
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
<Row :gutter="16">
|
<Row :gutter="16">
|
||||||
<Col :sm="12" :xs="24">
|
<Col :sm="12" :xs="24">
|
||||||
<FormItem :label="$L('URL 类型')">
|
<FormItem :label="$L('类型')">
|
||||||
<Select v-model="item.menu.url_type" transfer>
|
<Select v-model="item.menu.type" transfer>
|
||||||
<Option value="iframe">iframe</Option>
|
<Option value="iframe">iframe</Option>
|
||||||
<Option value="iframe_blank">iframe_blank</Option>
|
<Option value="iframe_blank">iframe_blank</Option>
|
||||||
<Option value="inline">inline</Option>
|
<Option value="inline">inline</Option>
|
||||||
@ -439,7 +439,7 @@ const createCustomMicroMenu = () => ({
|
|||||||
version: 'custom',
|
version: 'custom',
|
||||||
menu: {
|
menu: {
|
||||||
location: 'application',
|
location: 'application',
|
||||||
url_type: 'iframe',
|
type: 'iframe',
|
||||||
visible_to: 'admin',
|
visible_to: 'admin',
|
||||||
keep_alive: true,
|
keep_alive: true,
|
||||||
auto_dark_theme: true,
|
auto_dark_theme: true,
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export default {
|
|||||||
id: 'iframe-test',
|
id: 'iframe-test',
|
||||||
name: 'iframe-test',
|
name: 'iframe-test',
|
||||||
url: url,
|
url: url,
|
||||||
url_type: 'iframe',
|
type: 'iframe',
|
||||||
transparent: true,
|
transparent: true,
|
||||||
keep_alive: false,
|
keep_alive: false,
|
||||||
})
|
})
|
||||||
|
|||||||
20
resources/assets/js/store/actions.js
vendored
20
resources/assets/js/store/actions.js
vendored
@ -5064,7 +5064,7 @@ export default {
|
|||||||
* - id 应用ID(必须)
|
* - id 应用ID(必须)
|
||||||
* - name 应用名称(必须)
|
* - name 应用名称(必须)
|
||||||
* - url 应用地址(必须)
|
* - url 应用地址(必须)
|
||||||
* - url_type 地址类型(可选)
|
* - type 打开类型(可选,string 或 {mobile,desktop,default};default 用于补齐 mobile/desktop,缺省为 iframe)
|
||||||
* - background 背景颜色(可选)
|
* - background 背景颜色(可选)
|
||||||
* - capsule 应用胶囊配置(可选)
|
* - capsule 应用胶囊配置(可选)
|
||||||
* - transparent 是否透明模式 (true/false),默认 false
|
* - transparent 是否透明模式 (true/false),默认 false
|
||||||
@ -5094,11 +5094,27 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.replace(/\{system_base_url}/g, serverLocation.origin)
|
.replace(/\{system_base_url}/g, serverLocation.origin)
|
||||||
|
|
||||||
|
const resolveType = () => {
|
||||||
|
if (typeof data.type === 'string') {
|
||||||
|
return data.type
|
||||||
|
}
|
||||||
|
if ($A.isJson(data.type)) {
|
||||||
|
const defaultType = typeof data.type.default === 'string' ? data.type.default : 'iframe'
|
||||||
|
const mobileType = typeof data.type.mobile === 'string'
|
||||||
|
? data.type.mobile
|
||||||
|
: (typeof data.type.app === 'string' ? data.type.app : defaultType)
|
||||||
|
const desktopType = typeof data.type.desktop === 'string' ? data.type.desktop : defaultType
|
||||||
|
return $A.platformType() === 'desktop' ? desktopType : mobileType
|
||||||
|
}
|
||||||
|
return 'inline'
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
url: $A.mainUrl(data.url),
|
url: $A.mainUrl(data.url),
|
||||||
url_type: data.url_type || 'inline',
|
type: resolveType(),
|
||||||
background: data.background || null,
|
background: data.background || null,
|
||||||
capsule: $A.isJson(data.capsule) ? data.capsule : {},
|
capsule: $A.isJson(data.capsule) ? data.capsule : {},
|
||||||
transparent: typeof data.transparent == 'boolean' ? data.transparent : false,
|
transparent: typeof data.transparent == 'boolean' ? data.transparent : false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user