You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2022/11/17 06:29:45 UTC

[incubator-streampark] branch dev updated: [improve] add menu i18n and fix team dropdown (#2037)

This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/dev by this push:
     new 70f39dc80 [improve] add menu i18n and fix team dropdown (#2037)
70f39dc80 is described below

commit 70f39dc80636b112c585b80320f05c0fd8e6c45b
Author: WSZ <12...@qq.com>
AuthorDate: Thu Nov 17 14:29:40 2022 +0800

    [improve] add menu i18n and fix team dropdown (#2037)
    
    * [improve] add menu i18n and fix team dropdown
    
    * [fix] update app.ts i18n
---
 .../streampark-console-webapp/src/api/base/system.ts | 12 +++---------
 .../layouts/default/header/components/UserTeam.vue   | 10 ++++++++--
 .../src/layouts/default/header/index.vue             |  6 +++++-
 .../src/locales/lang/en/layout.ts                    |  1 +
 .../src/locales/lang/en/system/team.ts               |  1 +
 .../src/locales/lang/zh-CN/flink/app.ts              |  2 +-
 .../src/locales/lang/zh-CN/layout.ts                 |  1 +
 .../src/locales/lang/zh-CN/system/team.ts            |  1 +
 .../src/router/helper/menuHelper.ts                  |  7 ++++++-
 .../src/store/modules/permission.ts                  |  3 ++-
 .../streampark-console-webapp/src/utils/index.ts     |  4 ++--
 .../src/views/flink/app/hooks/useCreateSchema.ts     |  2 +-
 .../src/views/system/menu/Menu.vue                   | 20 +++++++++++++++++++-
 13 files changed, 51 insertions(+), 19 deletions(-)

diff --git a/streampark-console/streampark-console-webapp/src/api/base/system.ts b/streampark-console/streampark-console-webapp/src/api/base/system.ts
index df34c398b..c21f65feb 100644
--- a/streampark-console/streampark-console-webapp/src/api/base/system.ts
+++ b/streampark-console/streampark-console-webapp/src/api/base/system.ts
@@ -27,7 +27,6 @@ import {
   MenuListModel,
 } from './model/systemModel';
 import { defHttp } from '/@/utils/http/axios';
-import { ContentTypeEnum } from '/@/enums/httpEnum';
 
 enum Api {
   AccountList = '/system/getAccountList',
@@ -47,14 +46,9 @@ export const getAccountList = (params: AccountParams) =>
 export const getDeptList = (params?: DeptListItem) =>
   defHttp.get<DeptListGetResultModel>({ url: Api.DeptList, params });
 
-export const getMenuList = (params?: MenuParams) =>
-  defHttp.post<MenuListModel>({
-    url: Api.MenuList,
-    params,
-    headers: {
-      'Content-Type': ContentTypeEnum.FORM_URLENCODED,
-    },
-  });
+export const getMenuList = (params?: MenuParams): Promise<MenuListModel> => {
+  return defHttp.post({ url: Api.MenuList, params });
+};
 
 export const getRoleMenu = (params?: MenuParams) =>
   defHttp.post<Array<string>>({
diff --git a/streampark-console/streampark-console-webapp/src/layouts/default/header/components/UserTeam.vue b/streampark-console/streampark-console-webapp/src/layouts/default/header/components/UserTeam.vue
index 5d04b6e35..c19433439 100644
--- a/streampark-console/streampark-console-webapp/src/layouts/default/header/components/UserTeam.vue
+++ b/streampark-console/streampark-console-webapp/src/layouts/default/header/components/UserTeam.vue
@@ -14,11 +14,17 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
+<script lang="ts">
+  export default {
+    name: 'UserTeam',
+  };
+</script>
 <script setup lang="ts">
   import { ApiSelect } from '/@/components/Form';
   import { useUserStoreWithOut } from '/@/store/modules/user';
   import { fetchUserTeam } from '/@/api/system/member';
-
+  import { useI18n } from '/@/hooks/web/useI18n';
+  const { t } = useI18n();
   const userStore = useUserStoreWithOut();
 
   function handleSetTeamId(value: string) {
@@ -36,7 +42,7 @@
 
 <template>
   <div class="flex items-center min-w-160px">
-    <span class="text-blue-500 pr-10px"> Team : </span>
+    <span class="text-blue-500 pr-10px"> {{ t('system.team.team') }} : </span>
     <ApiSelect
       :api="fetchUserTeam as any"
       labelField="teamName"
diff --git a/streampark-console/streampark-console-webapp/src/layouts/default/header/index.vue b/streampark-console/streampark-console-webapp/src/layouts/default/header/index.vue
index 546376140..730224ffa 100755
--- a/streampark-console/streampark-console-webapp/src/layouts/default/header/index.vue
+++ b/streampark-console/streampark-console-webapp/src/layouts/default/header/index.vue
@@ -52,7 +52,7 @@
     <!-- action  -->
     <div :class="`${prefixCls}-action`">
       <a-button type="link" size="small" class="!hidden !md:block">
-        <span>Version:</span>
+        <span>{{ t('layout.header.version') }}:</span>
         <span class="pl-2px">{{ version }}</span>
       </a-button>
       <Divider type="vertical" />
@@ -119,6 +119,8 @@
   import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
   import { useLocale } from '/@/locales/useLocale';
   import { version } from '../../../../package.json';
+  import { useI18n } from '/@/hooks/web/useI18n';
+
   export default defineComponent({
     name: 'LayoutHeader',
     components: {
@@ -146,6 +148,7 @@
       fixed: propTypes.bool,
     },
     setup(props) {
+      const { t } = useI18n();
       const { prefixCls } = useDesign('layout-header');
       const {
         getShowTopMenu,
@@ -214,6 +217,7 @@
       });
 
       return {
+        t,
         prefixCls,
         getHeaderClass,
         getShowHeaderLogo,
diff --git a/streampark-console/streampark-console-webapp/src/locales/lang/en/layout.ts b/streampark-console/streampark-console-webapp/src/locales/lang/en/layout.ts
index 9410137c2..0c8394b0b 100644
--- a/streampark-console/streampark-console-webapp/src/locales/lang/en/layout.ts
+++ b/streampark-console/streampark-console-webapp/src/locales/lang/en/layout.ts
@@ -17,6 +17,7 @@
 export default {
   footer: { website: 'Website', onlineDocument: 'Document' },
   header: {
+    version: 'Version',
     // user dropdown
     dropdownItemDoc: 'Document',
     ChangePassword: 'ChangePassword',
diff --git a/streampark-console/streampark-console-webapp/src/locales/lang/en/system/team.ts b/streampark-console/streampark-console-webapp/src/locales/lang/en/system/team.ts
index f25938ae0..91acfb144 100644
--- a/streampark-console/streampark-console-webapp/src/locales/lang/en/system/team.ts
+++ b/streampark-console/streampark-console-webapp/src/locales/lang/en/system/team.ts
@@ -16,6 +16,7 @@
  */
 export default {
   addTeam: 'Add Team',
+  team: 'Team',
   modifyTeam: 'Modify Team',
   deleteTeam: 'Delete Team',
   deletePopConfirm: 'Are you sure delete this team ?',
diff --git a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/flink/app.ts b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/flink/app.ts
index 22a3abace..2956282d2 100644
--- a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/flink/app.ts
+++ b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/flink/app.ts
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 export default {
-  id: '作业编号',
+  id: '作业ID',
   appName: '作业名称',
   searchName: '名称',
   tags: '作业标签',
diff --git a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/layout.ts b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/layout.ts
index d0fa93b32..d16147507 100644
--- a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/layout.ts
+++ b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/layout.ts
@@ -17,6 +17,7 @@
 export default {
   footer: { website: '官网', onlineDocument: '在线文档' },
   header: {
+    version: '版本',
     // user dropdown
     dropdownItemDoc: '文档',
     ChangePassword: '更改密码',
diff --git a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/system/team.ts b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/system/team.ts
index 42ee4e16c..465761fd3 100644
--- a/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/system/team.ts
+++ b/streampark-console/streampark-console-webapp/src/locales/lang/zh-CN/system/team.ts
@@ -16,6 +16,7 @@
  */
 export default {
   addTeam: '创建Team',
+  team: '团队',
   modifyTeam: '编辑Team',
   deleteTeam: '删除Team',
   deletePopConfirm: '确定要删除这个Team ?',
diff --git a/streampark-console/streampark-console-webapp/src/router/helper/menuHelper.ts b/streampark-console/streampark-console-webapp/src/router/helper/menuHelper.ts
index 1d4aad081..3c17f5537 100644
--- a/streampark-console/streampark-console-webapp/src/router/helper/menuHelper.ts
+++ b/streampark-console/streampark-console-webapp/src/router/helper/menuHelper.ts
@@ -21,7 +21,8 @@ import { cloneDeep } from 'lodash-es';
 import { isUrl } from '/@/utils/is';
 import { RouteParams } from 'vue-router';
 import { toRaw } from 'vue';
-
+import { useI18n } from '/@/hooks/web/useI18n';
+const { t } = useI18n();
 export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
   const menuList = findPath(treeData, (n) => n.path === path) as Menu[];
   return (menuList || []).map((item) => item.path);
@@ -31,6 +32,10 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
 function joinParentPath(menus: Menu[], parentPath = '') {
   for (let index = 0; index < menus.length; index++) {
     const menu = menus[index];
+    // use i18n
+    if (!menu.hideMenu && /^\w+\.\w+$/.test(menu.name)) {
+      menu.name = t(`menu.${menu.name}`);
+    }
     // https://next.router.vuejs.org/guide/essentials/nested-routes.html
     // Note that nested paths that start with / will be treated as a root path.
     // This allows you to leverage the component nesting without having to use a nested URL.
diff --git a/streampark-console/streampark-console-webapp/src/store/modules/permission.ts b/streampark-console/streampark-console-webapp/src/store/modules/permission.ts
index ebb3500e4..2ab00288c 100644
--- a/streampark-console/streampark-console-webapp/src/store/modules/permission.ts
+++ b/streampark-console/streampark-console-webapp/src/store/modules/permission.ts
@@ -129,7 +129,8 @@ export const usePermissionStore = defineStore({
       // get teamList
       const { userId } = getAuthCache(USER_INFO_KEY) as UserInfo;
       let hasAuth = false;
-      if (userStore.teamList.length == 0 && userId) {
+      // Get the team list when building a route to ensure data consistency
+      if (userId) {
         const teamList = await fetchUserTeam({ userId });
         userStore.setTeamList(teamList.map((i) => ({ label: i.teamName, value: i.id })));
       }
diff --git a/streampark-console/streampark-console-webapp/src/utils/index.ts b/streampark-console/streampark-console-webapp/src/utils/index.ts
index ebe45cbe5..2142d5898 100644
--- a/streampark-console/streampark-console-webapp/src/utils/index.ts
+++ b/streampark-console/streampark-console-webapp/src/utils/index.ts
@@ -74,7 +74,7 @@ export function openWindow(
 export function getDynamicProps<T, U>(props: T): Partial<U> {
   const ret: Recordable = {};
 
-  Object.keys(props).map((key) => {
+  Object.keys(props as Recordable).map((key) => {
     ret[key] = unref((props as Recordable)[key]);
   });
 
@@ -99,7 +99,7 @@ export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormal
 export const withInstall = <T>(component: T, alias?: string) => {
   const comp = component as any;
   comp.install = (app: App) => {
-    app.component(comp.name || comp.displayName, component);
+    app.component(comp.name || comp.displayName, component as any);
     if (alias) {
       app.config.globalProperties[alias] = component;
     }
diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts b/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
index 69c006e47..2e2a90da2 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
@@ -251,7 +251,7 @@ export const useCreateSchema = (dependencyRef: Ref) => {
       },
       {
         field: 'jar',
-        label: t('flink.app.talbe.programJar'),
+        label: t('flink.app.programJar'),
         component: 'Select',
         componentProps: ({ formModel }) => {
           return {
diff --git a/streampark-console/streampark-console-webapp/src/views/system/menu/Menu.vue b/streampark-console/streampark-console-webapp/src/views/system/menu/Menu.vue
index ed62a9ca3..b70294f7d 100644
--- a/streampark-console/streampark-console-webapp/src/views/system/menu/Menu.vue
+++ b/streampark-console/streampark-console-webapp/src/views/system/menu/Menu.vue
@@ -36,6 +36,7 @@
   import { columns, searchFormSchema } from './menu.data';
   import { useMessage } from '/@/hooks/web/useMessage';
   import { useI18n } from '/@/hooks/web/useI18n';
+  import { isArray } from '/@/utils/is';
 
   export default defineComponent({
     name: 'MenuManagement',
@@ -47,6 +48,14 @@
       const [registerTable, { reload, expandAll }] = useTable({
         title: t('system.menu.table.title'),
         api: getMenuList,
+        afterFetch(result) {
+          try {
+            handleMenuName(result);
+          } catch (error) {
+            console.error(error);
+          }
+          return result;
+        },
         columns,
         formConfig: {
           baseColProps: { style: { paddingRight: '30px' } },
@@ -68,7 +77,16 @@
         //   dataIndex: 'action',
         // },
       });
-
+      function handleMenuName(menus: Recordable[]) {
+        if (isArray(menus)) {
+          menus.forEach((menu: Recordable) => {
+            if (menu.children && menu.children.length > 0) handleMenuName(menu.children);
+            if (menu.display && menu.type == '0' && /^\w+\.\w+$/.test(menu.title)) {
+              menu.text = t(`menu.${menu.text}`);
+            }
+          });
+        }
+      }
       function handleCreate() {
         openDrawer(true, { isUpdate: false });
       }