checkbox-group.d.ts.map 5.3 KB

1
  1. {"version":3,"sources":["../src/checkbox-group/checkbox-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAOlE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,cAAc;IACvD,eAAe,WAAe;IAE9B,SAAS;;;;;MAOP;IAEF,IAAI;;;MAGF;IAEF,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;MAMR;IAEF,SAAS;;MAIP;IAEF,SAAS;;MAIP;IAEF,eAAe;;;QAKb;IAEF,OAAO;;;;;;;;;6BAmGgB,MAAM;;MA2B3B;CACH","file":"checkbox-group.d.ts","sourcesContent":["import { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport Props from '../checkbox/checkbox-group-props';\n\nconst { prefix } = config;\nconst name = `${prefix}-checkbox-group`;\n@wxComponent()\nexport default class CheckBoxGroup extends SuperComponent {\n externalClasses = ['t-class'];\n\n relations = {\n '../checkbox/checkbox': {\n type: 'descendant' as 'descendant',\n linked() {\n this.updateChildren();\n },\n },\n };\n\n data = {\n classPrefix: name,\n checkboxOptions: [],\n };\n\n properties = {\n ...Props,\n defaultValue: {\n type: null,\n value: undefined,\n },\n };\n\n observers = {\n value: function () {\n this.updateChildren();\n },\n };\n\n lifetimes = {\n attached() {\n this.handleCreateMulCheckbox();\n },\n };\n\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n methods = {\n getChilds() {\n let items = this.getRelationNodes('../checkbox/checkbox');\n if (!items.length) {\n items = this.selectAllComponents('.t-checkbox-option');\n }\n return items || [];\n },\n\n // slot插入选项\n updateChildren() {\n const items = this.getChilds();\n\n const { value, disabled } = this.data;\n if (items.length > 0) {\n items.forEach((item: any) => {\n !item.data.checkAll &&\n item.setData({\n checked: value?.indexOf(item.data.value) > -1,\n });\n item.setDisabled(disabled);\n });\n // 关联可全选项\n if (items.findIndex((item) => item.data.checkAll) > -1) {\n items.forEach((item) => {\n item.setOptionLinked(true);\n });\n this.handleHalfCheck(items.length);\n }\n }\n },\n updateValue({ name, checked }) {\n const { value, max } = this.data;\n let newValue = value;\n if (max && checked && newValue.length === max) {\n return;\n }\n if (checked) {\n newValue = newValue.concat(name);\n } else {\n const index = newValue.findIndex((v: string) => v === name);\n newValue.splice(index, 1);\n }\n this._trigger('change', { value: newValue });\n },\n // 支持自定义options\n handleCreateMulCheckbox() {\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 checkboxOptions: optionsValue,\n });\n this.updateChildren();\n } catch (error) {\n console.error('error', error);\n }\n },\n // 处理全选\n handleCheckAll(e) {\n const { checked, option, name } = e.detail || e;\n const items = this.getChilds();\n\n if (!option) {\n if (!items?.length) {\n return;\n }\n this._trigger('change', {\n value: items\n .map((item) => {\n if (item.data.disabled) {\n return this.data.value.includes(item.data.value) ? item.data.value : '';\n }\n return checked && !item.data.checkAll ? item.data.value : '';\n })\n .filter((val) => val),\n });\n } else {\n this.updateValue({ name, checked });\n }\n },\n // 处理options半选\n handleHalfCheck(len: number) {\n const items = this.getChilds();\n const checkboxOptions = items.filter((i) => !i.data.checkAll);\n const all = checkboxOptions.map((item) => item.data.value);\n const enableValue = checkboxOptions\n .filter((i) => !i.data.disabled)\n .map((item) => item.data.value);\n const currentVal = Array.from(new Set(this.data.value?.filter((i) => all.indexOf(i) > -1)));\n const element = items.find((item) => item.data.checkAll);\n if (currentVal.length) {\n element?.setData({ checked: true });\n element?.changeCheckAllHalfStatus(currentVal.length !== len - 1);\n // 取消全选\n element?.setCancel(enableValue.every((val) => currentVal.includes(val)));\n } else {\n element?.setData({ checked: false });\n }\n },\n // 设置可全选option选项\n handleOptionLinked() {\n const items = this.selectAllComponents('.t-checkbox-option');\n if (this.data.checkboxOptions.length) {\n items.forEach((item) => {\n item.setOptionLinked(true);\n });\n }\n },\n };\n}\n"]}