v1.0
This commit is contained in:
24
uni_modules/uv-textarea/changelog.md
Normal file
24
uni_modules/uv-textarea/changelog.md
Normal file
@ -0,0 +1,24 @@
|
||||
## 1.0.9(2023-08-08)
|
||||
1. 优化
|
||||
## 1.0.8(2023-08-07)
|
||||
1. 修复值为null或undefined时显示错误的bug
|
||||
## 1.0.7(2023-08-05)
|
||||
1. v-model设置为数据时的BUG
|
||||
2. 复制过多内容,计数显示错误的BUG
|
||||
3. maxlength为-1改成不显示计数
|
||||
## 1.0.6(2023-07-30)
|
||||
1. 增加confirm-hold参数,参考官方文档
|
||||
## 1.0.5(2023-07-25)
|
||||
1. 增加textStyle属性,自定义文本样式
|
||||
2. 增加countStyle属性,自定义统计数字的样式
|
||||
## 1.0.4(2023-07-14)
|
||||
1. 修复 设置maxlength为-1时不生效的BUG
|
||||
## 1.0.3(2023-07-13)
|
||||
1. 修复 uv-textarea设置value属性不生效的BUG
|
||||
## 1.0.2(2023-05-16)
|
||||
1. 优化组件依赖,修改后无需全局引入,组件导入即可使用
|
||||
2. 优化部分功能
|
||||
## 1.0.1(2023-05-12)
|
||||
1. 修复vue3中双向绑定问题
|
||||
## 1.0.0(2023-05-10)
|
||||
uv-textarea 文本域
|
138
uni_modules/uv-textarea/components/uv-textarea/props.js
Normal file
138
uni_modules/uv-textarea/components/uv-textarea/props.js
Normal file
@ -0,0 +1,138 @@
|
||||
export default {
|
||||
props: {
|
||||
value: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
},
|
||||
modelValue: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
},
|
||||
// 输入框为空时占位符
|
||||
placeholder: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
},
|
||||
// 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/
|
||||
placeholderClass: {
|
||||
type: String,
|
||||
default: 'textarea-placeholder'
|
||||
},
|
||||
// 指定placeholder的样式
|
||||
placeholderStyle: {
|
||||
type: [String, Object],
|
||||
default: 'color: #c0c4cc'
|
||||
},
|
||||
// 输入框高度
|
||||
height: {
|
||||
type: [String, Number],
|
||||
default: 70
|
||||
},
|
||||
// 设置键盘右下角按钮的文字,仅微信小程序,App-vue和H5有效
|
||||
confirmType: {
|
||||
type: String,
|
||||
default: 'done'
|
||||
},
|
||||
// 是否禁用
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否显示统计字数
|
||||
count: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否自动获取焦点,nvue不支持,H5取决于浏览器的实现
|
||||
focus: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否自动增加高度
|
||||
autoHeight: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 如果textarea是在一个position:fixed的区域,需要显示指定属性fixed为true
|
||||
fixed: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 指定光标与键盘的距离
|
||||
cursorSpacing: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
// 指定focus时的光标位置
|
||||
cursor: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
},
|
||||
// 是否显示键盘上方带有”完成“按钮那一栏,
|
||||
showConfirmBar: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 光标起始位置,自动聚焦时有效,需与selection-end搭配使用
|
||||
selectionStart: {
|
||||
type: Number,
|
||||
default: -1
|
||||
},
|
||||
// 光标结束位置,自动聚焦时有效,需与selection-start搭配使用
|
||||
selectionEnd: {
|
||||
type: Number,
|
||||
default: -1
|
||||
},
|
||||
// 键盘弹起时,是否自动上推页面
|
||||
adjustPosition: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 是否去掉 iOS 下的默认内边距,只微信小程序有效
|
||||
disableDefaultPadding: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// focus时,点击页面的时候不收起键盘,只微信小程序有效
|
||||
holdKeyboard: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 最大输入长度,设置为 -1 的时候不限制最大长度
|
||||
maxlength: {
|
||||
type: [String, Number],
|
||||
default: 140
|
||||
},
|
||||
// 边框类型,surround-四周边框,bottom-底部边框
|
||||
border: {
|
||||
type: String,
|
||||
default: 'surround'
|
||||
},
|
||||
// 用于处理或者过滤输入框内容的方法
|
||||
formatter: {
|
||||
type: [Function, null],
|
||||
default: null
|
||||
},
|
||||
// 是否忽略组件内对文本合成系统事件的处理
|
||||
ignoreCompositionEvent: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
// 是否忽略组件内对文本合成系统事件的处理
|
||||
confirmHold: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 文本样式
|
||||
textStyle: {
|
||||
type: [Object, String],
|
||||
default: () => {}
|
||||
},
|
||||
// 统计数字的样式
|
||||
countStyle: {
|
||||
type: [Object, String],
|
||||
default: () => {}
|
||||
},
|
||||
...uni.$uv?.props?.textarea
|
||||
}
|
||||
}
|
238
uni_modules/uv-textarea/components/uv-textarea/uv-textarea.vue
Normal file
238
uni_modules/uv-textarea/components/uv-textarea/uv-textarea.vue
Normal file
@ -0,0 +1,238 @@
|
||||
<template>
|
||||
<view class="uv-textarea"
|
||||
:class="textareaClass"
|
||||
:style="[textareaStyle]">
|
||||
<textarea class="uv-textarea__field"
|
||||
:value="innerValue"
|
||||
:style="[
|
||||
{height: $uv.addUnit(height)},
|
||||
$uv.addStyle(textStyle)
|
||||
]"
|
||||
:placeholder="placeholder"
|
||||
:placeholder-style="$uv.addStyle(placeholderStyle, 'string')"
|
||||
:placeholder-class="placeholderClass"
|
||||
:disabled="disabled"
|
||||
:focus="focus"
|
||||
:autoHeight="autoHeight"
|
||||
:fixed="fixed"
|
||||
:cursorSpacing="cursorSpacing"
|
||||
:cursor="cursor"
|
||||
:showConfirmBar="showConfirmBar"
|
||||
:selectionStart="selectionStart"
|
||||
:selectionEnd="selectionEnd"
|
||||
:adjustPosition="adjustPosition"
|
||||
:disableDefaultPadding="disableDefaultPadding"
|
||||
:holdKeyboard="holdKeyboard"
|
||||
:maxlength="maxlen"
|
||||
:confirmType="confirmType"
|
||||
:ignoreCompositionEvent="ignoreCompositionEvent"
|
||||
:confirm-hold="confirmHold"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
@linechange="onLinechange"
|
||||
@input="onInput"
|
||||
@confirm="onConfirm"
|
||||
@keyboardheightchange="onKeyboardheightchange"></textarea>
|
||||
<text class="uv-textarea__count"
|
||||
:style="[{
|
||||
'background-color': disabled ? 'transparent' : '#fff',
|
||||
},$uv.addStyle(countStyle)]"
|
||||
v-if="count && maxlen!=-1">{{ getCount }}/{{ maxlen }}</text>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
|
||||
import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
|
||||
import props from "./props.js";
|
||||
/**
|
||||
* Textarea 文本域
|
||||
* @description 文本域此组件满足了可能出现的表单信息补充,编辑等实际逻辑的功能,内置了字数校验等
|
||||
* @tutorial https://www.uvui.cn/components/textarea.html
|
||||
*
|
||||
* @property {String | Number} value / v-model 输入框的内容
|
||||
* @property {String | Number} placeholder 输入框为空时占位符
|
||||
* @property {String} placeholderClass 指定placeholder的样式类,注意页面或组件的style中写了scoped时,需要在类名前写/deep/ ( 默认 'input-placeholder' )
|
||||
* @property {String | Object} placeholderStyle 指定placeholder的样式,字符串/对象形式,如"color: red;"
|
||||
* @property {String | Number} height 输入框高度(默认 70 )
|
||||
* @property {String} confirmType 设置键盘右下角按钮的文字,仅微信小程序,App-vue和H5有效(默认 'done' )
|
||||
* @property {Boolean} disabled 是否禁用(默认 false )
|
||||
* @property {Boolean} count 是否显示统计字数(默认 false )
|
||||
* @property {Boolean} focus 是否自动获取焦点,nvue不支持,H5取决于浏览器的实现(默认 false )
|
||||
* @property {Boolean | Function} autoHeight 是否自动增加高度(默认 false )
|
||||
* @property {Boolean} fixed 如果textarea是在一个position:fixed的区域,需要显示指定属性fixed为true(默认 false )
|
||||
* @property {Number} cursorSpacing 指定光标与键盘的距离(默认 0 )
|
||||
* @property {String | Number} cursor 指定focus时的光标位置
|
||||
* @property {Function} formatter 内容式化函数
|
||||
* @property {Boolean} showConfirmBar 是否显示键盘上方带有”完成“按钮那一栏,(默认 true )
|
||||
* @property {Number} selectionStart 光标起始位置,自动聚焦时有效,需与selection-end搭配使用,(默认 -1 )
|
||||
* @property {Number | Number} selectionEnd 光标结束位置,自动聚焦时有效,需与selection-start搭配使用(默认 -1 )
|
||||
* @property {Boolean} adjustPosition 键盘弹起时,是否自动上推页面(默认 true )
|
||||
* @property {Boolean | Number} disableDefaultPadding 是否去掉 iOS 下的默认内边距,只微信小程序有效(默认 false )
|
||||
* @property {Boolean} holdKeyboard focus时,点击页面的时候不收起键盘,只微信小程序有效(默认 false )
|
||||
* @property {String | Number} maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认 140 )
|
||||
* @property {String} border 边框类型,surround-四周边框,none-无边框,bottom-底部边框(默认 'surround' )
|
||||
* @property {Boolean} ignoreCompositionEvent 是否忽略组件内对文本合成系统事件的处理
|
||||
* @property {Boolean} confirmHold 点击键盘右下角按钮时是否保持键盘不收起
|
||||
* @property {Object} textStyle 文本样式
|
||||
* @property {Object} countStyle 统计数字的样式
|
||||
*
|
||||
* @event {Function(e)} focus 输入框聚焦时触发,event.detail = { value, height },height 为键盘高度
|
||||
* @event {Function(e)} blur 输入框失去焦点时触发,event.detail = {value, cursor}
|
||||
* @event {Function(e)} linechange 输入框行数变化时调用,event.detail = {height: 0, heightRpx: 0, lineCount: 0}
|
||||
* @event {Function(e)} input 当键盘输入时,触发 input 事件
|
||||
* @event {Function(e)} confirm 点击完成时, 触发 confirm 事件
|
||||
* @event {Function(e)} keyboardheightchange 键盘高度发生变化的时候触发此事件
|
||||
* @example <uv--textarea v-model="value1" placeholder="请输入内容" ></uv--textarea>
|
||||
*/
|
||||
export default {
|
||||
name: "uv-textarea",
|
||||
mixins: [mpMixin, mixin, props],
|
||||
data() {
|
||||
return {
|
||||
// 输入框的值
|
||||
innerValue: "",
|
||||
// 是否处于获得焦点状态
|
||||
focused: false,
|
||||
// 过滤处理方法
|
||||
innerFormatter: value => value
|
||||
}
|
||||
},
|
||||
created() {
|
||||
// #ifndef VUE3
|
||||
this.innerValue = this.value;
|
||||
// #endif
|
||||
// #ifdef VUE3
|
||||
this.innerValue = this.modelValue;
|
||||
// #endif
|
||||
},
|
||||
watch: {
|
||||
value(newVal) {
|
||||
this.innerValue = newVal;
|
||||
},
|
||||
modelValue(newVal) {
|
||||
this.innerValue = newVal;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 组件的类名
|
||||
textareaClass() {
|
||||
let classes = [],
|
||||
{ border, disabled } = this;
|
||||
border === "surround" && (classes = classes.concat(["uv-border", "uv-textarea--radius"]));
|
||||
border === "bottom" && (classes = classes.concat(["uv-border-bottom", "uv-textarea--no-radius", ]));
|
||||
disabled && classes.push("uv-textarea--disabled");
|
||||
return classes.join(" ");
|
||||
},
|
||||
// 组件的样式
|
||||
textareaStyle() {
|
||||
const style = {};
|
||||
// #ifdef APP-NVUE
|
||||
// 由于textarea在安卓nvue上的差异性,需要额外再调整其内边距
|
||||
if (this.$uv.os() === "android") {
|
||||
style.paddingTop = "6px";
|
||||
style.paddingLeft = "9px";
|
||||
style.paddingBottom = "3px";
|
||||
style.paddingRight = "6px";
|
||||
}
|
||||
// #endif
|
||||
return this.$uv.deepMerge(style, this.$uv.addStyle(this.customStyle));
|
||||
},
|
||||
maxlen() {
|
||||
return this.maxlength < 0 ? this.maxlength < 0 ? -1 : 140 : this.maxlength;
|
||||
},
|
||||
getCount() {
|
||||
try{
|
||||
return this.innerValue.length > this.maxlen ? this.maxlen: this.innerValue.length;
|
||||
}catch(e){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 在微信小程序中,不支持将函数当做props参数,故只能通过ref形式调用
|
||||
setFormatter(e) {
|
||||
this.innerFormatter = e
|
||||
},
|
||||
onFocus(e) {
|
||||
this.$emit("focus", e);
|
||||
},
|
||||
onBlur(e) {
|
||||
this.$emit("blur", e);
|
||||
// 尝试调用uv-form的验证方法
|
||||
this.$uv.formValidate(this, "blur");
|
||||
},
|
||||
onLinechange(e) {
|
||||
this.$emit("linechange", e);
|
||||
},
|
||||
onInput(e) {
|
||||
let { value = "" } = e.detail || {};
|
||||
// 格式化过滤方法
|
||||
const formatter = this.formatter || this.innerFormatter
|
||||
const formatValue = formatter(value)
|
||||
// 为了避免props的单向数据流特性,需要先将innerValue值设置为当前值,再在$nextTick中重新赋予设置后的值才有效
|
||||
this.innerValue = value
|
||||
this.$nextTick(() => {
|
||||
this.innerValue = formatValue;
|
||||
this.valueChange();
|
||||
})
|
||||
},
|
||||
// 内容发生变化,进行处理
|
||||
valueChange() {
|
||||
const value = this.innerValue;
|
||||
this.$nextTick(() => {
|
||||
this.$emit("input", value);
|
||||
this.$emit("update:modelValue", value);
|
||||
this.$emit("change", value);
|
||||
// 尝试调用uv-form的验证方法
|
||||
this.$uv.formValidate(this, "change");
|
||||
});
|
||||
},
|
||||
onConfirm(e) {
|
||||
this.$emit("confirm", e);
|
||||
},
|
||||
onKeyboardheightchange(e) {
|
||||
this.$emit("keyboardheightchange", e);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
$show-border: 1;
|
||||
$show-border-surround: 1;
|
||||
$show-border-bottom: 1;
|
||||
@import '@/uni_modules/uv-ui-tools/libs/css/variable.scss';
|
||||
@import '@/uni_modules/uv-ui-tools/libs/css/components.scss';
|
||||
@import '@/uni_modules/uv-ui-tools/libs/css/color.scss';
|
||||
.uv-textarea {
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
position: relative;
|
||||
@include flex;
|
||||
flex: 1;
|
||||
padding: 9px;
|
||||
&--radius {
|
||||
border-radius: 4px;
|
||||
}
|
||||
&--no-radius {
|
||||
border-radius: 0;
|
||||
}
|
||||
&--disabled {
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
&__field {
|
||||
flex: 1;
|
||||
font-size: 15px;
|
||||
color: $uv-content-color;
|
||||
width: 100%;
|
||||
}
|
||||
&__count {
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
bottom: 2px;
|
||||
font-size: 12px;
|
||||
color: $uv-tips-color;
|
||||
background-color: #ffffff;
|
||||
padding: 1px 4px;
|
||||
}
|
||||
}
|
||||
</style>
|
87
uni_modules/uv-textarea/package.json
Normal file
87
uni_modules/uv-textarea/package.json
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"id": "uv-textarea",
|
||||
"displayName": "uv-textarea 文本域 全面兼容vue3+2、app、h5、小程序等多端",
|
||||
"version": "1.0.9",
|
||||
"description": "文本域此组件满足了可能出现的表单信息补充,编辑等实际逻辑的功能,内置了字数校验等。",
|
||||
"keywords": [
|
||||
"uv-textarea",
|
||||
"uvui",
|
||||
"uv-ui",
|
||||
"textarea",
|
||||
"文本域"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "component-vue",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "插件不采集任何数据",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [
|
||||
"uv-ui-tools"
|
||||
],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "y",
|
||||
"vue3": "y"
|
||||
},
|
||||
"App": {
|
||||
"app-vue": "y",
|
||||
"app-nvue": "y"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "y",
|
||||
"Android Browser": "y",
|
||||
"微信浏览器(Android)": "y",
|
||||
"QQ浏览器(Android)": "y"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "y",
|
||||
"IE": "y",
|
||||
"Edge": "y",
|
||||
"Firefox": "y",
|
||||
"Safari": "y"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "y",
|
||||
"阿里": "y",
|
||||
"百度": "y",
|
||||
"字节跳动": "y",
|
||||
"QQ": "y",
|
||||
"钉钉": "u",
|
||||
"快手": "u",
|
||||
"飞书": "u",
|
||||
"京东": "u"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
uni_modules/uv-textarea/readme.md
Normal file
19
uni_modules/uv-textarea/readme.md
Normal file
@ -0,0 +1,19 @@
|
||||
## Textarea 文本域
|
||||
|
||||
> **组件名:uv-textarea**
|
||||
|
||||
文本域此组件满足了可能出现的表单信息补充,编辑等实际逻辑的功能,内置了字数校验等。
|
||||
|
||||
# <a href="https://www.uvui.cn/components/textarea.html" target="_blank">查看文档</a>
|
||||
|
||||
## [下载完整示例项目](https://ext.dcloud.net.cn/plugin?name=uv-ui) <small>(请不要 下载插件ZIP)</small>
|
||||
|
||||
### [更多插件,请关注uv-ui组件库](https://ext.dcloud.net.cn/plugin?name=uv-ui)
|
||||
|
||||
<a href="https://ext.dcloud.net.cn/plugin?name=uv-ui" target="_blank">
|
||||
|
||||

|
||||
|
||||
</a>
|
||||
|
||||
#### 如使用过程中有任何问题反馈,或者您对uv-ui有一些好的建议,欢迎加入uv-ui官方交流群:<a href="https://www.uvui.cn/components/addQQGroup.html" target="_blank">官方QQ群</a>
|
Reference in New Issue
Block a user