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;6BAAM,IAAI,QAAQ,KAAK,QAAQ,EAAE;4BAChC,YAAY,CAAC,IAAI,mBACZ,OAAO,EACV,CAAC;yBACJ;oBACH,CAAC,CAAC,CAAC;oBACH,IAAI,CAAC,OAAO,CAAC;wBACX,YAAY,EAAE,YAAY;qBAC3B,CAAC,CAAC;iBACJ;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;iBAC/B;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CAAA,CAAA;AAlGoB,UAAU;IAD9B,WAAW,EAAE;GACO,UAAU,CAkG9B;eAlGoB,UAAU","file":"radio-group.js","sourcesContent":["import config from '../common/config';\nimport { SuperComponent, wxComponent } from '../common/src/index';\nimport Props from '../radio/radio-group-props';\n\nconst { prefix } = config;\nconst name = `${prefix}-radio-group`;\n\n@wxComponent()\nexport default class RadioGroup extends SuperComponent {\n externalClasses = [`${prefix}-class`];\n\n data = {\n prefix,\n classPrefix: name,\n radioOptions: [],\n };\n\n relations = {\n '../radio/radio': {\n type: 'descendant' as 'descendant',\n linked(target) {\n const { value, disabled } = this.data;\n target.setData({\n checked: value === target.data.value,\n });\n target.setDisabled(disabled);\n },\n },\n };\n\n properties = {\n ...Props,\n };\n\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n lifetimes = {\n attached() {\n this.initWithOptions();\n },\n };\n\n observers = {\n value() {\n this.getChilds().forEach((item) => {\n item.setData({\n checked: this.data.value === item.data.value,\n });\n });\n },\n };\n\n methods = {\n getChilds() {\n let items = this.getRelationNodes('../radio/radio');\n if (!items.length) {\n items = this.selectAllComponents(`.${prefix}-radio-option`);\n }\n return items;\n },\n\n updateValue(value) {\n this._trigger('change', { value });\n },\n\n handleRadioChange(e) {\n const { value } = e.target.dataset;\n\n this.updateValue(value);\n },\n\n // 支持自定义options\n initWithOptions() {\n const { options } = this.data;\n // 数字数组|字符串数组|对像数组\n if (!options?.length || !Array.isArray(options)) {\n return;\n }\n const optionsValue = [];\n try {\n options.forEach((element) => {\n const typeName = typeof element;\n if (typeName === 'number' || typeName === 'string') {\n optionsValue.push({\n label: `${element}`,\n value: element,\n });\n } else if (typeName === 'object') {\n optionsValue.push({\n ...element,\n });\n }\n });\n this.setData({\n radioOptions: optionsValue,\n });\n } catch (error) {\n console.error('error', error);\n }\n },\n };\n}\n"]}
|