From a47aa0c4314e690fc3dda1736df20416581b1d78 Mon Sep 17 00:00:00 2001 From: jiangzhixiong <710328466@qq.com> Date: Thu, 9 May 2024 11:56:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(zhst/func):=20=E6=B7=BB=E5=8A=A0pxtoRem?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/biz/CHANGELOG.md | 23 +++ packages/biz/package.json | 2 +- packages/biz/src/tree/boxTree.tsx | 3 +- .../biz/src/treeTransfer/TreeTransfer.tsx | 3 +- packages/biz/src/treeTransfer/demo/basic.tsx | 4 +- packages/biz/src/treeTransfer/demo/mock.ts | 2 +- packages/func/.fatherrc.ts | 11 +- packages/func/CHANGELOG.md | 17 ++ packages/func/es/string/demo/getValueByUrl.js | 43 ----- packages/func/es/string/index.js | 15 ++ .../func/lib/string/demo/getValueByUrl.js | 48 ------ packages/func/lib/string/index.js | 11 +- packages/func/package.json | 2 +- packages/func/src/string/demo/pxTorem.tsx | 25 +++ packages/func/src/string/demo/scale.temp.ts | 131 +++++++++++++++ packages/func/src/string/index.md | 1 + packages/func/src/string/index.ts | 12 ++ packages/func/src/utils/autoSize.ts | 151 ++++++++++++++++++ packages/hooks/.fatherrc.ts | 11 +- packages/hooks/CHANGELOG.md | 13 ++ packages/hooks/package.json | 2 +- packages/icon/.fatherrc.ts | 10 +- packages/material/CHANGELOG.md | 51 ++++++ packages/material/package.json | 4 +- .../src/algorithmConfig/algorithmConfig.tsx | 67 ++++++-- .../algorithmTable/AlgorithmTable.tsx | 61 +++---- .../timeTemplateTable/TimeTemplateTable.tsx | 21 ++- .../src/algorithmConfig/demo/basic.tsx | 2 +- packages/meta/CHANGELOG.md | 17 ++ packages/meta/package.json | 2 +- packages/request/.fatherrc.ts | 10 +- packages/request/CHANGELOG.md | 14 ++ packages/request/es/index.js | 67 +++----- packages/request/lib/index.js | 24 +-- packages/request/package.json | 2 +- packages/request/src/code.ts | 47 ++++++ packages/request/src/index.tsx | 71 +++----- packages/slave/CHANGELOG.md | 13 ++ packages/slave/es/index.js | 70 +++++--- packages/slave/lib/index.js | 59 ++++--- packages/slave/package.json | 2 +- packages/slave/src/index.tsx | 17 +- 42 files changed, 839 insertions(+), 322 deletions(-) delete mode 100644 packages/func/es/string/demo/getValueByUrl.js delete mode 100644 packages/func/lib/string/demo/getValueByUrl.js create mode 100644 packages/func/src/string/demo/pxTorem.tsx create mode 100644 packages/func/src/string/demo/scale.temp.ts create mode 100644 packages/func/src/utils/autoSize.ts create mode 100644 packages/request/src/code.ts diff --git a/packages/biz/CHANGELOG.md b/packages/biz/CHANGELOG.md index b7adda0..4ddf2fb 100644 --- a/packages/biz/CHANGELOG.md +++ b/packages/biz/CHANGELOG.md @@ -1,5 +1,28 @@ # @zhst/biz +## 0.18.8 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + - @zhst/hooks@0.10.4 + - @zhst/meta@0.16.4 + +## 0.18.7 + +### Patch Changes + +- @zhst/func@0.11.3 +- @zhst/hooks@0.10.3 +- @zhst/meta@0.16.3 + +## 0.18.6 + +### Patch Changes + +- biz 优化无限滚动组件、boxselectTree 组件;material 修改算法编辑模块 + ## 0.18.5 ### Patch Changes diff --git a/packages/biz/package.json b/packages/biz/package.json index 8754a9c..b897fe3 100644 --- a/packages/biz/package.json +++ b/packages/biz/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/biz", - "version": "0.18.5", + "version": "0.18.8", "description": "业务库", "keywords": [ "business", diff --git a/packages/biz/src/tree/boxTree.tsx b/packages/biz/src/tree/boxTree.tsx index f769199..48798f6 100644 --- a/packages/biz/src/tree/boxTree.tsx +++ b/packages/biz/src/tree/boxTree.tsx @@ -1,6 +1,5 @@ import React, { FC, useState } from 'react'; -import { Tree, Badge, TreeDataNode, Space, TreeProps } from 'antd'; -import theme from 'antd/es/theme' +import { Tree, Badge, TreeDataNode, Space, TreeProps, theme } from 'antd'; import { CloseOutlined, EditOutlined, SettingOutlined } from '@ant-design/icons' import { ModalForm, ProFormText } from '@ant-design/pro-components'; import './index.less' diff --git a/packages/biz/src/treeTransfer/TreeTransfer.tsx b/packages/biz/src/treeTransfer/TreeTransfer.tsx index b89a493..4a7d46a 100644 --- a/packages/biz/src/treeTransfer/TreeTransfer.tsx +++ b/packages/biz/src/treeTransfer/TreeTransfer.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react'; -import { Button, Card, ConfigProvider, Flex, Input, InputProps, TransferProps, TreeDataNode, TreeProps, Tree } from 'antd'; -import theme from 'antd/es/theme' +import { Button, Card, ConfigProvider, theme, Flex, Input, InputProps, TransferProps, TreeDataNode, TreeProps, Tree } from 'antd'; import './index.less' import { DeleteOutlined, DoubleRightOutlined, SearchOutlined } from '@ant-design/icons'; diff --git a/packages/biz/src/treeTransfer/demo/basic.tsx b/packages/biz/src/treeTransfer/demo/basic.tsx index c4858d1..35be3a6 100644 --- a/packages/biz/src/treeTransfer/demo/basic.tsx +++ b/packages/biz/src/treeTransfer/demo/basic.tsx @@ -22,9 +22,9 @@ const App: React.FC = () => { * @param key * @param param1 */ - const onItemDelete = (key: any, { keys }: any) => { + const onItemDelete = (key: any, { keys = [] }: any) => { setCheckedKeys(pre => { - const newKeys = pre.filter(_key => !keys.includes(_key)) + const newKeys = pre.filter(_key => _key !== key) console.log('newKeys', newKeys, keys) return newKeys }) diff --git a/packages/biz/src/treeTransfer/demo/mock.ts b/packages/biz/src/treeTransfer/demo/mock.ts index 32106c5..27235c5 100644 --- a/packages/biz/src/treeTransfer/demo/mock.ts +++ b/packages/biz/src/treeTransfer/demo/mock.ts @@ -30,7 +30,7 @@ export const boxDataSource: TreeDataNode[] = [ title: '分组0-1-4', isLeaf: false, children: [ - { key: '0-1-3-1', title: '分组0-1-3-1', isLeaf: true }, + { key: '0-1-4-1', title: '分组0-1-3-1', isLeaf: true }, { key: '0-1-4-2', title: '分组0-1-3-2', isLeaf: true }, { key: '0-1-4-3', title: '分组0-1-3-3', isLeaf: true }, ], diff --git a/packages/func/.fatherrc.ts b/packages/func/.fatherrc.ts index f057955..447d06b 100644 --- a/packages/func/.fatherrc.ts +++ b/packages/func/.fatherrc.ts @@ -2,7 +2,12 @@ import { defineConfig } from 'father'; export default defineConfig({ // more father config: https://github.com/umijs/father/blob/master/docs/config.md - esm: { output: 'es' }, - cjs: { output: 'lib' }, - // umd: { output: 'dist' } + esm: { + output: 'es', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, + cjs: { + output: 'lib', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, }); diff --git a/packages/func/CHANGELOG.md b/packages/func/CHANGELOG.md index 1d876c6..fb91a08 100644 --- a/packages/func/CHANGELOG.md +++ b/packages/func/CHANGELOG.md @@ -1,5 +1,22 @@ # @zhst/utils +## 0.12.0 + +### Minor Changes + +- feat: zhst/func 添加 pxToRem 方法 + +### Patch Changes + +- @zhst/request@0.12.4 + +## 0.11.3 + +### Patch Changes + +- Updated dependencies + - @zhst/request@0.12.3 + ## 0.11.2 ### Patch Changes diff --git a/packages/func/es/string/demo/getValueByUrl.js b/packages/func/es/string/demo/getValueByUrl.js deleted file mode 100644 index afe0071..0000000 --- a/packages/func/es/string/demo/getValueByUrl.js +++ /dev/null @@ -1,43 +0,0 @@ -function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } -function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } -function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } -function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } -function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } -/** - * Created by jiangzhixiong on 2024/03/20 - */ - -import React, { useState } from 'react'; -import { getValueByUrl } from '@zhst/func'; -import { Input, Button, Space } from 'antd'; -var demo = function demo() { - var _useState = useState(null), - _useState2 = _slicedToArray(_useState, 2), - url = _useState2[0], - setUrl = _useState2[1]; - var _useState3 = useState(null), - _useState4 = _slicedToArray(_useState3, 2), - keyword = _useState4[0], - setKeyword = _useState4[1]; - var _useState5 = useState(null), - _useState6 = _slicedToArray(_useState5, 2), - outputVal = _useState6[0], - setOutPutVal = _useState6[1]; - var handleClick = function handleClick() { - var val = getValueByUrl(keyword, url); - setOutPutVal(val); - }; - return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Space, null, "\u94FE\u63A5\uFF1A", /*#__PURE__*/React.createElement(Input, { - onChange: function onChange(e) { - return setUrl(e.target.value); - } - }), "\u83B7\u53D6\u5B57\u6BB5\uFF1A", /*#__PURE__*/React.createElement(Input, { - onChange: function onChange(e) { - return setKeyword(e.target.value); - } - }), /*#__PURE__*/React.createElement(Button, { - onClick: handleClick - }, "\u63D0\u4EA4")), /*#__PURE__*/React.createElement("p", null, "\u8F93\u51FA\uFF1A", outputVal)); -}; -export default demo; \ No newline at end of file diff --git a/packages/func/es/string/index.js b/packages/func/es/string/index.js index 7e842b1..6178477 100644 --- a/packages/func/es/string/index.js +++ b/packages/func/es/string/index.js @@ -71,4 +71,19 @@ export var getValueByUrl = function getValueByUrl(key, str) { result = new URLSearchParams(str.indexOf('?') > -1 ? str : "?".concat(str)).get(key); } return result; +}; + +/** + * 行内px 转 rem + * @param value px像素 + * @param rootFontSize 根元素大小: 默认16px + */ +export var pxToRem = function pxToRem(value, rootFontSize) { + var fontSize = rootFontSize || parseFloat(document.documentElement.style.fontSize) || 16; + var valueArr = value.split(' '); + return valueArr.filter(function (o) { + return o; + }).map(function (val) { + return parseFloat(val) / fontSize + 'rem'; + }).join(' '); }; \ No newline at end of file diff --git a/packages/func/lib/string/demo/getValueByUrl.js b/packages/func/lib/string/demo/getValueByUrl.js deleted file mode 100644 index 73be0dd..0000000 --- a/packages/func/lib/string/demo/getValueByUrl.js +++ /dev/null @@ -1,48 +0,0 @@ -var __create = Object.create; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __getProtoOf = Object.getPrototypeOf; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( - // If the importer is in node compatibility mode or this is not an ESM - // file that has been converted to a CommonJS file using a Babel- - // compatible transform (i.e. "__esModule" has not been set), then set - // "default" to the CommonJS "module.exports" for node compatibility. - isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, - mod -)); -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/string/demo/getValueByUrl.tsx -var getValueByUrl_exports = {}; -__export(getValueByUrl_exports, { - default: () => getValueByUrl_default -}); -module.exports = __toCommonJS(getValueByUrl_exports); -var import_react = __toESM(require("react")); -var import_func = require("@zhst/func"); -var import_antd = require("antd"); -var demo = () => { - const [url, setUrl] = (0, import_react.useState)(null); - const [keyword, setKeyword] = (0, import_react.useState)(null); - const [outputVal, setOutPutVal] = (0, import_react.useState)(null); - const handleClick = () => { - let val = (0, import_func.getValueByUrl)(keyword, url); - setOutPutVal(val); - }; - return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, null, "链接:", /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { onChange: (e) => setUrl(e.target.value) }), "获取字段:", /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { onChange: (e) => setKeyword(e.target.value) }), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { onClick: handleClick }, "提交")), /* @__PURE__ */ import_react.default.createElement("p", null, "输出:", outputVal)); -}; -var getValueByUrl_default = demo; diff --git a/packages/func/lib/string/index.js b/packages/func/lib/string/index.js index 0bab8ba..b5e6592 100644 --- a/packages/func/lib/string/index.js +++ b/packages/func/lib/string/index.js @@ -22,7 +22,8 @@ __export(string_exports, { cutStr: () => cutStr, getStrLength: () => getStrLength, getValueByUrl: () => getValueByUrl, - isUrl: () => isUrl + isUrl: () => isUrl, + pxToRem: () => pxToRem }); module.exports = __toCommonJS(string_exports); var getStrLength = function(str) { @@ -74,10 +75,16 @@ var getValueByUrl = (key, str) => { } return result; }; +var pxToRem = (value, rootFontSize) => { + const fontSize = rootFontSize || parseFloat(document.documentElement.style.fontSize) || 16; + const valueArr = value.split(" "); + return valueArr.filter((o) => o).map((val) => parseFloat(val) / fontSize + "rem").join(" "); +}; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { cutStr, getStrLength, getValueByUrl, - isUrl + isUrl, + pxToRem }); diff --git a/packages/func/package.json b/packages/func/package.json index dfe1dfa..54ac8a6 100644 --- a/packages/func/package.json +++ b/packages/func/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/func", - "version": "0.11.2", + "version": "0.12.0", "description": "函数合集", "keywords": [ "hooks" diff --git a/packages/func/src/string/demo/pxTorem.tsx b/packages/func/src/string/demo/pxTorem.tsx new file mode 100644 index 0000000..0f2a1e9 --- /dev/null +++ b/packages/func/src/string/demo/pxTorem.tsx @@ -0,0 +1,25 @@ +/** + * Created by jiangzhixiong on 2024/03/20 + */ + +import React, { useState } from 'react' +import { pxToRem } from '@zhst/func' +import { Input } from 'antd' + +const demo = () => { + const [outputVal, setOutPutVal ] = useState(null) + + const handleChange = (e) => { + const value = pxToRem(e.target.value) + setOutPutVal(value) + } + + return ( +
+ +

