|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +import { message } from "antd"; |
| 19 | +import { |
| 20 | + getRegistryList, |
| 21 | + insertOrUpdateRegistry, |
| 22 | + getRegistryDetail, |
| 23 | + batchDeleteRegistry, |
| 24 | +} from "../services/api"; |
| 25 | +import { getIntlContent } from "../utils/IntlUtils"; |
| 26 | + |
| 27 | +export default { |
| 28 | + namespace: "registry", |
| 29 | + |
| 30 | + state: { |
| 31 | + registryList: [], |
| 32 | + total: 0, |
| 33 | + }, |
| 34 | + |
| 35 | + effects: { |
| 36 | + *fetch(params, { call, put }) { |
| 37 | + const { payload } = params; |
| 38 | + const json = yield call(getRegistryList, payload); |
| 39 | + if (json.code === 200) { |
| 40 | + let { dataList, page } = json.data; |
| 41 | + dataList = dataList.map((item) => { |
| 42 | + item.key = item.id; |
| 43 | + return item; |
| 44 | + }); |
| 45 | + yield put({ |
| 46 | + type: "saveRegistryList", |
| 47 | + payload: { |
| 48 | + total: page.totalCount, |
| 49 | + dataList, |
| 50 | + }, |
| 51 | + }); |
| 52 | + } else { |
| 53 | + message.destroy(); |
| 54 | + message.error(json.message); |
| 55 | + } |
| 56 | + }, |
| 57 | + |
| 58 | + *add(params, { call, put }) { |
| 59 | + const { payload, callback, fetchValue } = params; |
| 60 | + const json = yield call(insertOrUpdateRegistry, payload); |
| 61 | + if (json.code === 200) { |
| 62 | + message.destroy(); |
| 63 | + message.success(getIntlContent("SHENYU.COMMON.RESPONSE.ADD.SUCCESS")); |
| 64 | + callback(); |
| 65 | + yield put({ type: "fetch", payload: fetchValue }); |
| 66 | + } else { |
| 67 | + message.destroy(); |
| 68 | + message.error(json.message); |
| 69 | + } |
| 70 | + }, |
| 71 | + |
| 72 | + *update(params, { call, put }) { |
| 73 | + const { payload, callback, fetchValue } = params; |
| 74 | + const json = yield call(insertOrUpdateRegistry, payload); |
| 75 | + if (json.code === 200) { |
| 76 | + message.destroy(); |
| 77 | + message.success( |
| 78 | + getIntlContent("SHENYU.COMMON.RESPONSE.UPDATE.SUCCESS"), |
| 79 | + ); |
| 80 | + callback(); |
| 81 | + yield put({ type: "fetch", payload: fetchValue }); |
| 82 | + } else { |
| 83 | + message.destroy(); |
| 84 | + message.error(json.message); |
| 85 | + } |
| 86 | + }, |
| 87 | + |
| 88 | + *delete(params, { call, put }) { |
| 89 | + const { payload, fetchValue, callback } = params; |
| 90 | + const { list } = payload; |
| 91 | + const json = yield call(batchDeleteRegistry, { list }); |
| 92 | + if (json.code === 200) { |
| 93 | + message.destroy(); |
| 94 | + message.success( |
| 95 | + getIntlContent("SHENYU.COMMON.RESPONSE.DELETE.SUCCESS"), |
| 96 | + ); |
| 97 | + callback(); |
| 98 | + yield put({ type: "fetch", payload: fetchValue }); |
| 99 | + } else { |
| 100 | + message.destroy(); |
| 101 | + message.error(json.message); |
| 102 | + } |
| 103 | + }, |
| 104 | + |
| 105 | + *fetchItem(params, { call }) { |
| 106 | + const { payload, callback } = params; |
| 107 | + const json = yield call(getRegistryList, { id: payload.id }); |
| 108 | + if (json.code === 200) { |
| 109 | + const registry = json.data.dataList[0]; |
| 110 | + callback(registry); |
| 111 | + } else { |
| 112 | + message.destroy(); |
| 113 | + message.error(json.message); |
| 114 | + } |
| 115 | + }, |
| 116 | + *getDetail(params, { call }) { |
| 117 | + const { payload, callback } = params; |
| 118 | + const json = yield call(getRegistryDetail, payload); |
| 119 | + if (json.code === 200) { |
| 120 | + const registry = json.data; |
| 121 | + callback(registry); |
| 122 | + } else { |
| 123 | + message.destroy(); |
| 124 | + message.error(json.message); |
| 125 | + } |
| 126 | + }, |
| 127 | + }, |
| 128 | + |
| 129 | + reducers: { |
| 130 | + saveRegistryList(state, { payload }) { |
| 131 | + return { |
| 132 | + ...state, |
| 133 | + registryList: payload.dataList, |
| 134 | + total: payload.total, |
| 135 | + }; |
| 136 | + }, |
| 137 | + }, |
| 138 | +}; |
0 commit comments