Skip to content

Commit

Permalink
feat: up-text组件支持uni-app-x
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Aug 27, 2024
1 parent 0e77e00 commit 01dee26
Show file tree
Hide file tree
Showing 27 changed files with 1,673 additions and 371 deletions.
23 changes: 23 additions & 0 deletions src/uni_modules/uview-plus/components/up-link/link.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* @Author : LQ,jry
* @Description :
* @version : 3.0
* @Date : 2021-08-20 16:44:21
* @LastAuthor : jry
* @lastTime : 2024-08-20 14:20:58
* @FilePath : /uview-plus/libs/config/props/link.js
*/
import config from '../../libs/config/config'

export default {
// link超链接组件props参数
link: {
color: config.getString('color.up-primary'),
fontSize: '15px',
underLine: false,
href: '',
mpTips: '链接已复制,请在浏览器打开',
lineColor: '',
text: ''
}
} as UTSJSONObject
2 changes: 1 addition & 1 deletion src/uni_modules/uview-plus/components/up-link/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineMixin } from '../../libs/vue.js'
import defProps from '../../libs/config/props.js'
export const props = defineMixin({
export const propsLink = defineMixin({
props: {
// 文字颜色
color: {
Expand Down
43 changes: 43 additions & 0 deletions src/uni_modules/uview-plus/components/up-link/props.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineMixin } from '../../libs/vue'
import defProps from './link'
let crtProp = defProps['link'] as UTSJSONObject

export const propsLink = defineMixin({
props: {
// 文字颜色
color: {
type: String,
default: crtProp['color']
},
// 字体大小,单位px
fontSize: {
type: [String],
default: crtProp['fontSize']
},
// 是否显示下划线
underLine: {
type: Boolean,
default: crtProp['underLine']
},
// 要跳转的链接
href: {
type: String,
default: crtProp['href']
},
// 小程序中复制到粘贴板的提示语
mpTips: {
type: String,
default: crtProp['mpTips']
},
// 下划线颜色
lineColor: {
type: String,
default: crtProp['lineColor']
},
// 超链接的问题,不使用slot形式传入,是因为nvue下无法修改颜色
text: {
type: String,
default: crtProp['text']
}
}
})
89 changes: 89 additions & 0 deletions src/uni_modules/uview-plus/components/up-link/up-link.uvue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<text
class="up-link"
@tap.stop="openLink"
:style="[linkStyle, addStyle(customStyle)]"
>{{text}}</text>
</template>

<script>
import { propsLink } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addStyle, addUnit, getPx, toast } from '../../libs/function/index';
/**
* link 超链接
* @description 该组件为超链接组件,在不同平台有不同表现形式:在APP平台会通过plus环境打开内置浏览器,在小程序中把链接复制到粘贴板,同时提示信息,在H5中通过window.open打开链接。
* @tutorial https://ijry.github.io/uview-plus/components/link.html
* @property {String} color 文字颜色 (默认 color['up-primary'] )
* @property {String | Number} fontSize 字体大小,单位px (默认 15 )
* @property {Boolean} underLine 是否显示下划线 (默认 false )
* @property {String} href 跳转的链接,要带上http(s)
* @property {String} mpTips 各个小程序平台把链接复制到粘贴板后的提示语(默认“链接已复制,请在浏览器打开”)
* @property {String} lineColor 下划线颜色,默认同color参数颜色
* @property {String} text 超链接的问题,不使用slot形式传入,是因为nvue下无法修改颜色
* @property {Object} customStyle 定义需要用到的外部样式
*
* @example <up-link href="http://www.uviewui.com">蜀道难,难于上青天</up-link>
*/
export default {
name: "up-link",
mixins: [mpMixin, mixin, propsLink],
computed: {
linkStyle(): any{
const style = {
color: this.color,
fontSize: addUnit(this.fontSize),
// line-height设置为比字体大小多2px
lineHeight: addUnit(parseInt(getPx(this.fontSize)) + 2),
textDecoration: this.underLine ? 'underline' : 'none'
}
// if (this.underLine) {
// style.borderBottomColor = this.lineColor || this.color
// style.borderBottomWidth = '1px'
// }
return style
}
},
emits: ["click"],
methods: {
addStyle(style: any): any {
return addStyle(style)
},
openLink(): void {
// #ifdef APP
// todo
//plus.runtime.openURL(this.href)
// #endif
// #ifdef H5
window.open(this.href)
// #endif
// #ifdef MP
// todo
// uni.setClipboardData({
// data: this.href,
// success: () => {
// uni.hideToast();
// this.$nextTick(() => {
// toast(this.mpTips);
// })
// }
// });
// #endif
this.$emit('click')
}
}
}
</script>

<style lang="scss" scoped>
@import "../../libs/css/components.scss";
$up-link-line-height:1 !default;

.up-link {
line-height: $up-link-line-height;
@include flex;
flex-wrap: wrap;
flex: 1;
}
</style>
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/up-link/up-link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</template>

<script>
import { props } from './props.js';
import { propsLink } from './props.js';
import { mpMixin } from '../../libs/mixin/mpMixin.js';
import { mixin } from '../../libs/mixin/mixin.js';
import { addStyle, addUnit, getPx, toast } from '../../libs/function/index.js';
Expand All @@ -28,7 +28,7 @@
*/
export default {
name: "up-link",
mixins: [mpMixin, mixin, props],
mixins: [mpMixin, mixin, propsLink],
computed: {
linkStyle() {
const style = {
Expand Down
3 changes: 2 additions & 1 deletion src/uni_modules/uview-plus/components/up-navbar/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* @lastTime : 2024-08-20 14:20:58
* @FilePath : /uview-plus/libs/config/props/navbar.js
*/
import color from '../../libs/config/color'
import color from '../../libs/config/color.js'

export default {
// navbar 组件
navbar: {
Expand Down
8 changes: 7 additions & 1 deletion src/uni_modules/uview-plus/components/up-text/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineMixin } from '../../libs/vue.js'
import defProps from '../../libs/config/props.js'
export const props = defineMixin({

export const propsText = defineMixin({
props: {
// 主题颜色
type: {
Expand Down Expand Up @@ -107,6 +108,11 @@ export const props = defineMixin({
wordWrap: {
type: String,
default: () => defProps.text.wordWrap
},
// 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
lang: {
type: String,
default: () => defProps.text.lang
}
}
})
154 changes: 154 additions & 0 deletions src/uni_modules/uview-plus/components/up-text/props.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { defineMixin } from '../../libs/vue'
import defProps from './text'
let crtProp = defProps['text'] as UTSJSONObject

export const propsText = defineMixin({
props: {
// 主题颜色
type: {
type: String,
default: crtProp['type']
},
// 是否显示
show: {
type: Boolean,
default: crtProp['show']
},
// 显示的值
text: {
type: [String, Number],
default: crtProp['text']
},
// 前置图标
prefixIcon: {
type: String,
default: crtProp['prefixIcon']
},
// 后置图标
suffixIcon: {
type: String,
default: crtProp['suffixIcon']
},
// 文本处理的匹配模式
// text-普通文本,price-价格,phone-手机号,name-姓名,date-日期,link-超链接
mode: {
type: String,
default: crtProp['mode']
},
// mode=link下,配置的链接
href: {
type: String,
default: crtProp['href']
},
// 格式化规则
format: {
type: [String, Function],
default: crtProp['format']
},
// mode=phone时,点击文本是否拨打电话
call: {
type: Boolean,
default: crtProp['call']
},
// 小程序的打开方式
openType: {
type: String,
default: crtProp['openType']
},
// 是否粗体,默认normal
bold: {
type: Boolean,
default: crtProp['bold']
},
// 是否块状
block: {
type: Boolean,
default: crtProp['block']
},
// 文本显示的行数,如果设置,超出此行数,将会显示省略号
lines: {
type: [String, Number],
default: crtProp['lines']
},
// 文本颜色
color: {
type: String,
default: crtProp['color']
},
// 字体大小
size: {
type: [String, Number],
default: crtProp['size']
},
// 图标的样式
iconStyle: {
type: [Object, String],
default: crtProp['iconStyle']
},
// 文字装饰,下划线,中划线等,可选值 none|underline|line-through
decoration: {
tepe: String,
default: crtProp['decoration']
},
// 外边距,对象、字符串,数值形式均可
margin: {
type: [Object, String, Number],
default: crtProp['margin']
},
// 文本行高
lineHeight: {
type: [String, Number],
default: crtProp['lineHeight']
},
// 文本对齐方式,可选值left|center|right
align: {
type: String,
default: crtProp['align']
},
// 文字换行,可选值break-word|normal|anywhere
wordWrap: {
type: String,
default: crtProp['wordWrap']
},
// 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。只微信小程序有效
lang: {
type: String,
default: crtProp['lang']
},
// 会话来源,open-type="contact"时有效。只微信小程序有效
sessionFrom: {
type: String,
default: crtProp['sessionFrom']
},
// 会话内消息卡片标题,open-type="contact"时有效
// 默认当前标题,只微信小程序有效
sendMessageTitle: {
type: String,
default: crtProp['sendMessageTitle']
},
// 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
// 默认当前分享路径,只微信小程序有效
sendMessagePath: {
type: String,
default: crtProp['sendMessagePath']
},
// 会话内消息卡片图片,open-type="contact"时有效
// 默认当前页面截图,只微信小程序有效
sendMessageImg: {
type: String,
default: crtProp['sendMessageImg']
},
// 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,
// 用户点击后可以快速发送小程序消息,open-type="contact"时有效
showMessageCard: {
type: Boolean,
default: crtProp['showMessageCard']
},
// 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
// 只微信小程序、QQ小程序有效
appParameter: {
type: String,
default: crtProp['appParameter']
},
}
})
3 changes: 2 additions & 1 deletion src/uni_modules/uview-plus/components/up-text/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default {
margin: 0,
lineHeight: '',
align: 'left',
wordWrap: 'normal'
wordWrap: 'normal',
lang: 'en'
}

}
Loading

0 comments on commit 01dee26

Please sign in to comment.