feat(zhst/func): 添加pxtoRem方法
This commit is contained in:
parent
9d4eab8c9e
commit
a47aa0c431
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/biz",
|
||||
"version": "0.18.5",
|
||||
"version": "0.18.8",
|
||||
"description": "业务库",
|
||||
"keywords": [
|
||||
"business",
|
||||
|
@ -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'
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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 },
|
||||
],
|
||||
|
@ -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/*']
|
||||
},
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -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;
|
@ -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(' ');
|
||||
};
|
@ -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;
|
@ -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
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/func",
|
||||
"version": "0.11.2",
|
||||
"version": "0.12.0",
|
||||
"description": "函数合集",
|
||||
"keywords": [
|
||||
"hooks"
|
||||
|
25
packages/func/src/string/demo/pxTorem.tsx
Normal file
25
packages/func/src/string/demo/pxTorem.tsx
Normal file
@ -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<any>(null)
|
||||
|
||||
const handleChange = (e) => {
|
||||
const value = pxToRem(e.target.value)
|
||||
setOutPutVal(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Input onChange={handleChange} />
|
||||
<p>输出:{outputVal}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default demo
|
131
packages/func/src/string/demo/scale.temp.ts
Normal file
131
packages/func/src/string/demo/scale.temp.ts
Normal file
@ -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('<meta name="viewport" content=""/>');
|
||||
|
||||
|
||||
//监听页面是否发生改变
|
||||
$(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 + "%",
|
||||
});
|
||||
}
|
||||
})();
|
||||
}
|
@ -21,3 +21,4 @@ const value3 = getValueByUrl('a', 'a=123&token=asdfasdfsdf')
|
||||
```
|
||||
|
||||
<code src="./demo/getValueByUrl.tsx">调试台</code>
|
||||
<code src="./demo/pxTorem.tsx">px 转 rem</code>
|
||||
|
@ -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(' ')
|
||||
}
|
||||
|
151
packages/func/src/utils/autoSize.ts
Normal file
151
packages/func/src/utils/autoSize.ts
Normal file
@ -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
|
@ -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/*']
|
||||
},
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/hooks",
|
||||
"version": "0.10.2",
|
||||
"version": "0.10.4",
|
||||
"description": "hooks合集",
|
||||
"keywords": [
|
||||
"hooks"
|
||||
|
@ -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/*']
|
||||
},
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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<any>['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<AlgorithmConfigRef, AlgorithmConfigProps>((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<AlgorithmConfigRef, AlgorithmConfigProps>((pr
|
||||
|
||||
return (
|
||||
<Flex style={{ border: `1px solid ${token.colorBorder}`, backgroundColor: token.colorBgBase }}>
|
||||
<div title={title} style={{ width: '13.9%' }}>
|
||||
<div title={title} style={{ position: 'relative', width: '13.9%' }}>
|
||||
<Title>{title}</Title>
|
||||
<div style={{ borderTop: `1px solid ${token.colorBorder}` }}>
|
||||
<div style={{ paddingBottom: '36px', height: '612px', overflowY: 'scroll', boxSizing: "border-box", borderTop: `1px solid ${token.colorBorder}` }}>
|
||||
{boxList.map(item => {
|
||||
return (
|
||||
<p
|
||||
key={item.id}
|
||||
onClick={() => 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<AlgorithmConfigRef, AlgorithmConfigProps>((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}</p>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
{showLoadMoreButton && (
|
||||
<div style={{ width: '100%', padding: '6px', position: 'absolute', left: '0', bottom: '0', boxSizing: 'border-box' }}>
|
||||
{customLoadMoreButton || <Button onClick={onLoadMoreButtonClick} block>加载更多</Button>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ boxSizing: 'border-box', width: '46.3%', textAlign: 'center', borderLeft: `1px solid ${token.colorBorder}`, borderRight: `1px solid ${token.colorBorder}` }}>
|
||||
{/* 单个配置 */}
|
||||
@ -117,12 +154,14 @@ const AlgorithmConfig = forwardRef<AlgorithmConfigRef, AlgorithmConfigProps>((pr
|
||||
fallback={ErrorImage}
|
||||
/>
|
||||
<h2>请进行批量配置</h2>
|
||||
<ul style={{ display: 'inline-block', paddingLeft: 0, width: '51.8%', listStyle: 'none', textAlign: 'left', color: token.colorTextLabel }}>
|
||||
<li>· 盒子批量配置仅支持同型号盒子;</li>
|
||||
<li>· 采取覆盖式更新,不保留原有配置,且预警检测框默认全屏范围;</li>
|
||||
<li>· 人流量统计默认检测线为屏幕中央横向线条,且箭头指向下方;</li>
|
||||
<li>· 优先选择拉流正常的摄像头。</li>
|
||||
</ul>
|
||||
{customBatchCenterContent || (
|
||||
<ul style={{ display: 'inline-block', paddingLeft: 0, width: '51.8%', listStyle: 'none', textAlign: 'left', color: token.colorTextLabel }}>
|
||||
<li>· 盒子批量配置仅支持同型号盒子;</li>
|
||||
<li>· 采取覆盖式更新,不保留原有配置,且预警检测框默认全屏范围;</li>
|
||||
<li>· 人流量统计默认检测线为屏幕中央横向线条,且箭头指向下方;</li>
|
||||
<li>· 优先选择拉流正常的摄像头。</li>
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -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= <DataSource extends AnyObject = AnyObject>(
|
||||
0: { text: '白天' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '算力占用',
|
||||
dataIndex: 'powerOccupy',
|
||||
},
|
||||
// {
|
||||
// title: '算力占用',
|
||||
// dataIndex: 'powerOccupy',
|
||||
// },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'option',
|
||||
@ -88,29 +88,34 @@ const AlgorithmTable= <DataSource extends AnyObject = AnyObject>(
|
||||
];
|
||||
|
||||
return (
|
||||
<ProTable<DataSource>
|
||||
columns={columns}
|
||||
bordered
|
||||
scroll={{ y: 240, x: 600 }}
|
||||
dataSource={[]}
|
||||
headerTitle={(
|
||||
<Space size={16}>
|
||||
<Select
|
||||
value={selectedKey}
|
||||
style={{ width: 320 }}
|
||||
onChange={onSortSelect}
|
||||
options={sortList}
|
||||
/>
|
||||
<PlusCircleFilled onClick={() => onAddAlgorithm?.(selectedKey)} style={{ fontSize: '24px', color: token.colorPrimary, cursor: 'pointer' }} />
|
||||
</Space>
|
||||
)}
|
||||
toolbar={undefined}
|
||||
rowKey="id"
|
||||
search={false}
|
||||
options={false}
|
||||
pagination={false}
|
||||
{...props}
|
||||
/>
|
||||
<div>
|
||||
<Space size={16} style={{ marginBottom: '12px' }}>
|
||||
<Select
|
||||
value={selectedKey}
|
||||
style={{ width: 320 }}
|
||||
onChange={onSortSelect}
|
||||
options={sortList}
|
||||
/>
|
||||
<PlusCircleFilled onClick={() => onAddAlgorithm?.(selectedKey)} style={{ fontSize: '24px', color: token.colorPrimary, cursor: 'pointer' }} />
|
||||
</Space>
|
||||
<ProTable<DataSource>
|
||||
columns={columns}
|
||||
bordered
|
||||
scroll={{ y: 240, x: 600 }}
|
||||
dataSource={[]}
|
||||
cardProps={{
|
||||
bodyStyle: {
|
||||
padding: 0
|
||||
}
|
||||
}}
|
||||
toolbar={undefined}
|
||||
rowKey="id"
|
||||
search={false}
|
||||
options={false}
|
||||
pagination={false}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -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<DataSource, Params extends ParamsType = ParamsType, ValueType = "text"> extends ProTableProps<DataSource, Params, ValueType> {
|
||||
onItemBlur?: (value?: number | string, id?: any, record?: any) => void,
|
||||
@ -15,7 +15,7 @@ const TimeTemplateTable = <DataSource extends AnyObject = AnyObject>(
|
||||
props: TimeTemplateTableProps<DataSource, ParamsType, 'text'>
|
||||
) => {
|
||||
const {
|
||||
// onItemBlur,
|
||||
onItemBlur,
|
||||
} = props
|
||||
|
||||
|
||||
@ -37,17 +37,22 @@ const TimeTemplateTable = <DataSource extends AnyObject = AnyObject>(
|
||||
// title: '算力占用',
|
||||
// dataIndex: 'powerOccupy',
|
||||
// },
|
||||
// {
|
||||
// title: '配置路数',
|
||||
// key: 'option',
|
||||
// valueType: 'option',
|
||||
// render: (_, record) => <InputNumber value={record.lineNum} onBlur={e => onItemBlur?.(e.target.value, record.id, record)} min={0} />,
|
||||
// },
|
||||
{
|
||||
title: '配置路数',
|
||||
key: 'option',
|
||||
valueType: 'option',
|
||||
render: (_, record) => <InputNumber value={record.lineNum} onBlur={e => onItemBlur?.(e.target.value, record.id, record)} min={0} />,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<ProTable<DataSource>
|
||||
columns={columns}
|
||||
cardProps={{
|
||||
bodyStyle: {
|
||||
padding: 0
|
||||
}
|
||||
}}
|
||||
bordered
|
||||
scroll={{ y: 95 }}
|
||||
toolbar={undefined}
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/meta",
|
||||
"version": "0.16.2",
|
||||
"version": "0.16.4",
|
||||
"description": "原子组件",
|
||||
"keywords": [
|
||||
"meta",
|
||||
|
@ -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/*']
|
||||
},
|
||||
});
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
};
|
@ -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);
|
||||
}
|
||||
]
|
||||
],
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/request",
|
||||
"version": "0.12.2",
|
||||
"version": "0.12.4",
|
||||
"description": "请求库",
|
||||
"keywords": [
|
||||
"request",
|
||||
|
47
packages/request/src/code.ts
Normal file
47
packages/request/src/code.ts
Normal file
@ -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
|
||||
}
|
@ -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);
|
||||
},
|
||||
],
|
||||
],
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zhst/slave",
|
||||
"version": "0.7.2",
|
||||
"version": "0.7.4",
|
||||
"description": "微前端子应用方法库",
|
||||
"keywords": [
|
||||
"slave",
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user