|
|
|
@ -20,44 +20,34 @@
|
|
|
|
|
</a> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
|
<script lang="ts"> |
|
|
|
|
import { ref, defineComponent } from 'vue' |
|
|
|
|
<script lang="ts" setup name="RuleProps"> |
|
|
|
|
import { ref } from 'vue' |
|
|
|
|
import { remove } from '../../../utils' |
|
|
|
|
import { useFormDesignState } from '../../../hooks/useFormDesignState' |
|
|
|
|
import { isArray } from 'lodash-es' |
|
|
|
|
import { Form, FormItem, AutoComplete, Input } from 'ant-design-vue' |
|
|
|
|
import Icon from '@/components/Icon' |
|
|
|
|
import { Icon } from '@/components/Icon' |
|
|
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
|
name: 'RuleProps', |
|
|
|
|
components: { |
|
|
|
|
Form, |
|
|
|
|
FormItem, |
|
|
|
|
AutoComplete, |
|
|
|
|
Input, |
|
|
|
|
Icon |
|
|
|
|
}, |
|
|
|
|
setup() { |
|
|
|
|
// 获取祖先组件的状态 |
|
|
|
|
const { formConfig } = useFormDesignState() |
|
|
|
|
// 抽离 currentItem |
|
|
|
|
/** |
|
|
|
|
// 获取祖先组件的状态 |
|
|
|
|
const { formConfig } = useFormDesignState() |
|
|
|
|
// 抽离 currentItem |
|
|
|
|
/** |
|
|
|
|
* 添加正则校验,判断当前组件的rules是不是数组,如果不是数组,使用set方法重置成数组,然后添加正则校验 |
|
|
|
|
*/ |
|
|
|
|
const addRules = () => { |
|
|
|
|
const addRules = () => { |
|
|
|
|
if (!isArray(formConfig.value.currentItem!.rules)) formConfig.value.currentItem!['rules'] = [] |
|
|
|
|
formConfig.value.currentItem!.rules?.push({ pattern: '', message: '' }) |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 删除正则校验,当正则规则为0时,删除rules属性 |
|
|
|
|
* @param index {number} 需要删除的规则下标 |
|
|
|
|
*/ |
|
|
|
|
const removeRule = (index: number) => { |
|
|
|
|
const removeRule = (index: number) => { |
|
|
|
|
remove(formConfig.value.currentItem!.rules as Array<any>, index) |
|
|
|
|
if (formConfig.value.currentItem!.rules?.length === 0) delete formConfig.value.currentItem!['rules'] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const patternDataSource = ref([ |
|
|
|
|
const patternDataSource = ref([ |
|
|
|
|
{ |
|
|
|
|
value: '/^(?:(?:\\+|00)86)?1[3-9]\\d{9}$/', |
|
|
|
|
text: '手机号码' |
|
|
|
@ -125,13 +115,11 @@ export default defineComponent({
|
|
|
|
|
text: '车牌号(新能源)' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
value: |
|
|
|
|
'/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/', |
|
|
|
|
value: '/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/', |
|
|
|
|
text: '车牌号(非新能源)' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
value: |
|
|
|
|
'/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/', |
|
|
|
|
value: '/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/', |
|
|
|
|
text: '车牌号(新能源+非新能源)' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
@ -226,11 +214,7 @@ export default defineComponent({
|
|
|
|
|
value: '/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$/', |
|
|
|
|
text: 'email(支持中文邮箱)' |
|
|
|
|
} |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
return { addRules, removeRule, formConfig, patternDataSource } |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
]) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style lang="less" scoped> |
|
|
|
|