New Huajishe Check ChaoXing
This commit is contained in:
3
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/props.d.ts
vendored
Normal file
3
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/props.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TdRadioGroupProps } from './type';
|
||||
declare const props: TdRadioGroupProps;
|
||||
export default props;
|
||||
@@ -0,0 +1,44 @@
|
||||
const props = {
|
||||
allowUncheck: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
borderless: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
disabled: {
|
||||
type: null,
|
||||
value: undefined,
|
||||
},
|
||||
icon: {
|
||||
type: null,
|
||||
value: 'circle',
|
||||
},
|
||||
keys: {
|
||||
type: Object,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
value: '',
|
||||
},
|
||||
options: {
|
||||
type: Array,
|
||||
},
|
||||
placement: {
|
||||
type: String,
|
||||
value: 'left',
|
||||
},
|
||||
readonly: {
|
||||
type: null,
|
||||
value: undefined,
|
||||
},
|
||||
value: {
|
||||
type: null,
|
||||
value: null,
|
||||
},
|
||||
defaultValue: {
|
||||
type: null,
|
||||
},
|
||||
};
|
||||
export default props;
|
||||
26
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/radio-group.d.ts
vendored
Normal file
26
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/radio-group.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { SuperComponent, RelationsOptions } from '../common/src/index';
|
||||
export default class RadioGroup extends SuperComponent {
|
||||
externalClasses: string[];
|
||||
data: {
|
||||
prefix: string;
|
||||
classPrefix: string;
|
||||
radioOptions: any[];
|
||||
};
|
||||
relations: RelationsOptions;
|
||||
properties: import("./type").TdRadioGroupProps<import("./type").RadioValue>;
|
||||
controlledProps: {
|
||||
key: string;
|
||||
event: string;
|
||||
}[];
|
||||
observers: {
|
||||
value(v: any): void;
|
||||
options(): void;
|
||||
disabled(v: any): void;
|
||||
};
|
||||
methods: {
|
||||
getChildren(): any;
|
||||
updateValue(value: any): void;
|
||||
handleRadioChange(e: any): void;
|
||||
initWithOptions(): void;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
import config from '../common/config';
|
||||
import { SuperComponent, wxComponent } from '../common/src/index';
|
||||
import props from './props';
|
||||
const { prefix } = config;
|
||||
const name = `${prefix}-radio-group`;
|
||||
let RadioGroup = class RadioGroup extends SuperComponent {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.externalClasses = [`${prefix}-class`];
|
||||
this.data = {
|
||||
prefix,
|
||||
classPrefix: name,
|
||||
radioOptions: [],
|
||||
};
|
||||
this.relations = {
|
||||
'../radio/radio': {
|
||||
type: 'descendant',
|
||||
linked(target) {
|
||||
const { value, disabled, readonly } = this.data;
|
||||
target.setData({
|
||||
checked: value === target.data.value,
|
||||
});
|
||||
target.setDisabled(disabled);
|
||||
target.setReadonly(readonly);
|
||||
},
|
||||
},
|
||||
};
|
||||
this.properties = props;
|
||||
this.controlledProps = [
|
||||
{
|
||||
key: 'value',
|
||||
event: 'change',
|
||||
},
|
||||
];
|
||||
this.observers = {
|
||||
value(v) {
|
||||
this.getChildren().forEach((item) => {
|
||||
item.setData({
|
||||
checked: v === item.data.value,
|
||||
});
|
||||
});
|
||||
},
|
||||
options() {
|
||||
this.initWithOptions();
|
||||
},
|
||||
disabled(v) {
|
||||
var _a;
|
||||
if ((_a = this.data.options) === null || _a === void 0 ? void 0 : _a.length) {
|
||||
this.initWithOptions();
|
||||
return;
|
||||
}
|
||||
this.getChildren().forEach((item) => {
|
||||
item.setDisabled(v);
|
||||
});
|
||||
},
|
||||
};
|
||||
this.methods = {
|
||||
getChildren() {
|
||||
let items = this.$children;
|
||||
if (!(items === null || items === void 0 ? void 0 : items.length)) {
|
||||
items = this.selectAllComponents(`.${prefix}-radio-option`);
|
||||
}
|
||||
return items;
|
||||
},
|
||||
updateValue(value) {
|
||||
this._trigger('change', { value });
|
||||
},
|
||||
handleRadioChange(e) {
|
||||
const { checked } = e.detail;
|
||||
const { value, index, allowUncheck } = e.target.dataset;
|
||||
this._trigger('change', checked === false && allowUncheck ? { value: null, index } : { value, index });
|
||||
},
|
||||
initWithOptions() {
|
||||
const { options, value, keys, disabled, readonly } = this.data;
|
||||
if (!(options === null || options === void 0 ? void 0 : options.length) || !Array.isArray(options)) {
|
||||
this.setData({
|
||||
radioOptions: [],
|
||||
});
|
||||
return;
|
||||
}
|
||||
const optionsValue = [];
|
||||
try {
|
||||
options.forEach((element) => {
|
||||
var _a, _b, _c;
|
||||
const typeName = typeof element;
|
||||
if (typeName === 'number' || typeName === 'string') {
|
||||
optionsValue.push({
|
||||
label: `${element}`,
|
||||
value: element,
|
||||
checked: value === element,
|
||||
disabled,
|
||||
readonly,
|
||||
});
|
||||
}
|
||||
else if (typeName === 'object') {
|
||||
optionsValue.push(Object.assign(Object.assign({}, element), { label: element[(_a = keys === null || keys === void 0 ? void 0 : keys.label) !== null && _a !== void 0 ? _a : 'label'], value: element[(_b = keys === null || keys === void 0 ? void 0 : keys.value) !== null && _b !== void 0 ? _b : 'value'], checked: value === element[(_c = keys === null || keys === void 0 ? void 0 : keys.value) !== null && _c !== void 0 ? _c : 'value'], disabled: element.disabled || disabled, readonly: element.readonly || readonly }));
|
||||
}
|
||||
});
|
||||
this.setData({
|
||||
radioOptions: optionsValue,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
console.error('error', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
RadioGroup = __decorate([
|
||||
wxComponent()
|
||||
], RadioGroup);
|
||||
export default RadioGroup;
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"component": true,
|
||||
"styleIsolation": "apply-shared",
|
||||
"usingComponents": {
|
||||
"t-radio": "../radio/radio"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<wxs src="../common/utils.wxs" module="_" />
|
||||
|
||||
<view style="{{_._style([style, customStyle])}}" class="{{classPrefix}} class {{prefix}}-class" aria-role="radiogroup">
|
||||
<slot />
|
||||
<block wx:for="{{radioOptions}}" wx:key="value">
|
||||
<t-radio
|
||||
class="{{prefix}}-radio-option"
|
||||
data-index="{{index}}"
|
||||
data-value="{{item.value}}"
|
||||
data-allow-uncheck="{{item.allowUncheck || allowUncheck}}"
|
||||
block="{{item.block || true}}"
|
||||
label="{{item.label || ''}}"
|
||||
value="{{item.value}}"
|
||||
checked="{{item.checked || false}}"
|
||||
content="{{item.content || ''}}"
|
||||
allow-uncheck="{{item.allowUncheck || allowUncheck}}"
|
||||
content-disabled="{{item.contentDisabled || false}}"
|
||||
readonly="{{item.readonly || false}}"
|
||||
disabled="{{item.disabled || false}}"
|
||||
icon="{{item.icon || icon}}"
|
||||
placement="{{item.placement || placement}}"
|
||||
max-content-row="{{item.maxContentRow || 5}}"
|
||||
max-label-row="{{item.maxLabelRow || 3}}"
|
||||
name="{{item.name || ''}}"
|
||||
borderless="{{borderless}}"
|
||||
bind:change="handleRadioChange"
|
||||
/>
|
||||
</block>
|
||||
</view>
|
||||
56
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/type.d.ts
vendored
Normal file
56
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/radio-group/type.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
import { KeysType } from '../common/common';
|
||||
export interface TdRadioGroupProps<T = RadioValue> {
|
||||
allowUncheck?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
borderless?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
disabled?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
icon?: {
|
||||
type: null;
|
||||
value?: 'circle' | 'line' | 'dot' | Array<string>;
|
||||
};
|
||||
keys?: {
|
||||
type: ObjectConstructor;
|
||||
value?: KeysType;
|
||||
};
|
||||
name?: {
|
||||
type: StringConstructor;
|
||||
value?: string;
|
||||
};
|
||||
options?: {
|
||||
type: ArrayConstructor;
|
||||
value?: Array<RadioOption>;
|
||||
};
|
||||
placement?: {
|
||||
type: StringConstructor;
|
||||
value?: 'left' | 'right';
|
||||
};
|
||||
readonly?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
value?: {
|
||||
type: null;
|
||||
value?: T;
|
||||
};
|
||||
defaultValue?: {
|
||||
type: null;
|
||||
value?: T;
|
||||
};
|
||||
}
|
||||
export declare type RadioOption = string | number | RadioOptionObj;
|
||||
export interface RadioOptionObj {
|
||||
label?: string;
|
||||
value?: string | number;
|
||||
readonly?: boolean;
|
||||
disabled?: boolean;
|
||||
allowUncheck?: boolean;
|
||||
}
|
||||
export declare type RadioValue = string | number | boolean;
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user