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

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

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