输出:{outputVal}

+
+ ) +} + +export default demo diff --git a/packages/func/src/string/demo/scale.temp.ts b/packages/func/src/string/demo/scale.temp.ts new file mode 100644 index 0000000..f7a49db --- /dev/null +++ b/packages/func/src/string/demo/scale.temp.ts @@ -0,0 +1,131 @@ +// @ts-nocheck +// !! 参考代码,不投入使用 +/** + * 适应屏幕 + */ +const screenAdapt = () => { + window.global = window; + (function () { + if ($(window).width() >= 1920) { + $(window).width() && $('body').css('width', $(window).width()); + $(window).height() && $('body').css('height', $(window).height()); + } else { + $(window).width() && $('body').css('width', "1920px"); + + var ratio = $(window).width() / (1920 || $('body').width()); + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: "100%", + height: "1080px" + }); + } + $('head').append(''); + + + //监听页面是否发生改变 + $(window, document).resize(function () { + resize(); + }) + + + function resize () { + if (window.screen.display == 2) { // 等比缩放高度铺满 + resizeCenter(); + } else if (window.screen.display == 3) { //全屏铺满 + resizeFull(); + } else if (window.screen.display == 4) { //等比缩放高度铺满并且可以左右移动 + resizeHeight(); + } else { // 等比缩放宽度铺满 + resizeWidth(); + } + + } + function resizeWidth () { + window.location.reload() + if ($(window).width() >= 1920) { + var ratio = $(window).width() / ($(window).width() || $('body').width()); + $(window).height() && $('body').css('height', $(window).height()); + } else { + $('body').css('height', "1080px"); + } + var ratio = $(window).width() / (1920 || $('body').width()); + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: "100%" + }); + } + function resizeCenter () { + if (!window.screen.height || !window.screen.width) return resizeCenterBak(); + var ratio = $(window).height() / window.screen.height; + + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: 100 * (window.screen.width / $(window).width() * ratio) + "%" + ' 100%', + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + marginLeft: ($(window).width() - $('body').width() * ratio) / 2 + }); + } + + + function resizeHeight () { // + if (!window.screen.height || !window.screen.width) return resizeCenterBak(); + var ratio = $(window).height() / window.screen.height; + + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: 100 * (window.screen.width / $(window).width() * ratio) + "%" + ' 100%', + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + // marginLeft: ($(window).width() - $('body').width() * ratio) / 2 + }); + $('html').css({ + overflowX: 'scroll', + }) + } + + + function resizeFull () { + if (!window.screen.height || !window.screen.width) return resizeFullBak(); + var ratioX = $(window).width() / window.screen.width; + var ratioY = $(window).height() / window.screen.height; + + $('body').css({ + transform: "scale(" + ratioX + ", " + ratioY + ")", + transformOrigin: "left top", + backgroundSize: "100% 100%", + }); + } + + + function resizeCenterBak () { + var ratioX = $(window).width() / $('body').width(); + var ratioY = $(window).height() / $('body').height(); + var ratio = Math.min(ratioX, ratioY); + + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: (1 / ratioX) * 100 * ratio + "%", + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + marginLeft: ($(window).width() - $('body').width() * ratio) / 2 + }); + } + function resizeFullBak () { + var ratioX = $(window).width() / $('body').width(); + var ratioY = $(window).height() / $('body').height(); + + + $('body').css({ + transform: "scale(" + ratioX + ", " + ratioY + ")", + transformOrigin: "left top", + backgroundSize: "100% " + ratioY * 100 + "%", + }); + } + })(); +} diff --git a/packages/func/src/string/index.md b/packages/func/src/string/index.md index 82cf768..ffc97ad 100644 --- a/packages/func/src/string/index.md +++ b/packages/func/src/string/index.md @@ -21,3 +21,4 @@ const value3 = getValueByUrl('a', 'a=123&token=asdfasdfsdf') ``` 调试台 +px 转 rem diff --git a/packages/func/src/string/index.ts b/packages/func/src/string/index.ts index 996a23d..08ad3a1 100644 --- a/packages/func/src/string/index.ts +++ b/packages/func/src/string/index.ts @@ -78,3 +78,15 @@ export const getValueByUrl = (key: string, str: string) => { return result } + +/** + * 行内px 转 rem + * @param value px像素 + * @param rootFontSize 根元素大小: 默认16px + */ +export const pxToRem = (value: string, rootFontSize?: number) => { + const fontSize = rootFontSize || parseFloat(document.documentElement.style.fontSize) || 16 + const valueArr = value.split(' ') + + return valueArr.filter(o => o).map(val => ((parseFloat(val) / fontSize) + 'rem')).join(' ') +} diff --git a/packages/func/src/utils/autoSize.ts b/packages/func/src/utils/autoSize.ts new file mode 100644 index 0000000..8fa95a3 --- /dev/null +++ b/packages/func/src/utils/autoSize.ts @@ -0,0 +1,151 @@ +// @ts-nocheck +// !! 开发中 +// 手动添加mate标签 +const addMeta = (name: string, content: string) => { + const meta = document.createElement('meta'); + meta.content = content; + meta.name = name; + document.getElementsByTagName('head')[0].appendChild(meta); +}; + + +const autoResize = (opt: { + el: HTMLDivElement + targetWidth?: number + targetHeight?: number +}) => { + const { targetHeight = 1080, targetWidth = 1920, el } = opt + let targetRatio = targetWidth / targetHeight; // 宽高比率 (宽 / 高) - 默认:16 /9 + + // 当前设备(浏览器)的宽度 + let clientWidth = + document.documentElement.clientWidth || document.body.clientWidth; + let clientHeight = + document.documentElement.clientHeight || document.body.clientHeight; + // 当前宽高比例 + // let currentRatio = clientWidth / clientHeight; + + if (clientWidth >= 1920) { + el.style.width = `${clientWidth}px` + el.style.height = `${clientHeight}px` + } else { + el.style.width = '1920px' + + // let currentRatio = + } + + addMeta( + 'viewport', + 'width=' + clientWidth + ',initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover', + ); + + + const resizeWidth = () => { + if ($(window).width() >= 1920) { + var ratio = $(window).width() / ($(window).width() || $('body').width()); + $(window).height() && $('body').css('height', $(window).height()); + } else { + $('body').css('height', "1080px"); + } + var ratio = $(window).width() / (1920 || $('body').width()); + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: "100%" + }); + } + function resizeCenter () { + if (!window.screen.height || !window.screen.width) return resizeCenterBak(); + var ratio = $(window).height() / window.screen.height; + + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: 100 * (window.screen.width / $(window).width() * ratio) + "%" + ' 100%', + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + marginLeft: ($(window).width() - $('body').width() * ratio) / 2 + }); + } + + + function resizeHeight () { // + if (!window.screen.height || !window.screen.width) return resizeCenterBak(); + var ratio = $(window).height() / window.screen.height; + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: 100 * (window.screen.width / $(window).width() * ratio) + "%" + ' 100%', + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + }); + $('html').css({ + overflowX: 'scroll', + }) + } + + + function resizeFull () { + if (!window.screen.height || !window.screen.width) return resizeFullBak(); + var ratioX = $(window).width() / window.screen.width; + var ratioY = $(window).height() / window.screen.height; + + $('body').css({ + transform: "scale(" + ratioX + ", " + ratioY + ")", + transformOrigin: "left top", + backgroundSize: "100% 100%", + }); + } + + + function resizeCenterBak () { + var ratioX = $(window).width() / $('body').width(); + var ratioY = $(window).height() / $('body').height(); + var ratio = Math.min(ratioX, ratioY); + + + $('body').css({ + transform: "scale(" + ratio + ")", + transformOrigin: "left top", + backgroundSize: (1 / ratioX) * 100 * ratio + "%", + backgroundPosition: ($(window).width() - $('body').width() * ratio) / 2 + "px top", + marginLeft: ($(window).width() - $('body').width() * ratio) / 2 + }); + } + function resizeFullBak () { + var ratioX = $(window).width() / $('body').width(); + var ratioY = $(window).height() / $('body').height(); + + + $('body').css({ + transform: "scale(" + ratioX + ", " + ratioY + ")", + transformOrigin: "left top", + backgroundSize: "100% " + ratioY * 100 + "%", + }); + } + + if (window.screen.display === 2) { // 等比缩放高度铺满 + resizeCenter(); + } else if (window.screen.display === 3) { //全屏铺满 + resizeFull(); + } else if (window.screen.display === 4) { //等比缩放高度铺满并且可以左右移动 + resizeHeight(); + } else { // 等比缩放宽度铺满 + resizeWidth(); + } + + + // if (currentRatio > targetRatio) { + // let scaleRatio = clientHeight / targetHeight; // 参照高度进行缩放(屏幕很宽的情况下) + // const transform = `scale(${scaleRatio}) translateX(-50%) left: 50%`; + // console.log('transform', transform) + // // el.style.transform = + // } else { + // // 4.开始缩放网页 + // let scaleRatio = clientWidth / targetWidth; // 参照宽度进行缩放(默认情况下) + // console.log('scaleRatio', scaleRatio) + // el.style.transform = `scale(${scaleRatio})`; + // } +} + +export default autoResize diff --git a/packages/hooks/.fatherrc.ts b/packages/hooks/.fatherrc.ts index f057955..447d06b 100644 --- a/packages/hooks/.fatherrc.ts +++ b/packages/hooks/.fatherrc.ts @@ -2,7 +2,12 @@ import { defineConfig } from 'father'; export default defineConfig({ // more father config: https://github.com/umijs/father/blob/master/docs/config.md - esm: { output: 'es' }, - cjs: { output: 'lib' }, - // umd: { output: 'dist' } + esm: { + output: 'es', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, + cjs: { + output: 'lib', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, }); diff --git a/packages/hooks/CHANGELOG.md b/packages/hooks/CHANGELOG.md index 687b404..0768a9d 100644 --- a/packages/hooks/CHANGELOG.md +++ b/packages/hooks/CHANGELOG.md @@ -1,5 +1,18 @@ # @zhst/hooks +## 0.10.4 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + +## 0.10.3 + +### Patch Changes + +- @zhst/func@0.11.3 + ## 0.10.2 ### Patch Changes diff --git a/packages/hooks/package.json b/packages/hooks/package.json index 60b4ff4..b6e3f6c 100644 --- a/packages/hooks/package.json +++ b/packages/hooks/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/hooks", - "version": "0.10.2", + "version": "0.10.4", "description": "hooks合集", "keywords": [ "hooks" diff --git a/packages/icon/.fatherrc.ts b/packages/icon/.fatherrc.ts index 9e3a0ef..447d06b 100644 --- a/packages/icon/.fatherrc.ts +++ b/packages/icon/.fatherrc.ts @@ -2,6 +2,12 @@ import { defineConfig } from 'father'; export default defineConfig({ // more father config: https://github.com/umijs/father/blob/master/docs/config.md - esm: { output: 'es' }, - cjs: { output: 'lib' }, + esm: { + output: 'es', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, + cjs: { + output: 'lib', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, }); diff --git a/packages/material/CHANGELOG.md b/packages/material/CHANGELOG.md index eec15b6..57a4c5c 100644 --- a/packages/material/CHANGELOG.md +++ b/packages/material/CHANGELOG.md @@ -1,5 +1,56 @@ # @zhst/material +## 0.13.4 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + - @zhst/biz@0.18.8 + - @zhst/hooks@0.10.4 + - @zhst/meta@0.16.4 + +## 0.13.3 + +### Patch Changes + +- zhst/material: 修改 theme 组件引用方式 + +## 0.13.2 + +### Patch Changes + +- zhst/material: 修改 antd 依赖版本 + +## 0.13.1 + +### Patch Changes + +- zhst/material: 修复引用 antd/theme 失败 + +## 0.13.0 + +### Minor Changes + +- zhst/material: 添加盒子列表加载更多 + +## 0.12.7 + +### Patch Changes + +- @zhst/func@0.11.3 +- @zhst/biz@0.18.7 +- @zhst/hooks@0.10.3 +- @zhst/meta@0.16.3 + +## 0.12.6 + +### Patch Changes + +- biz 优化无限滚动组件、boxselectTree 组件;material 修改算法编辑模块 +- Updated dependencies + - @zhst/biz@0.18.6 + ## 0.12.5 ### Patch Changes diff --git a/packages/material/package.json b/packages/material/package.json index 50577a9..2040332 100644 --- a/packages/material/package.json +++ b/packages/material/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/material", - "version": "0.12.5", + "version": "0.13.4", "description": "物料库", "keywords": [ "business", @@ -43,7 +43,7 @@ "@zhst/meta": "workspace:^", "xterm": "^5.3.0", "xterm-addon-fit": "^0.8.0", - "antd": "^5.14.2", + "antd": "^5.12.5", "classnames": "^2.5.1", "rc-util": "^5.38.1" } diff --git a/packages/material/src/algorithmConfig/algorithmConfig.tsx b/packages/material/src/algorithmConfig/algorithmConfig.tsx index 34ccdc2..d94c442 100644 --- a/packages/material/src/algorithmConfig/algorithmConfig.tsx +++ b/packages/material/src/algorithmConfig/algorithmConfig.tsx @@ -1,5 +1,5 @@ -import React, { forwardRef, useImperativeHandle } from 'react'; -import { Flex, Image } from "antd"; +import React, { forwardRef, ReactNode, useImperativeHandle } from 'react'; +import { Button, Flex, Image } from "antd"; import theme from 'antd/es/theme' import { CropperImage } from '@zhst/meta' import type { CropperImageProps } from '@zhst/meta' @@ -49,6 +49,22 @@ export interface AlgorithmConfigProps { type: AlgorithmTableProps['tableType'] title?:string; // boxList列表的属性名称【点位列表、盒子列表】 onSelect?: (key: string, info?: any) => void + /** + * 是否显示/隐藏加载更多按钮 + */ + showLoadMoreButton?: boolean + /** + * 点击加载更多事件 + */ + onLoadMoreButtonClick?: () => void; + /** + * 自定义加载更多按钮 + */ + customLoadMoreButton: ReactNode + /** + * 自定义批量中间文案 + */ + customBatchCenterContent: ReactNode } export interface AlgorithmConfigRef { @@ -58,15 +74,19 @@ const AlgorithmConfig = forwardRef((pr const { algorithmTableDataSource = [], timeTemplateDataSource = [], - boxList = [], drawListener, cropperImageProps = {}, algorithmTableProps, timeTemplateTableProps, selectedKey, + boxList = [], type = 'multiple', rowKey = 'id', onSelect, title='盒子名称', + showLoadMoreButton, + onLoadMoreButtonClick, + customBatchCenterContent, + customLoadMoreButton, } = props const { token } = useToken() // @ts-ignore @@ -77,14 +97,16 @@ const AlgorithmConfig = forwardRef((pr return ( -
+
{title} -
+
{boxList.map(item => { return (

onSelect?.(item.id, item)} + // @ts-ignore + key={item[rowKey]} + // @ts-ignore + onClick={() => onSelect?.(item[rowKey], item)} style={{ margin: 0, padding: `${token.paddingXXS}px ${token.paddingLG}px`, @@ -93,12 +115,27 @@ const AlgorithmConfig = forwardRef((pr color: selectedKey === item[rowKey] ? token.colorPrimary : token.colorText, // @ts-ignore backgroundColor: selectedKey === item[rowKey] ? token.blue1 : token.colorBgBase, - transition: '0cancelDraw.2s ease' + transition: '.2s ease all', + }} + onMouseEnter={(e: any) => { + e.target.style.backgroundColor = token.colorPrimaryBg + e.target.style.color = token.colorPrimary + }} + onMouseLeave={(e: any) => { + // @ts-ignore + if (selectedKey === item[rowKey]) return + e.target.style.color = token.colorText + e.target.style.backgroundColor = null }} >{item.name}

) })}
+ {showLoadMoreButton && ( +
+ {customLoadMoreButton || } +
+ )}
{/* 单个配置 */} @@ -117,12 +154,14 @@ const AlgorithmConfig = forwardRef((pr fallback={ErrorImage} />

请进行批量配置

-
    -
  • · 盒子批量配置仅支持同型号盒子;
  • -
  • · 采取覆盖式更新,不保留原有配置,且预警检测框默认全屏范围;
  • -
  • · 人流量统计默认检测线为屏幕中央横向线条,且箭头指向下方;
  • -
  • · 优先选择拉流正常的摄像头。
  • -
+ {customBatchCenterContent || ( +
    +
  • · 盒子批量配置仅支持同型号盒子;
  • +
  • · 采取覆盖式更新,不保留原有配置,且预警检测框默认全屏范围;
  • +
  • · 人流量统计默认检测线为屏幕中央横向线条,且箭头指向下方;
  • +
  • · 优先选择拉流正常的摄像头。
  • +
+ )}
) } diff --git a/packages/material/src/algorithmConfig/components/algorithmTable/AlgorithmTable.tsx b/packages/material/src/algorithmConfig/components/algorithmTable/AlgorithmTable.tsx index 98548e3..244c882 100644 --- a/packages/material/src/algorithmConfig/components/algorithmTable/AlgorithmTable.tsx +++ b/packages/material/src/algorithmConfig/components/algorithmTable/AlgorithmTable.tsx @@ -5,7 +5,7 @@ import { ProTable, } from '@ant-design/pro-components'; import { Popconfirm, Select, Space, Switch } from 'antd'; -import theme from 'antd/es/theme'; +import theme from 'antd/es/theme' import { AnyObject } from 'antd/es/_util/type'; import { SelectProps } from 'antd/lib'; import SchemaFormModal from '../schemaFormModal'; @@ -59,10 +59,10 @@ const AlgorithmTable= ( 0: { text: '白天' }, }, }, - { - title: '算力占用', - dataIndex: 'powerOccupy', - }, + // { + // title: '算力占用', + // dataIndex: 'powerOccupy', + // }, { title: '操作', key: 'option', @@ -88,29 +88,34 @@ const AlgorithmTable= ( ]; return ( - - columns={columns} - bordered - scroll={{ y: 240, x: 600 }} - dataSource={[]} - headerTitle={( - - + onAddAlgorithm?.(selectedKey)} style={{ fontSize: '24px', color: token.colorPrimary, cursor: 'pointer' }} /> + + + columns={columns} + bordered + scroll={{ y: 240, x: 600 }} + dataSource={[]} + cardProps={{ + bodyStyle: { + padding: 0 + } + }} + toolbar={undefined} + rowKey="id" + search={false} + options={false} + pagination={false} + {...props} + /> +
) } diff --git a/packages/material/src/algorithmConfig/components/timeTemplateTable/TimeTemplateTable.tsx b/packages/material/src/algorithmConfig/components/timeTemplateTable/TimeTemplateTable.tsx index 0d06431..889b8b9 100644 --- a/packages/material/src/algorithmConfig/components/timeTemplateTable/TimeTemplateTable.tsx +++ b/packages/material/src/algorithmConfig/components/timeTemplateTable/TimeTemplateTable.tsx @@ -4,8 +4,8 @@ import type { ParamsType, ProColumns, ProTableProps } from '@ant-design/pro-comp import { ProTable, } from '@ant-design/pro-components'; -// import { InputNumber } from 'antd'; import { AnyObject } from 'antd/es/_util/type'; +import { InputNumber } from 'antd'; export interface TimeTemplateTableProps extends ProTableProps { onItemBlur?: (value?: number | string, id?: any, record?: any) => void, @@ -15,7 +15,7 @@ const TimeTemplateTable = ( props: TimeTemplateTableProps ) => { const { - // onItemBlur, + onItemBlur, } = props @@ -37,17 +37,22 @@ const TimeTemplateTable = ( // title: '算力占用', // dataIndex: 'powerOccupy', // }, - // { - // title: '配置路数', - // key: 'option', - // valueType: 'option', - // render: (_, record) => onItemBlur?.(e.target.value, record.id, record)} min={0} />, - // }, + { + title: '配置路数', + key: 'option', + valueType: 'option', + render: (_, record) => onItemBlur?.(e.target.value, record.id, record)} min={0} />, + }, ]; return ( columns={columns} + cardProps={{ + bodyStyle: { + padding: 0 + } + }} bordered scroll={{ y: 95 }} toolbar={undefined} diff --git a/packages/material/src/algorithmConfig/demo/basic.tsx b/packages/material/src/algorithmConfig/demo/basic.tsx index e80605b..6f1ace9 100644 --- a/packages/material/src/algorithmConfig/demo/basic.tsx +++ b/packages/material/src/algorithmConfig/demo/basic.tsx @@ -8,7 +8,7 @@ const algorithmTableDataSource: any = [] const timeTemplateDataSource: any = [] const boxListData: any[] | (() => any[]) = [] -for (let i = 0; i < 5; i += 1) { +for (let i = 0; i < 100; i += 1) { algorithmTableDataSource.push({ id: String(i), templateName: '算法模板' + (i + 1), diff --git a/packages/meta/CHANGELOG.md b/packages/meta/CHANGELOG.md index 2ea5951..3106c80 100644 --- a/packages/meta/CHANGELOG.md +++ b/packages/meta/CHANGELOG.md @@ -1,5 +1,22 @@ # @zhst/utils +## 0.16.4 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + - @zhst/hooks@0.10.4 + - @zhst/meta@0.16.4 + +## 0.16.3 + +### Patch Changes + +- @zhst/func@0.11.3 +- @zhst/hooks@0.10.3 +- @zhst/meta@0.16.3 + ## 0.16.2 ### Patch Changes diff --git a/packages/meta/package.json b/packages/meta/package.json index 07c20d8..ef1e3ae 100644 --- a/packages/meta/package.json +++ b/packages/meta/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/meta", - "version": "0.16.2", + "version": "0.16.4", "description": "原子组件", "keywords": [ "meta", diff --git a/packages/request/.fatherrc.ts b/packages/request/.fatherrc.ts index 9e3a0ef..447d06b 100644 --- a/packages/request/.fatherrc.ts +++ b/packages/request/.fatherrc.ts @@ -2,6 +2,12 @@ import { defineConfig } from 'father'; export default defineConfig({ // more father config: https://github.com/umijs/father/blob/master/docs/config.md - esm: { output: 'es' }, - cjs: { output: 'lib' }, + esm: { + output: 'es', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, + cjs: { + output: 'lib', + ignores: ['**/demo/*', 'src/**/demo/*'] + }, }); diff --git a/packages/request/CHANGELOG.md b/packages/request/CHANGELOG.md index 9fc110e..aa7f206 100644 --- a/packages/request/CHANGELOG.md +++ b/packages/request/CHANGELOG.md @@ -1,5 +1,19 @@ # @zhst/request +## 0.12.4 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + +## 0.12.3 + +### Patch Changes + +- zhst/request: 后端接口返回数据变更,兼容 + - @zhst/func@0.11.3 + ## 0.12.2 ### Patch Changes diff --git a/packages/request/es/index.js b/packages/request/es/index.js index 353d677..382b49e 100644 --- a/packages/request/es/index.js +++ b/packages/request/es/index.js @@ -17,46 +17,9 @@ export var reqConfig = function reqConfig(config) { errorConfig: { // @ts-ignore errorHandler: function errorHandler(error) { - var _ref2 = (error === null || error === void 0 ? void 0 : error.request) || {}, - status = _ref2.status; - if ([403, 401].includes(status)) { - message.error('登录过期,请重新登录'); - onError === null || onError === void 0 || onError(error); - return; - } - // if (opts?.skipErrorHandler) throw error - // try { - // const { res } = ctx; - // const d = await res.text(); - - // if (res.status === 401 && store.user.isLogin) { - // store.user.resetLoginState(); - // message.warning('登录过期,请重新登录!'); - // return; - // } - // const isEmptyRes = d === '' || d.replace(/\s/g,"")=== 'tokenisinvalid'; //有些后端接口成功会返回空 做下兼容 - // const body = !isEmptyRes ? JSON.parse(d || '{}') : d; - // const sessionCode = sessionStorage.getItem('zhst_errcode') || '{}' - // const ERROR_CODE = JSON.parse(sessionCode); - - // if (Number(res.status) === 200) { - // ctx.res = body; - // } else { - // // 先判断Grpc-Metadata-Errorx-Message - // let errMsg = ERROR_CODE[body.code]?.value || body.message || '您的网络发生异常,无法连接服务器' - // toast && message.error(errMsg || body); - // ctx.res = { - // code: body.code, - // message: errMsg - // }; - // } - - // } catch (error) { - // if (get(error, 'type') !== 'CustomError') { - // toast && message.error('您的网络发生异常,无法连接服务器'); - // } - // throw error; - // } + // const { status } = error?.request || {} + onError === null || onError === void 0 || onError(error); + message.error('网络异常'); }, // @ts-ignore errorThrower: function errorThrower(res) { @@ -86,21 +49,27 @@ export var reqConfig = function reqConfig(config) { // if (response.status !== 200) { // throw Error(JSON.stringify(response.data)); // } - var _ref3 = (response === null || response === void 0 ? void 0 : response.data) || {}, - code = _ref3.code; - if (showMsg && code !== 200) { - message.error(response.data.message || '请求失败!'); - return null; + var _ref2 = (response === null || response === void 0 ? void 0 : response.data) || {}, + code = _ref2.code; + if ([403, 401].includes(code)) { + message.error('登录过期,请重新登录'); + onError === null || onError === void 0 || onError(response === null || response === void 0 ? void 0 : response.data); + return {}; } - return response.data; + if (showMsg && code !== 200) { + var _response$data; + message.error(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.message) || '请求失败!'); + return {}; + } + return response.data || {}; }, function (error) { var _error$response; - var _ref4 = ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || {}, - code = _ref4.code; + var _ref3 = ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) || {}, + code = _ref3.code; if (showMsg && code !== 200) { message.error(error.response.data.message || '请求失败!'); } - return Promise.reject(error); + return Promise.reject(error.response); }]] }, config); }; \ No newline at end of file diff --git a/packages/request/lib/index.js b/packages/request/lib/index.js index d304086..d7bf16e 100644 --- a/packages/request/lib/index.js +++ b/packages/request/lib/index.js @@ -35,12 +35,8 @@ var reqConfig = (config) => { errorConfig: { // @ts-ignore errorHandler(error) { - const { status } = (error == null ? void 0 : error.request) || {}; - if ([403, 401].includes(status)) { - import_antd.message.error("登录过期,请重新登录"); - onError == null ? void 0 : onError(error); - return; - } + onError == null ? void 0 : onError(error); + import_antd.message.error("网络异常"); }, // @ts-ignore errorThrower(res) { @@ -73,12 +69,18 @@ var reqConfig = (config) => { // 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理 [ (response) => { + var _a; const { code } = (response == null ? void 0 : response.data) || {}; - if (showMsg && code !== 200) { - import_antd.message.error(response.data.message || "请求失败!"); - return null; + if ([403, 401].includes(code)) { + import_antd.message.error("登录过期,请重新登录"); + onError == null ? void 0 : onError(response == null ? void 0 : response.data); + return {}; } - return response.data; + if (showMsg && code !== 200) { + import_antd.message.error(((_a = response.data) == null ? void 0 : _a.message) || "请求失败!"); + return {}; + } + return response.data || {}; }, (error) => { var _a; @@ -86,7 +88,7 @@ var reqConfig = (config) => { if (showMsg && code !== 200) { import_antd.message.error(error.response.data.message || "请求失败!"); } - return Promise.reject(error); + return Promise.reject(error.response); } ] ], diff --git a/packages/request/package.json b/packages/request/package.json index 4da708f..27ba939 100644 --- a/packages/request/package.json +++ b/packages/request/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/request", - "version": "0.12.2", + "version": "0.12.4", "description": "请求库", "keywords": [ "request", diff --git a/packages/request/src/code.ts b/packages/request/src/code.ts new file mode 100644 index 0000000..b16e0c7 --- /dev/null +++ b/packages/request/src/code.ts @@ -0,0 +1,47 @@ +enum CommonErrCode { + UNKNOW_ERROR = 0, // 未知错误, proto编译必须定义,禁止使用此值 + STATUS_OK = 200, // 正常, 目前只是为了展示警告信息,配合errLevel使用 + SERVER_COMMON_ERROR = 201, // 服务通用错误 + REUQEST_PARAM_ERROR = 202, // 参数请求错误 + TOKEN_EXPIRE_ERROR = 203, // 令牌无效 + TOKEN_GENERATE_ERROR = 204, // 生成令牌失败 + DB_ERROR = 205, // 数据库错误 + CONTEXT_DONE = 206, // context done + STREAM_SEND_ERROR = 207, //流式接口发送失败 + STREAM_RECV_ERROR = 208, //流式接口接收失败 + TIME_OUT = 209, //超时 + INTERNAL_ERROR = 210, //服务内部错误 + REDIS_ERROR = 211, //缓存数据库错误 + + // user-manager + USER_NOT_EXIST = 550, // 用户不存在 + USER_PASSWORD_INCORRECT = 551, // 用户名密码错误 + USER_DISABLED = 552, // 用户不可用 + USER_TOKEN_MISMATCH = 553, // 登录信息不匹配 + USER_HAVE_NO_ACCESS = 554, // 没有操作权限 + USER_INFO_NOT_FOUND = 555, // 获取用户信息失败 + USER_LOGIN_FAILED = 556, // 登陆失败 + USER_LOGIN_EXPIRED = 557, // 登录过期 + USER_INFO_NOT_COMPLETED = 558, // 用户信息不完整 + USER_PASSWORD_NOT_STRONG = 559, // 密码强度不足 + USER_NAME_NOT_UNIQUE = 560, // 用户名已存在 + USER_COUNT_ACHIEVE_LIMIT = 561, // 用户数达到上限 + USER_WITHOUT_PERMISSION = 562, // 用户无权限 + USER_SET_REDLOCK_FAIL = 563, // 用户获取操作权限失败 + USER_ISSUED_STATUS_NO_ISSUED = 564, // 未授权 + USER_ISSUED_STATUS_EXPIRY = 565, // 过期 + USER_ISSUED_STATUS_INVALID = 566, // 非法授权 + USER_ISSUED_STATUS_UNKNOW = 567, // 未知 + USER_NAME_CANT_MOD = 568, // 用户名不可修改 + USER_ORG_NAME_NOT_UNIQUE = 569, // 组织名已存在 + USER_ORG_NOT_EXIST = 570, // 组织不存在 + USER_ORG_INFO_NOT_FOUND = 571, // 获取组织信息失败 + USER_ROLE_NAME_NOT_UNIQUE = 580, // 角色名已存在 + USER_ROLE_NOT_EXIST = 581, // 角色不存在 + USER_ROLE_INFO_NOT_FOUND = 582, // 获取角色信息失败 + USER_ROLE_HAVE_USER = 583, // 角色下有用户绑定 + + // solution_manager 2000 + IMPORT_SOLUTION_CONFIG_EXCEPTION = 2001, // 算法导入配置文件异常 + IMPORT_SOLUTION_MODEL_EX +} diff --git a/packages/request/src/index.tsx b/packages/request/src/index.tsx index 2c6e73d..7a4e066 100644 --- a/packages/request/src/index.tsx +++ b/packages/request/src/index.tsx @@ -1,14 +1,25 @@ import { message } from 'antd' export interface ReqConfigProps { + /** + * 超时时间 + */ timeout?: number baseURL?: string errorConfig?: { errorHandler?: (error: any, opts: any) => void errorThrower?: (err: any) => void } + /** + * 权限校验的头部信息 + */ authorization?: string showMsg?: boolean + /** + * 报错捕捉 + * @param error 报错信息 + * @returns + */ onError: (error?: any) => void } @@ -24,46 +35,10 @@ export const reqConfig = (config: ReqConfigProps) => { baseURL: location.origin, errorConfig: { // @ts-ignore - errorHandler(error: any) { - const { status } = error?.request || {} - if ([403,401].includes(status)) { - message.error('登录过期,请重新登录') - onError?.(error) - return - } - // if (opts?.skipErrorHandler) throw error - // try { - // const { res } = ctx; - // const d = await res.text(); - - // if (res.status === 401 && store.user.isLogin) { - // store.user.resetLoginState(); - // message.warning('登录过期,请重新登录!'); - // return; - // } - // const isEmptyRes = d === '' || d.replace(/\s/g,"")=== 'tokenisinvalid'; //有些后端接口成功会返回空 做下兼容 - // const body = !isEmptyRes ? JSON.parse(d || '{}') : d; - // const sessionCode = sessionStorage.getItem('zhst_errcode') || '{}' - // const ERROR_CODE = JSON.parse(sessionCode); - - // if (Number(res.status) === 200) { - // ctx.res = body; - // } else { - // // 先判断Grpc-Metadata-Errorx-Message - // let errMsg = ERROR_CODE[body.code]?.value || body.message || '您的网络发生异常,无法连接服务器' - // toast && message.error(errMsg || body); - // ctx.res = { - // code: body.code, - // message: errMsg - // }; - // } - - // } catch (error) { - // if (get(error, 'type') !== 'CustomError') { - // toast && message.error('您的网络发生异常,无法连接服务器'); - // } - // throw error; - // } + errorHandler(error) { + // const { status } = error?.request || {} + onError?.(error) + message.error('网络异常') }, // @ts-ignore errorThrower(res) { @@ -102,11 +77,17 @@ export const reqConfig = (config: ReqConfigProps) => { // } const { code } = response?.data || {} - if (showMsg && code !== 200) { - message.error(response.data.message || '请求失败!') - return null + if ([403,401, 203].includes(code)) { + message.error('登录过期,请重新登录') + onError?.(response?.data) + return {} } - return response.data; + + if (showMsg && code !== 200) { + message.error(response.data?.message || '请求失败!') + return {} + } + return response.data || {}; }, (error: any) => { const { code } = error.response?.data || {} @@ -114,7 +95,7 @@ export const reqConfig = (config: ReqConfigProps) => { if (showMsg && code !== 200) { message.error(error.response.data.message || '请求失败!') } - return Promise.reject(error); + return Promise.reject(error.response); }, ], ], diff --git a/packages/slave/CHANGELOG.md b/packages/slave/CHANGELOG.md index 62d8fdf..fafbf28 100644 --- a/packages/slave/CHANGELOG.md +++ b/packages/slave/CHANGELOG.md @@ -1,5 +1,18 @@ # @zhst/slave +## 0.7.4 + +### Patch Changes + +- Updated dependencies + - @zhst/func@0.12.0 + +## 0.7.3 + +### Patch Changes + +- @zhst/func@0.11.3 + ## 0.7.2 ### Patch Changes diff --git a/packages/slave/es/index.js b/packages/slave/es/index.js index 7c3cdc4..cc46172 100644 --- a/packages/slave/es/index.js +++ b/packages/slave/es/index.js @@ -22,7 +22,7 @@ var Slave = /*#__PURE__*/function () { key: "init", value: function () { var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(opt) { - var _opt$jumpToLogin, jumpToLogin, jumpUrl, tokenKey, _opt$showMsg, showMsg, msgText, from, to, currentUrl, currentJumpUrl, _token, _fromUrl, _toUrl; + var _opt$jumpToLogin, jumpToLogin, jumpUrl, tokenKey, _opt$showMsg, showMsg, msgText, from, to, currentUrl, currentJumpUrl, _token, isLogin; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: @@ -33,27 +33,23 @@ var Slave = /*#__PURE__*/function () { currentJumpUrl = new URL(jumpUrl); _token = currentUrl.searchParams.get(tokenKey || 'token') || this.getToken(); this.setToken(_token); - _fromUrl = from || location.origin + location.pathname; - this.checkUrl(_fromUrl, 'from'); - - // 判段from字段是否为链接 - if (!currentJumpUrl.searchParams.get('from')) { - currentJumpUrl.searchParams.set('from', _fromUrl); - } - _toUrl = to || location.origin + location.pathname; - this.checkUrl(_toUrl, 'to'); - if (!currentJumpUrl.searchParams.get('to')) { - currentJumpUrl.searchParams.set('to', _toUrl); - } - - // 判断当前登录环境 - this.checkEnv({ - showMsg: showMsg, - msgText: msgText + this._setUrlKey({ + targetKey: 'from', + targetUrl: from, + jumpUrl: currentJumpUrl + }); + this._setUrlKey({ + targetKey: 'to', + targetUrl: to, + jumpUrl: currentJumpUrl }); - // 是否执行跳转页面 - if (jumpToLogin && jumpUrl && !_token) { + // 判断当前登录环境 + isLogin = this.checkEnv({ + showMsg: showMsg, + msgText: msgText + }); // 是否执行跳转页面 + if (jumpToLogin && !isLogin) { // 判断是否为同一个域,采用不同的跳转方式 // 同一个域名下 if (currentJumpUrl.origin === location.origin) { @@ -62,7 +58,7 @@ var Slave = /*#__PURE__*/function () { location.href = currentJumpUrl.href; } } - case 14: + case 10: case "end": return _context.stop(); } @@ -72,7 +68,28 @@ var Slave = /*#__PURE__*/function () { return _init.apply(this, arguments); } return init; - }() // 判端是否登录 + }() // 设置 URL 中的值 + /** + * @param opt targetUrl 目标链接,目标链接的 key 值,sourceUrl: 需要添加参数的链接 + */ + }, { + key: "_setUrlKey", + value: function _setUrlKey(opt) { + var targetUrl = opt.targetUrl, + targetKey = opt.targetKey, + jumpUrl = opt.jumpUrl; + var _targetUrl = targetUrl || location.origin + location.pathname; + this.checkUrl(_targetUrl, targetKey); + if (!jumpUrl.searchParams.get(targetKey)) { + jumpUrl.searchParams.set(targetKey, _targetUrl); + } + } + + /** + * 判端是否登录 + * @param _opt showMsg 是否提示 | msgText 提示文案 + * @returns boolean + */ }, { key: "checkEnv", value: function checkEnv(_opt) { @@ -103,18 +120,21 @@ var Slave = /*#__PURE__*/function () { }, { key: "setToken", value: function setToken(val) { - val && localStorage.setItem(this.authTokenDefine, val); + var tokenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.authTokenDefine; + val && localStorage.setItem(tokenKey, val); } }, { key: "removeToken", value: function removeToken(cb) { - localStorage.removeItem(this.authTokenDefine); + var tokenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.authTokenDefine; + localStorage.removeItem(tokenKey); cb === null || cb === void 0 || cb(); } }, { key: "getToken", value: function getToken() { - return localStorage.getItem(this.authTokenDefine); + var tokenKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.authTokenDefine; + return localStorage.getItem(tokenKey); } }]); return Slave; diff --git a/packages/slave/lib/index.js b/packages/slave/lib/index.js index 2bee0f6..9204e78 100644 --- a/packages/slave/lib/index.js +++ b/packages/slave/lib/index.js @@ -38,24 +38,25 @@ var Slave = class { msgText, from, to + // force } = opt; this.checkUrl(jumpUrl, "jumpUrl"); let currentUrl = new URL(location.href); let currentJumpUrl = new URL(jumpUrl); let _token = currentUrl.searchParams.get(tokenKey || "token") || this.getToken(); this.setToken(_token); - let _fromUrl = from || location.origin + location.pathname; - this.checkUrl(_fromUrl, "from"); - if (!currentJumpUrl.searchParams.get("from")) { - currentJumpUrl.searchParams.set("from", _fromUrl); - } - let _toUrl = to || location.origin + location.pathname; - this.checkUrl(_toUrl, "to"); - if (!currentJumpUrl.searchParams.get("to")) { - currentJumpUrl.searchParams.set("to", _toUrl); - } - this.checkEnv({ showMsg, msgText }); - if (jumpToLogin && jumpUrl && !_token) { + this._setUrlKey({ + targetKey: "from", + targetUrl: from, + jumpUrl: currentJumpUrl + }); + this._setUrlKey({ + targetKey: "to", + targetUrl: to, + jumpUrl: currentJumpUrl + }); + const isLogin = this.checkEnv({ showMsg, msgText }); + if (jumpToLogin && !isLogin) { if (currentJumpUrl.origin === location.origin) { history.pushState("", "", currentJumpUrl.href); } else { @@ -63,7 +64,27 @@ var Slave = class { } } } - // 判端是否登录 + // 设置 URL 中的值 + /** + * @param opt targetUrl 目标链接,目标链接的 key 值,sourceUrl: 需要添加参数的链接 + */ + _setUrlKey(opt) { + const { + targetUrl, + targetKey, + jumpUrl + } = opt; + let _targetUrl = targetUrl || location.origin + location.pathname; + this.checkUrl(_targetUrl, targetKey); + if (!jumpUrl.searchParams.get(targetKey)) { + jumpUrl.searchParams.set(targetKey, _targetUrl); + } + } + /** + * 判端是否登录 + * @param _opt showMsg 是否提示 | msgText 提示文案 + * @returns boolean + */ checkEnv(_opt) { const _token = this.getToken() || String(this.getToken()); if (!_token && _token !== "null" && _opt.showMsg) { @@ -83,15 +104,15 @@ var Slave = class { this.removeToken(); location.replace(location.origin + location.pathname); } - setToken(val) { - val && localStorage.setItem(this.authTokenDefine, val); + setToken(val, tokenKey = this.authTokenDefine) { + val && localStorage.setItem(tokenKey, val); } - removeToken(cb) { - localStorage.removeItem(this.authTokenDefine); + removeToken(cb, tokenKey = this.authTokenDefine) { + localStorage.removeItem(tokenKey); cb == null ? void 0 : cb(); } - getToken() { - return localStorage.getItem(this.authTokenDefine); + getToken(tokenKey = this.authTokenDefine) { + return localStorage.getItem(tokenKey); } }; var src_default = new Slave(); diff --git a/packages/slave/package.json b/packages/slave/package.json index 9e3c789..865cc59 100644 --- a/packages/slave/package.json +++ b/packages/slave/package.json @@ -1,6 +1,6 @@ { "name": "@zhst/slave", - "version": "0.7.2", + "version": "0.7.4", "description": "微前端子应用方法库", "keywords": [ "slave", diff --git a/packages/slave/src/index.tsx b/packages/slave/src/index.tsx index e0277ba..d938644 100644 --- a/packages/slave/src/index.tsx +++ b/packages/slave/src/index.tsx @@ -14,6 +14,10 @@ export interface ISlaveConfig { * 自定义token键名称 */ tokenKey?: string; + /** + * 强制跳转; + */ + force?: boolean; showMsg?: boolean; msgText?: string; from?: string; @@ -35,7 +39,8 @@ class Slave { showMsg = true, msgText, from, - to + to, + // force } = opt this.checkUrl(jumpUrl, 'jumpUrl') // 当前链接 @@ -58,10 +63,10 @@ class Slave { }) // 判断当前登录环境 - this.checkEnv({ showMsg, msgText }) + const isLogin = this.checkEnv({ showMsg, msgText }) // 是否执行跳转页面 - if (jumpToLogin && jumpUrl && !_token) { + if (jumpToLogin && !isLogin) { // 判断是否为同一个域,采用不同的跳转方式 // 同一个域名下 if (currentJumpUrl.origin === location.origin) { @@ -90,7 +95,11 @@ class Slave { } } - // 判端是否登录 + /** + * 判端是否登录 + * @param _opt showMsg 是否提示 | msgText 提示文案 + * @returns boolean + */ checkEnv(_opt: { showMsg: boolean, msgText?: string }): boolean { const _token = this.getToken() || String(this.getToken()) if (!_token && _token !== 'null' && _opt.showMsg) {