看板
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import type { ExtractPropTypes, PropType } from 'vue';
|
||||
import { getColor, useLocale } from '../../';
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
/**
|
||||
* u-link 组件 props 类型定义
|
||||
* @description 超链接组件,支持多端跳转/复制/提示
|
||||
*/
|
||||
export const LinkProps = {
|
||||
/** 文字颜色 */
|
||||
color: {
|
||||
type: String,
|
||||
default: () => getColor('primary')
|
||||
},
|
||||
/** 字体大小,单位rpx */
|
||||
fontSize: {
|
||||
type: [String, Number] as PropType<string | number>,
|
||||
default: 28
|
||||
},
|
||||
/** 是否显示下划线 */
|
||||
underLine: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
/** 要跳转的链接 */
|
||||
href: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
/** 小程序中复制到粘贴板的提示语 */
|
||||
mpTips: {
|
||||
type: String,
|
||||
default: () => t('uLink.mpTips')
|
||||
},
|
||||
/** 下划线颜色 */
|
||||
lineColor: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
/** 是否默认点击跳转 */
|
||||
defaultClick: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* u-link 组件 props 类型
|
||||
*/
|
||||
export type LinkProps = ExtractPropTypes<typeof LinkProps>;
|
||||
@@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<text
|
||||
class="u-link"
|
||||
@tap.stop="openLink"
|
||||
:style="{
|
||||
color: color,
|
||||
fontSize: fontSize + 'rpx',
|
||||
borderBottom: underLine ? `1px solid ${lineColor ? lineColor : color}` : 'none',
|
||||
paddingBottom: underLine ? '0rpx' : '0'
|
||||
}"
|
||||
>
|
||||
<slot></slot>
|
||||
</text>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'u-link',
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
// #ifndef MP-TOUTIAO
|
||||
virtualHost: true,
|
||||
// #endif
|
||||
styleIsolation: 'shared'
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { $u } from '../..';
|
||||
import { LinkProps } from './types';
|
||||
|
||||
/**
|
||||
* link 超链接
|
||||
* @description 该组件为超链接组件,在不同平台有不同表现形式:在APP平台会通过plus环境打开内置浏览器,在小程序中把链接复制到粘贴板,同时提示信息,在H5中通过window.open打开链接。
|
||||
* @tutorial https://uviewpro.cn/zh/components/link.html
|
||||
* @property {String} color 文字颜色(默认var(--u-content-color))
|
||||
* @property {String Number} font-size 字体大小,单位rpx(默认28)
|
||||
* @property {Boolean} under-line 是否显示下划线(默认false)
|
||||
* @property {String} href 跳转的链接,要带上http(s)
|
||||
* @property {String} line-color 下划线颜色,默认同color参数颜色
|
||||
* @property {String} mp-tips 各个小程序平台把链接复制到粘贴板后的提示语(默认“链接已复制,请在浏览器打开”)
|
||||
* @example <u-link href="https://uviewpro.cn">蜀道难,难于上青天</u-link>
|
||||
*/
|
||||
const props = defineProps(LinkProps);
|
||||
const emit = defineEmits(['click']);
|
||||
|
||||
/**
|
||||
* 打开链接方法
|
||||
* 不同平台有不同表现形式
|
||||
*/
|
||||
function openLink() {
|
||||
if (!props.defaultClick) {
|
||||
emit('click', props.href);
|
||||
return;
|
||||
}
|
||||
// #ifdef APP-PLUS
|
||||
if (typeof plus !== 'undefined' && plus.runtime) {
|
||||
plus.runtime.openURL(props.href);
|
||||
}
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
if (typeof window !== 'undefined') {
|
||||
window.open(props.href);
|
||||
}
|
||||
// #endif
|
||||
// #ifdef MP
|
||||
if (typeof uni !== 'undefined' && uni.setClipboardData) {
|
||||
uni.setClipboardData({
|
||||
data: props.href,
|
||||
success: () => {
|
||||
uni.hideToast();
|
||||
if (typeof $u !== 'undefined' && $u.toast && props.mpTips) {
|
||||
$u.toast(props.mpTips);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import '../../libs/css/style.components.scss';
|
||||
|
||||
.u-link {
|
||||
line-height: 1;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user