12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- export default {
- computed: {
-
- value() {
- const {
- text,
- mode,
- format,
- href
- } = this
-
- if (mode === 'price') {
-
- if (!/^\d+(\.\d+)?$/.test(text)) {
- uni.$u.error('金额模式下,text参数需要为金额格式');
- }
-
- if (uni.$u.test.func(format)) {
-
- return format(text)
- }
-
- return uni.$u.priceFormat(text, 2)
- } if (mode === 'date') {
-
- !uni.$u.test.date(text) && uni.$u.error('日期模式下,text参数需要为日期或时间戳格式')
-
- if (uni.$u.test.func(format)) {
-
- return format(text)
- } if (format) {
-
- return uni.$u.timeFormat(text, format)
- }
-
- return uni.$u.timeFormat(text, 'yyyy-mm-dd')
- } if (mode === 'phone') {
-
-
- if (uni.$u.test.func(format)) {
-
- return format(text)
- } if (format === 'encrypt') {
-
- return `${text.substr(0, 3)}****${text.substr(7)}`
- }
- return text
- } if (mode === 'name') {
-
- !(typeof (text) === 'string') && uni.$u.error('姓名模式下,text参数需要为字符串格式')
- if (uni.$u.test.func(format)) {
-
- return format(text)
- } if (format === 'encrypt') {
-
- return this.formatName(text)
- }
- return text
- } if (mode === 'link') {
-
- !uni.$u.test.url(href) && uni.$u.error('超链接模式下,href参数需要为URL格式')
- return text
- }
- return text
- }
- },
- methods: {
-
- formatName(name) {
- let value = ''
- if (name.length === 2) {
- value = name.substr(0, 1) + '*'
- } else if (name.length > 2) {
- let char = ''
- for (let i = 0, len = name.length - 2; i < len; i++) {
- char += '*'
- }
- value = name.substr(0, 1) + char + name.substr(-1, 1)
- } else {
- value = name
- }
- return value
- }
- }
- }
|