前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Apache-ShenYu支持namespace功能

Apache-ShenYu支持namespace功能

作者头像
阿超
发布2024-08-23 19:44:55
740
发布2024-08-23 19:44:55
举报
文章被收录于专栏:快乐阿超

健康的身体是灵魂的客厅,病弱的身体是灵魂的监狱。——培根

我主要完成前端部分对接,pr如下:

https://github.com/apache/shenyu-dashboard/pull/462

这里主要是结合redux-saga完成需求,例如modal/global.js

shenyu-dashboard/src/models/global.js at 624a2afe74367b5c5a310627197d3622a8c896a4 · apache/shenyu-dashboard · GitHub

代码语言:javascript
复制
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { message } from "antd";
import { routerRedux } from "dva/router";
import {
  queryPlatform,
  getAllPlugins,
  getNamespaceList,
  asyncOnePlugin,
  getUserPermissionByToken,
} from "../services/api";
import { getIntlContent } from "../utils/IntlUtils";

export default {
  namespace: "global",

  state: {
    collapsed: false,
    platform: {},
    plugins: [],
    currentRouter: {},
    permissions: {},
    language: "",
    namespaces: [],
    currentNamespaceId: "649330b6-c2d7-4edc-be8e-8a54df9eb385",
  },

  effects: {
    *fetchPlatform(_, { call, put }) {
      const json = yield call(queryPlatform);
      if (json.code === 200) {
        yield put({
          type: "savePlatform",
          payload: json.data,
        });
      }
    },
    *fetchNamespaces(_, { call, put }) {
      const json = yield call(getNamespaceList);
      if (json.code === 200) {
        yield put({
          type: "saveNamespaces",
          payload: json.data,
        });
      }
    },
    *fetchPlugins({ payload }, { call, put }) {
      const { callback } = payload ?? {};
      const params = {
        currentPage: 1,
        pageSize: 50,
      };
      const json = yield call(getAllPlugins, params);
      if (json.code === 200) {
        let { dataList } = json.data;

        if (callback) {
          callback(dataList);
        }
        yield put({
          type: "savePlugins",
          payload: {
            dataList,
          },
        });
      }
    },
    *asyncPlugin(params, { call }) {
      const { payload } = params;
      const json = yield call(asyncOnePlugin, payload);
      if (json.code === 200) {
        message.success(getIntlContent("SHENYU.COMMON.RESPONSE.SYNC.SUCCESS"));
      } else {
        message.warn(json.message);
      }
    },
    *fetchPermission({ payload }, { call, put }) {
      const { callback } = payload;
      let permissions = { menu: [], button: [] };
      const token = window.sessionStorage.getItem("token");
      if (token) {
        const params = { token };
        const json = yield call(getUserPermissionByToken, params);
        if (json.code === 200) {
          let { menu, currentAuth } = json.data;
          permissions = { menu, button: currentAuth };
        } else {
          message.warn(getIntlContent("SHENYU.PERMISSION.EMPTY"));
          yield put(
            routerRedux.push({
              pathname: "/user/login",
            }),
          );
        }
      }

      yield put({
        type: "savePermissions",
        payload: { permissions },
      });
      callback(permissions);
    },
    *refreshPermission({ payload }, { call, put }) {
      const { callback } = payload ?? {};
      let permissions = { menu: [], button: [] };
      const token = window.sessionStorage.getItem("token");
      if (token) {
        const params = { token };
        const json = yield call(getUserPermissionByToken, params);
        if (json.code === 200) {
          let { menu, currentAuth } = json.data;
          permissions = { menu, button: currentAuth };
        }
      }

      yield put({
        type: "savePermissions",
        payload: { permissions },
      });
      if (callback) {
        callback(permissions);
      }
    },

    *resetPermission(_, { put }) {
      let permissions = { menu: [], button: [] };
      yield put({
        type: "savePermissions",
        payload: { permissions },
      });
    },
  },

  reducers: {
    changeLanguage(state, { payload }) {
      return {
        ...state,
        language: payload,
      };
    },
    changeLayoutCollapsed(state, { payload }) {
      return {
        ...state,
        collapsed: payload,
      };
    },
    savePlatform(state, { payload }) {
      return {
        ...state,
        platform: payload,
      };
    },
    saveNamespaces(state, { payload }) {
      return {
        ...state,
        namespaces: payload,
      };
    },
    saveCurrentNamespaceId(state, { payload }) {
      return {
        ...state,
        currentNamespaceId: payload,
      };
    },
    savePlugins(state, { payload }) {
      return {
        ...state,
        plugins: payload.dataList,
      };
    },
    saveCurrentRoutr(state, { payload }) {
      return {
        ...state,
        currentRouter: payload.currentRouter,
      };
    },
    savePermissions(state, { payload }) {
      return {
        ...state,
        permissions: payload.permissions,
      };
    },
  },

  subscriptions: {
    setup({ history }) {
      // Subscribe history(url) change, trigger `load` action if pathname is `/`
      return history.listen(({ pathname, search }) => {
        if (typeof window.ga !== "undefined") {
          window.ga("send", "pageview", pathname + search);
        }
      });
    },
  },
};

其他代码不多贴了

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-07-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档