From e930471243b3adae9a4393499517fcdc23637b9d Mon Sep 17 00:00:00 2001 From: jry Date: Sat, 31 Aug 2024 07:12:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20up-radio=E7=BB=84=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81uni-app-x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/up-cell/up-cell.uvue | 2 +- .../components/up-radio-group/props.uts | 90 +++++ .../components/up-radio-group/radioGroup.js | 2 +- .../components/up-radio-group/radioGroup.uts | 30 ++ .../up-radio-group/up-radio-group.uvue | 116 ++++++ .../uview-plus/components/up-radio/props.uts | 81 +++++ .../uview-plus/components/up-radio/radio.uts | 27 ++ .../components/up-radio/up-radio.uvue | 341 ++++++++++++++++++ .../uview-plus/libs/mixin/mixin.uts | 16 +- uni-app-x/pages.json | 16 +- .../radio/{radio.nvue => radio.uvue} | 36 +- 11 files changed, 724 insertions(+), 33 deletions(-) create mode 100644 src/uni_modules/uview-plus/components/up-radio-group/props.uts create mode 100644 src/uni_modules/uview-plus/components/up-radio-group/radioGroup.uts create mode 100644 src/uni_modules/uview-plus/components/up-radio-group/up-radio-group.uvue create mode 100644 src/uni_modules/uview-plus/components/up-radio/props.uts create mode 100644 src/uni_modules/uview-plus/components/up-radio/radio.uts create mode 100644 src/uni_modules/uview-plus/components/up-radio/up-radio.uvue rename uni-app-x/pages/componentsA/radio/{radio.nvue => radio.uvue} (89%) diff --git a/src/uni_modules/uview-plus/components/up-cell/up-cell.uvue b/src/uni_modules/uview-plus/components/up-cell/up-cell.uvue index 0aa968129..9e673623f 100644 --- a/src/uni_modules/uview-plus/components/up-cell/up-cell.uvue +++ b/src/uni_modules/uview-plus/components/up-cell/up-cell.uvue @@ -92,7 +92,7 @@ name: 'up-cell', data() { return { - + parentData: {} as UTSJSONObject } }, mixins: [mpMixin, mixin, propsCell], diff --git a/src/uni_modules/uview-plus/components/up-radio-group/props.uts b/src/uni_modules/uview-plus/components/up-radio-group/props.uts new file mode 100644 index 000000000..e34530344 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio-group/props.uts @@ -0,0 +1,90 @@ +import { defineMixin } from '../../libs/vue' +import defProps from './radioGroup' +import defPropsRadio from '../up-radio/radio' +let crtProp = defProps['radioGroup'] as UTSJSONObject +let crtPropRadio = defPropsRadio['radio'] as UTSJSONObject + +export const propsRadioGroup = defineMixin({ + props: { + // 绑定的值 + modelValue: { + type: [String, Number, Boolean], + default: crtProp['value'] + }, + // 是否禁用全部radio + disabled: { + type: Boolean, + default: crtProp['disabled'] + }, + // 形状,circle-圆形,square-方形 + shape: { + type: String, + default: crtProp['shape'] + }, + // 选中状态下的颜色,如设置此值,将会覆盖parent的activeColor值 + activeColor: { + type: String, + default: crtProp['activeColor'] + }, + // 未选中的颜色 + inactiveColor: { + type: String, + default: crtProp['inactiveColor'] + }, + // 标识符 + name: { + type: String, + default: crtProp['name'] + }, + // 整个组件的尺寸,默认px + size: { + type: [String, Number], + default: crtProp['size'] + }, + // 布局方式,row-横向,column-纵向 + placement: { + type: String, + default: crtProp['placement'] + }, + // label的文本 + label: { + type: [String], + default: crtProp['label'] + }, + // label的颜色 (默认 '#303133' ) + labelColor: { + type: [String], + default: crtProp['labelColor'] + }, + // label的字体大小,px单位 + labelSize: { + type: [String, Number], + default: crtProp['labelSize'] + }, + // 是否禁止点击文本操作checkbox(默认 false ) + labelDisabled: { + type: Boolean, + default: crtProp['labelDisabled'] + }, + // 图标颜色 + iconColor: { + type: String, + default: crtProp['iconColor'] + }, + // 图标的大小,单位px + iconSize: { + type: [String, Number], + default: crtProp['iconSize'] + }, + // 竖向配列时,是否显示下划线 + borderBottom: { + type: Boolean, + default: crtProp['borderBottom'] + }, + // 图标与文字的对齐方式 + iconPlacement: { + type: String, + default: crtPropRadio['iconPlacement'] + } + } +}) diff --git a/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.js b/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.js index e3f4824bc..e51841a9a 100644 --- a/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.js +++ b/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.js @@ -27,4 +27,4 @@ export default { borderBottom: false, iconPlacement: 'left' } -} +} as UTSJSONObject diff --git a/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.uts b/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.uts new file mode 100644 index 000000000..189df3667 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio-group/radioGroup.uts @@ -0,0 +1,30 @@ +/* + * @Author : jry + * @Description : + * @version : 4.0 + * @Date : 2024-08-30 23:26:58 + * @LastAuthor : jry + * @lastTime : 2024-08-30 23:26:58 + * @FilePath : /uview-plus/libs/config/props/radioGroup + */ +export default { + // radio-group组件 + radioGroup: { + value: '', + disabled: false, + shape: 'circle', + activeColor: '#2979ff', + inactiveColor: '#c8c9cc', + name: '', + size: 18, + placement: 'row', + label: '', + labelColor: '#303133', + labelSize: 14, + labelDisabled: false, + iconColor: '#ffffff', + iconSize: 12, + borderBottom: false, + iconPlacement: 'left' + } +} as UTSJSONObject diff --git a/src/uni_modules/uview-plus/components/up-radio-group/up-radio-group.uvue b/src/uni_modules/uview-plus/components/up-radio-group/up-radio-group.uvue new file mode 100644 index 000000000..4b86f9e89 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio-group/up-radio-group.uvue @@ -0,0 +1,116 @@ + + + + + diff --git a/src/uni_modules/uview-plus/components/up-radio/props.uts b/src/uni_modules/uview-plus/components/up-radio/props.uts new file mode 100644 index 000000000..600fee606 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio/props.uts @@ -0,0 +1,81 @@ +/* + * @Author : jry + * @Description : uview-plus component's props mixin file + * @version : 4.0 + * @Date : 2024-08-30 23:17:21 + * @LastAuthor : jry + * @lastTime : 2024-08-30 23:17:20 + */ + import { defineMixin } from '../../libs/vue' +import defProps from './radio' +let crtProp = defProps['radio'] as UTSJSONObject + +export const propsRadio = defineMixin({ + props: { + // radio的名称 + name: { + type: [String, Number, Boolean], + default: crtProp['name'] + }, + // 形状,square为方形,circle为圆型 + shape: { + type: String, + default: crtProp['shape'] + }, + // 是否禁用 + disabled: { + type: [String, Boolean], + default: crtProp['disabled'] + }, + // 是否禁止点击提示语选中单选框 + labelDisabled: { + type: [String, Boolean], + default: crtProp['labelDisabled'] + }, + // 选中状态下的颜色,如设置此值,将会覆盖parent的activeColor值 + activeColor: { + type: String, + default: crtProp['activeColor'] + }, + // 未选中的颜色 + inactiveColor: { + type: String, + default: crtProp['inactiveColor'] + }, + // 图标的大小,单位px + iconSize: { + type: [String, Number], + default: crtProp['iconSize'] + }, + // label的字体大小,px单位 + labelSize: { + type: [String, Number], + default: crtProp['labelSize'] + }, + // label提示文字,因为nvue下,直接slot进来的文字,由于特殊的结构,无法修改样式 + label: { + type: [String, Number], + default: crtProp['label'] + }, + // 整体的大小 + size: { + type: [String, Number], + default: crtProp['size'] + }, + // 图标颜色 + color: { + type: String, + default: crtProp['color'] + }, + // label的颜色 + labelColor: { + type: String, + default: crtProp['labelColor'] + }, + // 图标颜色 + iconColor: { + type: String, + default: crtProp['iconColor'] + } + } +}) diff --git a/src/uni_modules/uview-plus/components/up-radio/radio.uts b/src/uni_modules/uview-plus/components/up-radio/radio.uts new file mode 100644 index 000000000..bcbb8b945 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio/radio.uts @@ -0,0 +1,27 @@ +/* + * @Author : jry + * @Description : + * @version : 4.0 + * @Date : 2021-08-30 23:14:21 + * @LastAuthor : jry + * @lastTime : 2024-08-30 23:20:58 + * @FilePath : /uview-plus/libs/config/props/radio + */ +export default { + // radio组件 + radio: { + name: '', + shape: '', + disabled: '', + labelDisabled: '', + activeColor: '', + inactiveColor: '', + iconSize: '', + labelSize: '', + label: '', + labelColor: '', + size: '', + iconColor: '', + placement: '' + } +} as UTSJSONObject diff --git a/src/uni_modules/uview-plus/components/up-radio/up-radio.uvue b/src/uni_modules/uview-plus/components/up-radio/up-radio.uvue new file mode 100644 index 000000000..27f42c155 --- /dev/null +++ b/src/uni_modules/uview-plus/components/up-radio/up-radio.uvue @@ -0,0 +1,341 @@ + + + + + diff --git a/src/uni_modules/uview-plus/libs/mixin/mixin.uts b/src/uni_modules/uview-plus/libs/mixin/mixin.uts index 7938405d4..20d893bc8 100644 --- a/src/uni_modules/uview-plus/libs/mixin/mixin.uts +++ b/src/uni_modules/uview-plus/libs/mixin/mixin.uts @@ -138,16 +138,22 @@ export const mixin = defineMixin({ // 之所以需要这么做,是因为所有端中,头条小程序不支持通过this.parent.xxx去监听父组件参数的变化 // 此处并不会自动更新子组件的数据,而是依赖父组件up-radio-group去监听data的变化,手动调用更新子组件的方法去重新获取 this.parent = this.getParent(parentName) - // console.log('this.parent', this.parent) - // todo - // if (this.parent.children) { + console.log('this.parent', this.parent) + // if (this.parent.$data?.['children'] != null) { // // 如果父组件的children不存在本组件的实例,才将本实例添加到父组件的children中 - // this.parent.children.indexOf(this) === -1 && this.parent.children.push(this) + // // if (this.parent.$data['children'].indexOf(this) === -1) { + // // this.parent.$data['children'].push(this) + // // } // } if (this.parent != null) { // 历遍parentData中的属性,将parent中的同名属性赋值给parentData UTSJSONObject.keys(this.parentData).map((key: string) => { - this.parentData[key] = this.parent?.$props?.[key] + if (this.parent?.$props?.[key] != null) { + this.parentData[key] = this.parent?.$props?.[key] + } + if (this.parent?.$data?.[key] != null) { + this.parentData[key] = this.parent?.$data?.[key] + } }) } return {} diff --git a/uni-app-x/pages.json b/uni-app-x/pages.json index 8e3a7c4bb..9e13221db 100644 --- a/uni-app-x/pages.json +++ b/uni-app-x/pages.json @@ -104,14 +104,14 @@ // "style": { // "navigationBarTitleText": "吸顶" // } - // }, - // { - // "path": "radio/radio", - // "style": { - // "navigationBarTitleText": "单选框" - // } - // }, - // { + // } + ,{ + "path": "radio/radio", + "style": { + "navigationBarTitleText": "单选框" + } + } + // ,{ // "path": "checkbox/checkbox", // "style": { // "navigationBarTitleText": "复选框" diff --git a/uni-app-x/pages/componentsA/radio/radio.nvue b/uni-app-x/pages/componentsA/radio/radio.uvue similarity index 89% rename from uni-app-x/pages/componentsA/radio/radio.nvue rename to uni-app-x/pages/componentsA/radio/radio.uvue index 010e43bf8..514859b76 100644 --- a/uni-app-x/pages/componentsA/radio/radio.nvue +++ b/uni-app-x/pages/componentsA/radio/radio.uvue @@ -14,8 +14,8 @@ :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" @change="radioChange" > @@ -38,8 +38,8 @@ :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist2" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" > @@ -60,9 +60,9 @@ :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist3" :key="index" - :label="item.name" - :name="item.name" - :disabled="!index" + :label="item['name']" + :name="item['name']" + :disabled="index == 0" > @@ -83,8 +83,8 @@ :customStyle="{marginBottom:'8px'}" v-for="(item, index) in radiolist4" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" > @@ -105,8 +105,8 @@ :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist5" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" > @@ -126,8 +126,8 @@ :customStyle="{marginRight: '16px'}" v-for="(item, index) in radiolist6" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" > @@ -149,8 +149,8 @@ :customStyle="{marginBottom: '16px'}" v-for="(item, index) in radiolist7" :key="index" - :label="item.name" - :name="item.name" + :label="item['name']" + :name="item['name']" > @@ -299,15 +299,15 @@ } }, watch: { - radiovalue1(newValue, oldValue) { + radiovalue1(newValue: any, oldValue: any) { console.log('v-model', newValue); } }, methods: { - groupChange(n) { + groupChange(n: any) { console.log('groupChange', n); }, - radioChange(n) { + radioChange(n: any) { console.log('radioChange', n); } }