提交 e46f2924 编写于 作者: 张平川's avatar 张平川

feat: 新增输入框xss文本过滤功能

上级 c31751e6
......@@ -35,7 +35,8 @@
"vite-plugin-style-import": "1.4.1",
"vue": "^2.7.15",
"vue-router": "^3.6.5",
"vue-text-format": "^3.1.2"
"vue-text-format": "^3.1.2",
"xss": "^1.0.15"
},
"devDependencies": {
"@commitlint/cli": "^17.3.0",
......
......@@ -6,6 +6,7 @@ import {
useNamespace,
} from '@ibiz-template/vue-util';
import '@ibiz-template/theme/style/components/editor/ibiz-input/ibiz-input.scss';
import xss from 'xss';
const fomatFloat = function (value: number, n: number) {
const f = value;
......@@ -74,6 +75,19 @@ export const IBizInput = defineComponent({
}
const currentVal = ref<string>('');
const getInputValue = (value: string | number) => {
if (type.value === 'number' || !ibiz.config.enableXSS) {
return value;
}
const result = xss(value as string);
if (result !== value) {
currentVal.value = result;
inputRef.value?.setCurrentValue?.(result);
ibiz.message.warning('输入值存在不规范格式,已自动调整!');
}
return result;
};
watch(
() => props.value,
(newVal, oldVal) => {
......@@ -96,7 +110,7 @@ export const IBizInput = defineComponent({
(e: IData) => {
// 拦截掉blur触发后change
if (blurCacheValue !== e.target.value) {
emit('change', e.target.value);
emit('change', getInputValue(e.target.value));
}
blurCacheValue = undefined;
isDebounce = false;
......@@ -156,7 +170,7 @@ export const IBizInput = defineComponent({
inputRef.value?.setCurrentValue?.(number);
emit('change', number);
} else {
emit('change', blurCacheValue);
emit('change', getInputValue(blurCacheValue as string));
}
};
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册