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AAA;AA9CoB,IAAI;IADxB,WAAW,EAAE;GACO,IAAI,CA8CxB;eA9CoB,IAAI","file":"rate.js","sourcesContent":["/*\n * @Author: rileycai\n * @Date: 2021-09-21 19:01:54\n * @LastEditTime: 2021-11-10 14:30:02\n * @LastEditors: rileycai\n * @Description: Rate组件\n * @FilePath: /tdesign-miniprogram/src/rate/rate.ts\n */\nimport { SuperComponent, wxComponent } from '../common/src/index';\nimport config from '../common/config';\nimport props from './props';\n\nconst { prefix } = config;\nconst name = `${prefix}-rate`;\n\nconst rpx2px = (() => {\n let systemInfo: any = null;\n return (rpx: number): number => {\n if (!systemInfo) {\n systemInfo = wx.getSystemInfoSync();\n }\n return (rpx * (systemInfo ? systemInfo.screenWidth : 750)) / 750;\n };\n})();\n\n@wxComponent()\nexport default class Rate extends SuperComponent {\n externalClasses = ['t-class', 't-class-icon', 't-class-desc'];\n\n properties = props;\n\n controlledProps = [\n {\n key: 'value',\n event: 'change',\n },\n ];\n\n data = {\n classPrefix: name,\n icon: 'star-filled',\n halfIcon: 'star-filled',\n defaultTexts: ['极差', '失望', '一般', '满意', '惊喜'],\n disabledColor: '#999999',\n };\n\n onTouch(e: any) {\n const { count, allowHalf, gap, value: currentValue } = this.properties as any;\n const [touch] = e.touches;\n const margin = rpx2px(gap);\n const selQuery = this.createSelectorQuery();\n selQuery\n .select(`.${name}__wrapper`)\n .boundingClientRect((rect: any) => {\n const { width, left } = rect;\n const starWidth = (width - (count - 1) * margin) / count;\n const offsetX = touch.pageX - left;\n const num = (offsetX + margin) / (starWidth + margin);\n const remainder = num % 1;\n const integral = num - remainder;\n let value = remainder <= 0.5 && allowHalf ? integral + 0.5 : integral + 1;\n if (value > count) {\n value = count;\n } else if (value < 0) {\n value = 0;\n }\n if (value !== currentValue) {\n this._trigger('change', { value });\n }\n })\n .exec();\n }\n}\n"]}
|