mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-06 23:25:06 +08:00
多模块重构 12:修改项目名字,按照新的规则
This commit is contained in:
120
yudao-ui-app-v1/uni_modules/uview-ui/components/u-text/props.js
Normal file
120
yudao-ui-app-v1/uni_modules/uview-ui/components/u-text/props.js
Normal file
@ -0,0 +1,120 @@
|
||||
export default {
|
||||
props: {
|
||||
// 主题颜色
|
||||
type: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.type
|
||||
},
|
||||
// 是否显示
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.show
|
||||
},
|
||||
// 显示的值
|
||||
text: {
|
||||
type: [String, Number],
|
||||
default: uni.$u.props.text.text
|
||||
},
|
||||
// 前置图标
|
||||
prefixIcon: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.prefixIcon
|
||||
},
|
||||
// 后置图标
|
||||
suffixIcon: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.suffixIcon
|
||||
},
|
||||
// 文本处理的匹配模式
|
||||
// text-普通文本,price-价格,phone-手机号,name-姓名,date-日期,link-超链接
|
||||
mode: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.mode
|
||||
},
|
||||
// mode=link下,配置的链接
|
||||
href: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.href
|
||||
},
|
||||
// 格式化规则
|
||||
format: {
|
||||
type: [String, Function],
|
||||
default: uni.$u.props.text.format
|
||||
},
|
||||
// mode=phone时,点击文本是否拨打电话
|
||||
call: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.call
|
||||
},
|
||||
// 是否对mode=phone|name类型文本进行脱敏,用*号替换部分文本
|
||||
encrypt: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.encrypt
|
||||
},
|
||||
// 小程序的打开方式
|
||||
openType: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.openType
|
||||
},
|
||||
// 是否粗体,默认normal
|
||||
bold: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.bold
|
||||
},
|
||||
// 是否块状
|
||||
block: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.block
|
||||
},
|
||||
// 文本显示的行数,如果设置,超出此行数,将会显示省略号
|
||||
lines: {
|
||||
type: [String, Number],
|
||||
default: uni.$u.props.text.lines
|
||||
},
|
||||
// 文本颜色
|
||||
color: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.color
|
||||
},
|
||||
// 字体大小
|
||||
size: {
|
||||
type: [String, Number],
|
||||
default: uni.$u.props.text.size
|
||||
},
|
||||
// 图标的样式
|
||||
iconStyle: {
|
||||
type: [Object, String],
|
||||
default: uni.$u.props.text.iconStyle
|
||||
},
|
||||
// 是否显示金额的千分位,mode=price时有效
|
||||
precision: {
|
||||
type: Boolean,
|
||||
default: uni.$u.props.text.precision
|
||||
},
|
||||
// 文字装饰,下划线,中划线等,可选值 none|underline|line-through
|
||||
decoration: {
|
||||
tepe: String,
|
||||
default: uni.$u.props.text.decoration
|
||||
},
|
||||
// 外边距,对象、字符串,数值形式均可
|
||||
margin: {
|
||||
type: [Object, String, Number],
|
||||
default: uni.$u.props.text.margin
|
||||
},
|
||||
// 文本行高
|
||||
lineHeight: {
|
||||
type: [String, Number],
|
||||
default: uni.$u.props.text.lineHeight
|
||||
},
|
||||
// 文本对齐方式,可选值left|center|right
|
||||
align: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.align
|
||||
},
|
||||
// 文字换行,可选值break-word|normal|anywhere
|
||||
wordWrap: {
|
||||
type: String,
|
||||
default: uni.$u.props.text.wordWrap
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,222 @@
|
||||
<template>
|
||||
<view
|
||||
class="u-text"
|
||||
:class="[]"
|
||||
v-if="show"
|
||||
:style="{
|
||||
margin: margin
|
||||
}"
|
||||
@tap="clickHandler"
|
||||
>
|
||||
<text
|
||||
class="u-text__price"
|
||||
v-if="mode === 'price'"
|
||||
:style="[valueStyle]"
|
||||
>¥</text>
|
||||
<view
|
||||
class="u-text__prefix-icon"
|
||||
v-if="prefixIcon"
|
||||
>
|
||||
<u-icon
|
||||
:name="prefixIcon"
|
||||
:customStyle="$u.addStyle(iconStyle)"
|
||||
></u-icon>
|
||||
</view>
|
||||
<u-link
|
||||
v-if="mode === 'link'"
|
||||
:text="value"
|
||||
:href="href"
|
||||
underLine
|
||||
></u-link>
|
||||
<template v-else-if="openType && isMp">
|
||||
<button
|
||||
class="u-reset-button u-text__value"
|
||||
:style="[valueStyle]"
|
||||
:data-index="index"
|
||||
:openType="openType"
|
||||
@getuserinfo="onGetUserInfo"
|
||||
@contact="onContact"
|
||||
@getphonenumber="onGetPhoneNumber"
|
||||
@error="onError"
|
||||
@launchapp="onLaunchApp"
|
||||
@opensetting="onOpenSetting"
|
||||
:lang="lang"
|
||||
:session-from="sessionFrom"
|
||||
:send-message-title="sendMessageTitle"
|
||||
:send-message-path="sendMessagePath"
|
||||
:send-message-img="sendMessageImg"
|
||||
:show-message-card="showMessageCard"
|
||||
:app-parameter="appParameter"
|
||||
>{{ value }}</button>
|
||||
</template>
|
||||
<text
|
||||
v-else
|
||||
class="u-text__value"
|
||||
:style="[valueStyle]"
|
||||
:class="[type && `u-text__value--${type}`, lines && `u-line-${lines}`]"
|
||||
>{{ value }}</text>
|
||||
<view
|
||||
class="u-text__suffix-icon"
|
||||
v-if="suffixIcon"
|
||||
>
|
||||
<u-icon
|
||||
:name="suffixIcon"
|
||||
:customStyle="$u.addStyle(iconStyle)"
|
||||
></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import value from './value.js'
|
||||
import button from '../../libs/mixin/button.js'
|
||||
import openType from '../../libs/mixin/openType.js'
|
||||
import props from './props.js';
|
||||
/**
|
||||
* Text 文本
|
||||
* @description 此组件集成了文本类在项目中的常用功能,包括状态,拨打电话,格式化日期,*替换,超链接...等功能。 您大可不必在使用特殊文本时自己定义,text组件几乎涵盖您能使用的大部分场景。
|
||||
* @tutorial https://www.uviewui.com/components/loading.html
|
||||
* @property {String} type 主题颜色
|
||||
* @property {Boolean} show 是否显示(默认 true )
|
||||
* @property {String | Number} text 显示的值
|
||||
* @property {String} prefixIcon 前置图标
|
||||
* @property {String} suffixIcon 后置图标
|
||||
* @property {String} mode 文本处理的匹配模式 text-普通文本,price-价格,phone-手机号,name-姓名,date-日期,link-超链接
|
||||
* @property {String} href mode=link下,配置的链接
|
||||
* @property {String | Function} format 格式化规则
|
||||
* @property {Boolean} call mode=phone时,点击文本是否拨打电话(默认 false )
|
||||
* @property {Boolean} encrypt 是否对mode=phone|name类型文本进行脱敏,用*号替换部分文本(默认 false )
|
||||
* @property {String} openType 小程序的打开方式
|
||||
* @property {Boolean} bold 是否粗体,默认normal(默认 false )
|
||||
* @property {Boolean} block 是否块状(默认 false )
|
||||
* @property {String | Number} lines 文本显示的行数,如果设置,超出此行数,将会显示省略号
|
||||
* @property {String} color 文本颜色(默认 '#303133' )
|
||||
* @property {String | Number} size 字体大小(默认 15 )
|
||||
* @property {Object | String} iconStyle 图标的样式 (默认 {fontSize: '15px'} )
|
||||
* @property {Boolean} precision 是否显示金额的千分位,mode=price时有效(默认 true )
|
||||
* @property {String} decoration 是否显示金额的千分位,mode=price时有效(默认 'none' )
|
||||
* @property {Object | String | Number} margin 外边距,对象、字符串,数值形式均可(默认 0 )
|
||||
* @property {String | Number} lineHeight 文本行高
|
||||
* @property {String} align 文本对齐方式,可选值left|center|right(默认 'left' )
|
||||
* @property {String} wordWrap 文字换行,可选值break-word|normal|anywhere(默认 'normal' )
|
||||
* @event {Function} click 点击触发事件
|
||||
* @example <u--text text="我用十年青春,赴你最后之约"></u--text>
|
||||
*/
|
||||
export default {
|
||||
name: 'u--text',
|
||||
// #ifdef MP
|
||||
mixins: [uni.$u.mpMixin, uni.$u.mixin, value, button, openType, props],
|
||||
// #endif
|
||||
// #ifndef MP
|
||||
mixins: [uni.$u.mpMixin, uni.$u.mixin, value, props],
|
||||
// #endif
|
||||
computed: {
|
||||
valueStyle() {
|
||||
const style = {
|
||||
textDecoration: this.decoration,
|
||||
fontWeight: this.bold ? 'bold' : 'normal',
|
||||
textAlign: this.align,
|
||||
wordWrap: this.wordWrap,
|
||||
fontSize: uni.$u.addUnit(this.size)
|
||||
}
|
||||
!this.type && (style.color = this.color)
|
||||
this.isNvue && this.lines && (style.lines = this.lines)
|
||||
this.lineHeight && (style.lineHeight = uni.$u.addUnit(this.lineHeight))
|
||||
!this.isNvue && this.block && (style.display = 'block')
|
||||
return uni.$u.deepMerge(style, uni.$u.addStyle(this.customStyle))
|
||||
},
|
||||
isNvue() {
|
||||
let nvue = false
|
||||
// #ifdef APP-NVUE
|
||||
nvue = true
|
||||
// #endif
|
||||
return nvue
|
||||
},
|
||||
isMp() {
|
||||
let mp = false
|
||||
// #ifdef MP
|
||||
mp = true
|
||||
// #endif
|
||||
return mp
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
clickHandler() {
|
||||
// 如果为手机号模式,拨打电话
|
||||
if (this.mode === 'phone' && uni.$u.test.mobile(this.text)) {
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: this.text
|
||||
});
|
||||
}
|
||||
this.$emit('click')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import "../../libs/css/components.scss";
|
||||
|
||||
.u-text {
|
||||
@include flex(row);
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
flex: 1;
|
||||
|
||||
&__price {
|
||||
font-size: 14px;
|
||||
color: $u-content-color;
|
||||
}
|
||||
|
||||
&__value {
|
||||
font-size: 14px;
|
||||
@include flex;
|
||||
color: $u-content-color;
|
||||
flex-wrap: wrap;
|
||||
flex: 1;
|
||||
text-overflow: ellipsis;
|
||||
align-items: center;
|
||||
|
||||
&--primary {
|
||||
color: $u-primary;
|
||||
}
|
||||
|
||||
&--warning {
|
||||
color: $u-warning;
|
||||
}
|
||||
|
||||
&--success {
|
||||
color: $u-success;
|
||||
}
|
||||
|
||||
&--info {
|
||||
color: $u-info;
|
||||
}
|
||||
|
||||
&--error {
|
||||
color: $u-error;
|
||||
}
|
||||
|
||||
&--main {
|
||||
color: $u-main-color;
|
||||
}
|
||||
|
||||
&--content {
|
||||
color: $u-content-color;
|
||||
}
|
||||
|
||||
&--tips {
|
||||
color: $u-tips-color;
|
||||
}
|
||||
|
||||
&--light {
|
||||
color: $u-light-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
@ -0,0 +1,66 @@
|
||||
export default {
|
||||
computed: {
|
||||
// 经处理后需要显示的值
|
||||
value() {
|
||||
const {
|
||||
text,
|
||||
mode,
|
||||
format,
|
||||
href
|
||||
} = this
|
||||
// 价格类型
|
||||
if (mode === 'price') {
|
||||
// 如果text不为金额进行提示
|
||||
!uni.$u.test.amount(text) && uni.$u.error('金额模式下,text参数需要为金额格式')
|
||||
// 进行格式化,判断用户传入的format参数为正则,或者函数,如果没有传入format,则使用默认的金额格式化处理
|
||||
if (uni.$u.test.func(format)) {
|
||||
// 如果用户传入的是函数,使用函数格式化
|
||||
return format(text)
|
||||
}
|
||||
// 如果format非正则,非函数,则使用默认的金额格式化方法进行操作
|
||||
return uni.$u.priceFormat(text, 2)
|
||||
} if (mode === 'date') {
|
||||
// 判断是否合法的日期或者时间戳
|
||||
!uni.$u.test.date(text) && uni.$u.error('日期模式下,text参数需要为日期或时间戳格式')
|
||||
// 进行格式化,判断用户传入的format参数为正则,或者函数,如果没有传入format,则使用默认的格式化处理
|
||||
if (uni.$u.test.func(format)) {
|
||||
// 如果用户传入的是函数,使用函数格式化
|
||||
return format(text)
|
||||
} if (this.formart) {
|
||||
// 如果format非正则,非函数,则使用默认的时间格式化方法进行操作
|
||||
return uni.$u.timeFormat(text, format)
|
||||
}
|
||||
// 如果没有设置format,则设置为默认的时间格式化形式
|
||||
return uni.$u.timeFormat(text, 'yyyy-mm-dd')
|
||||
} if (mode === 'phone') {
|
||||
// 判断是否合法的手机号
|
||||
!uni.$u.test.mobile(text) && uni.$u.error('手机号模式下,text参数需要为手机号码格式')
|
||||
if (uni.$u.test.func(format)) {
|
||||
// 如果用户传入的是函数,使用函数格式化
|
||||
return format(text)
|
||||
} if (format === 'encrypt') {
|
||||
// 如果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') {
|
||||
// 如果format为encrypt,则将姓名进行星号加密处理
|
||||
// return text.replace(/(?<=.)./g, '*').substring(0, 3)
|
||||
return text
|
||||
}
|
||||
return text
|
||||
} if (mode === 'link') {
|
||||
// 判断是否合法的字符粗
|
||||
!uni.$u.test.url(href) && uni.$u.error('超链接模式下,href参数需要为URL格式')
|
||||
return text
|
||||
}
|
||||
return text
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user