sadais-piui 1.2.6-beta1 → 1.2.6-beta10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/components/pi-calendar/index.vue +4 -0
  2. package/components/pi-calendar-input/index.vue +199 -0
  3. package/components/pi-calendar-panel/index.vue +5 -6
  4. package/components/pi-checkbox/index.vue +22 -3
  5. package/components/pi-checkbox-group/index.vue +8 -6
  6. package/components/pi-date-picker/index.vue +83 -86
  7. package/components/pi-date-picker-input/index.vue +188 -0
  8. package/components/pi-form/index.vue +20 -0
  9. package/components/pi-form-item/index.vue +57 -9
  10. package/components/pi-input/index.vue +36 -4
  11. package/components/pi-popup-select/index.vue +2 -0
  12. package/components/pi-radio/index.vue +24 -5
  13. package/components/pi-radio-group/index.vue +16 -2
  14. package/components/pi-regions-select/index.vue +32 -6
  15. package/components/pi-regions-select-input/index.vue +192 -0
  16. package/components/pi-section/index.vue +1 -1
  17. package/components/pi-select/index.vue +79 -7
  18. package/components/pi-select-input/index.vue +208 -0
  19. package/components/pi-subsection/index.vue +403 -0
  20. package/config/calendarInput.js +18 -0
  21. package/config/checkbox.js +2 -1
  22. package/config/checkboxGroup.js +2 -1
  23. package/config/datePicker.js +1 -0
  24. package/config/datePickerInput.js +17 -0
  25. package/config/form.js +2 -0
  26. package/config/formItem.js +2 -0
  27. package/config/input.js +10 -1
  28. package/config/radio.js +4 -3
  29. package/config/radioGroup.js +3 -2
  30. package/config/regionsSelect.js +2 -1
  31. package/config/regionsSelectInput.js +28 -0
  32. package/config/select.js +1 -0
  33. package/config/selectInput.js +28 -0
  34. package/config/subsection.js +14 -0
  35. package/package.json +1 -1
@@ -161,6 +161,10 @@ export default {
161
161
  </script>
162
162
 
163
163
  <style lang="scss" scoped>
164
+ .pi-calendar {
165
+ max-width: 960rpx;
166
+ margin: 0 auto;
167
+ }
164
168
  .date-item {
165
169
  position: relative;
166
170
  z-index: 2;
@@ -0,0 +1,199 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 11:08:49
4
+ * @LastEditTime: 2022-05-21 15:00:48
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description: 日历输入
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-input/index.vue
8
+ -->
9
+
10
+ <template>
11
+ <view class="pi-calendar-input">
12
+ <!-- 输入框 -->
13
+ <view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
14
+ <slot />
15
+ </view>
16
+ <pi-input
17
+ v-else
18
+ type="text"
19
+ :value="getInputValue"
20
+ :custom-class="input.customClass"
21
+ :custom-style="input.customStyle"
22
+ :placeholder="input.placeholder"
23
+ :placeholder-style="input.placeholderStyle"
24
+ :placeholder-class="input.placeholderClass"
25
+ :disabled="input.disabled"
26
+ :border="input.border"
27
+ :maxlength="input.maxlength"
28
+ :password="input.password"
29
+ :cursor-spacing="input.cursorSpacing"
30
+ :focus="input.focus"
31
+ :confirm-type="input.confirmType"
32
+ :confirm-hold="input.confirmHold"
33
+ :cursor="input.cursor"
34
+ :selection-start="input.selectionStart"
35
+ :selection-end="input.selectionEnd"
36
+ :adjust-position="input.adjustPosition"
37
+ :hold-keyboard="input.holdKeyboard"
38
+ :auto-blur="input.autoBlur"
39
+ :show-confirmbar="input.showConfirmbar"
40
+ :auto-height="input.autoHeight"
41
+ :fixed="input.fixed"
42
+ :disable-default-padding="input.disableDefaultPadding"
43
+ :clearable="input.clearable"
44
+ :clear-icon="input.clearIcon"
45
+ @click="show = true"
46
+ />
47
+
48
+ <!-- 日历弹出框 -->
49
+ <pi-calendar
50
+ v-model="show"
51
+ :custom-class="getCalendar.customClass"
52
+ :custom-style="getCalendar.customStyle"
53
+ :show-title="getCalendar.showTitle"
54
+ :title="getCalendar.title"
55
+ :title-padding="getCalendar.titlePadding"
56
+ :type="getCalendar.type"
57
+ :calendar-panel="{
58
+ ...getCalendar.calendarPanel,
59
+ dateFormat: getCalendar.dateFormat,
60
+ value: val
61
+ }"
62
+ :popup="getCalendar.popup"
63
+ @confirm="handleCalendarConfirm"
64
+ />
65
+ </view>
66
+ </template>
67
+
68
+ <script>
69
+ import ValueSync from '../../mixin/value-sync'
70
+ import { getConfig } from '../../config'
71
+
72
+ const TAG = 'PiCalendarInput'
73
+ const { calendarInput } = getConfig()
74
+
75
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
76
+
77
+ export default {
78
+ name: 'PiCalendar',
79
+ // 混入v-model
80
+ mixins: [ValueSync],
81
+ props: {
82
+ // 初始值
83
+ value: {
84
+ required: false
85
+ },
86
+ // 自定义样式,对象形式
87
+ customStyle: {
88
+ type: Object,
89
+ // {}
90
+ default() {
91
+ return calendarInput.customStyle
92
+ }
93
+ },
94
+ // 自定义样式类,字符串形式
95
+ customClass: {
96
+ type: String,
97
+ // ''
98
+ default() {
99
+ return calendarInput.customClass
100
+ }
101
+ },
102
+ // input输入设置
103
+ input: {
104
+ type: Object,
105
+ default() {
106
+ // 参照calendar
107
+ return calendarInput.input
108
+ }
109
+ },
110
+ // 日历弹窗参数设置
111
+ calendar: {
112
+ type: Object,
113
+ default() {
114
+ // 参照calendar
115
+ return calendarInput.calendar
116
+ }
117
+ },
118
+ // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
119
+ dateFormat: {
120
+ type: String,
121
+ // 'YYYY-MM-DD'
122
+ default: calendarInput.dateFormat
123
+ },
124
+ // 范围选择时间分隔符,默认('至')
125
+ rangeSplit: {
126
+ type: String,
127
+ // '至'
128
+ default: calendarInput.rangeSplit
129
+ },
130
+ // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
131
+ parseValueFn: {
132
+ type: [Object, Function],
133
+ default() {
134
+ return {
135
+ [PI_DEFAULT_FN_FLAG]: true,
136
+ fn: calendarInput.parseValueFn
137
+ }
138
+ }
139
+ }
140
+ },
141
+ data() {
142
+ return {
143
+ show: false
144
+ }
145
+ },
146
+ computed: {
147
+ getCalendar() {
148
+ return this.$pi.lang.mergeDeep(calendarInput.calendar, this.calendar)
149
+ },
150
+ getInputValue() {
151
+ const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
152
+ ? this.parseValueFn.fn
153
+ : this.parseValueFn
154
+ if (this.$pi.lang.isFunction(parseValueFn)) {
155
+ const parseValue = parseValueFn(this.val)
156
+ return parseValue
157
+ }
158
+ if (!this.dateFormat) {
159
+ console.warn('使用pi-calendar-input组件,请设置.dateFormat,否则无法正常显示')
160
+ }
161
+ if (this.$pi.lang.isEmpty(this.val)) return ''
162
+ // 常规字段正常返回
163
+ if (this.$pi.lang.isString(this.val) || this.$pi.lang.isNumber(this.val)) {
164
+ return this.val
165
+ }
166
+ // 如果是日期对象,返回格式化后的日期
167
+ if (this.calendar.calendarPanel.type === 'date') {
168
+ return this.$pi.date.formatDate(new Date(this.val), this.dateFormat)
169
+ }
170
+ if (this.calendar.calendarPanel.type === 'range') {
171
+ return this.val
172
+ .map(date => {
173
+ return this.$pi.date.formatDate(new Date(date), this.dateFormat)
174
+ })
175
+ .join(this.rangeSplit)
176
+ }
177
+ return ''
178
+ }
179
+ },
180
+ methods: {
181
+ handlePopupClose() {
182
+ this.val = false
183
+ // 关闭
184
+ this.$emit('close')
185
+ this.handleEmitChange()
186
+ },
187
+ handleCalendarConfirm(value) {
188
+ this.val = value
189
+ this.handleEmitChange()
190
+ }
191
+ }
192
+ }
193
+ </script>
194
+
195
+ <style lang="scss" scoped>
196
+ .pi-calendar-input {
197
+ width: 100%;
198
+ }
199
+ </style>
@@ -58,7 +58,6 @@
58
58
  <view
59
59
  class="pi-abso-center pi-fw-500 pi-light-gray"
60
60
  style="
61
-
62
61
  z-index: 1;
63
62
  font-size: 300rpx;
64
63
  pointer-events: none;
@@ -267,6 +266,11 @@ export default {
267
266
  const inRange =
268
267
  start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
269
268
  const activeStyle = {}
269
+ // 处理中间范围的样式
270
+ if (inRange) {
271
+ activeStyle.color = this.rangeColor
272
+ activeStyle.background = this.rangeBg
273
+ }
270
274
  // 处理两端
271
275
  if (isBegin || isEnd) {
272
276
  activeStyle.color = this.activeColor
@@ -275,11 +279,6 @@ export default {
275
279
  : `0 ${this.getActiveBorderRadius} ${this.getActiveBorderRadius} 0`
276
280
  if (this.activeBg) activeStyle.background = this.activeBg
277
281
  }
278
- // 处理中间范围的样式
279
- if (inRange) {
280
- activeStyle.color = this.rangeColor
281
- activeStyle.background = this.rangeBg
282
- }
283
282
  day.activeStyle = activeStyle
284
283
  // type 为 range 开始和结束的提示
285
284
  if (isBegin) day.tip = this.startText
@@ -3,9 +3,14 @@
3
3
  class="pi-check-wrap"
4
4
  :style="[customStyle]"
5
5
  :class="[getShape, getActiveMode, { disabled: getDisable }, { active: val }, customClass]"
6
- @tap="handleCheckboxToggle"
6
+ @tap="handleCheckboxToggle(true)"
7
7
  >
8
- <view v-if="getShape !== 'text'" class="check-icon" :style="[checkStyle]">
8
+ <view
9
+ v-if="getShape !== 'text'"
10
+ class="check-icon"
11
+ :style="[checkStyle]"
12
+ @tap.stop="handleCheckboxToggle(false)"
13
+ >
9
14
  <view v-if="getShape === 'dot'" class="dot" :style="[dotStyle]" />
10
15
  <pi-icon v-else name="blod-check" :size="getIconSize" />
11
16
  </view>
@@ -124,6 +129,12 @@ export default {
124
129
  validator: function(value) {
125
130
  return ['line', 'line-circle', 'fill', 'fill-circle'].includes(value)
126
131
  }
132
+ },
133
+ // 是否点击图标才能选中,默认点击整行都能选中
134
+ onlyIconSelect: {
135
+ type: [Boolean],
136
+ // null
137
+ default: checkbox.onlyIconSelect
127
138
  }
128
139
  },
129
140
  data() {
@@ -162,6 +173,11 @@ export default {
162
173
  ? this.$pi.common.addUnit(this.inheritProps.iconSize)
163
174
  : this.$pi.common.addUnit(this.iconSize)
164
175
  },
176
+ getOnlyIconSelect() {
177
+ return this.inheritProps.onlyIconSelect !== null
178
+ ? this.inheritProps.onlyIconSelect
179
+ : this.onlyIconSelect
180
+ },
165
181
  checkStyle() {
166
182
  const style = {
167
183
  width: this.getSize,
@@ -218,7 +234,8 @@ export default {
218
234
  this.val = true
219
235
  }
220
236
  },
221
- handleCheckboxToggle() {
237
+ handleCheckboxToggle(isTapRow) {
238
+ if (this.getOnlyIconSelect && isTapRow) return
222
239
  if (this.getDisable) return
223
240
  if (this.readonly) return
224
241
  // 如果父组件做了可选数量限制
@@ -242,6 +259,8 @@ $unactive-color: #cccccc;
242
259
  .pi-check-wrap {
243
260
  display: inline-flex;
244
261
  align-items: center;
262
+ cursor: pointer;
263
+
245
264
  .check-icon {
246
265
  position: relative;
247
266
  display: inline-flex;
@@ -33,7 +33,8 @@ export default {
33
33
  'size',
34
34
  'iconSize',
35
35
  'activeColor',
36
- 'activeMode'
36
+ 'activeMode',
37
+ 'onlyIconSelect'
37
38
  ])
38
39
  ], // 注入value与val,进行双向绑定
39
40
  options: {
@@ -125,6 +126,12 @@ export default {
125
126
  validator: function(value) {
126
127
  return ['', 'line', 'line-circle', 'fill', 'fill-circle'].includes(value)
127
128
  }
129
+ },
130
+ // 是否点击图标才能选中,默认点击整行都能选中
131
+ onlyIconSelect: {
132
+ type: [Boolean, null],
133
+ // null
134
+ default: checkboxGroup.onlyIconSelect
128
135
  }
129
136
  },
130
137
  computed: {
@@ -137,11 +144,6 @@ export default {
137
144
  handler(value) {
138
145
  this.handleValChange()
139
146
  }
140
- },
141
- value: {
142
- handler(val) {
143
- console.warn('val', val)
144
- }
145
147
  }
146
148
  },
147
149
  methods: {
@@ -29,32 +29,9 @@
29
29
  @pickend="handlePickend"
30
30
  @change="handleDateChange"
31
31
  >
32
- <picker-view-column>
33
- <view v-for="(item, index) in years" :key="index" :style="indicatorStyle">
34
- {{ item }}年
35
- </view>
36
- </picker-view-column>
37
- <picker-view-column v-if="showMonth">
38
- <view v-for="(item, index) in months" :key="index" :style="indicatorStyle">
39
- {{ item + 1 }}月
40
- </view>
41
- </picker-view-column>
42
- <picker-view-column v-if="showDay">
43
- <view v-for="(item, index) in days" :key="index" :style="indicatorStyle">{{ item }}日</view>
44
- </picker-view-column>
45
- <picker-view-column v-if="showHour">
46
- <view v-for="(item, index) in hours" :key="index" :style="indicatorStyle">
47
- {{ item }}时
48
- </view>
49
- </picker-view-column>
50
- <picker-view-column v-if="showMinute">
51
- <view v-for="(item, index) in minutes" :key="index" :style="indicatorStyle">
52
- {{ item }}分
53
- </view>
54
- </picker-view-column>
55
- <picker-view-column v-if="showSecond">
56
- <view v-for="(item, index) in seconds" :key="index" :style="indicatorStyle">
57
- {{ item }}秒
32
+ <picker-view-column v-for="col in columns" :key="col.field">
33
+ <view v-for="item in col.items" :key="item" :style="indicatorStyle">
34
+ {{ item }}{{ col.unit }}
58
35
  </view>
59
36
  </picker-view-column>
60
37
  </picker-view>
@@ -68,14 +45,7 @@ import { getConfig } from '../../config'
68
45
 
69
46
  const TAG = 'PiDatePicker'
70
47
  const { datePicker } = getConfig()
71
- const FIELD_MAPS = [
72
- { field: 'year', getMethod: 'years', setMethod: 'setYear' },
73
- { field: 'month', getMethod: 'months', setMethod: 'setMonth' },
74
- { field: 'day', getMethod: 'days', setMethod: 'setDate' },
75
- { field: 'hour', getMethod: 'hours', setMethod: 'setHours' },
76
- { field: 'minute', getMethod: 'minutes', setMethod: 'setMinutes' },
77
- { field: 'second', getMethod: 'seconds', setMethod: 'setSeconds' }
78
- ]
48
+ const FIELDS = ['year', 'month', 'day', 'hour', 'minute', 'second']
79
49
 
80
50
  export default {
81
51
  name: 'PiDatePicker',
@@ -124,13 +94,25 @@ export default {
124
94
  type: String,
125
95
  validator: function(value) {
126
96
  // 这个值必须匹配下列字符串中的一个
127
- return ['year', 'month', 'day', 'hour', 'minute', 'second'].includes(value)
97
+ return FIELDS.includes(value)
128
98
  },
129
99
  // 'day'
130
100
  default() {
131
101
  return datePicker.field
132
102
  }
133
103
  },
104
+ // 日期类型,date、datetime、time
105
+ dateType: {
106
+ // `'date'` `'datetime'` `'time'`
107
+ type: String,
108
+ validator: function(value) {
109
+ return ['date', 'datetime', 'time'].includes(value)
110
+ },
111
+ // 'datetime'
112
+ default() {
113
+ return datePicker.dateType
114
+ }
115
+ },
134
116
  // 日期默认值
135
117
  defaultValue: {
136
118
  type: [Number, String, Date],
@@ -245,61 +227,75 @@ export default {
245
227
  const itemHeight = uni.upx2px(this.itemHeight)
246
228
  return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
247
229
  },
248
- showYear() {
249
- return ['year', 'month', 'day', 'hour', 'minute', 'second'].includes(this.field)
250
- },
251
- showMonth() {
252
- return ['month', 'day', 'hour', 'minute', 'second'].includes(this.field)
253
- },
254
- showDay() {
255
- return ['day', 'hour', 'minute', 'second'].includes(this.field)
256
- },
257
- showHour() {
258
- return ['hour', 'minute', 'second'].includes(this.field)
259
- },
260
- showMinute() {
261
- return ['minute', 'second'].includes(this.field)
262
- },
263
- showSecond() {
264
- return ['second'].includes(this.field)
265
- },
266
- years() {
267
- return this.$pi.common.generateArray(this.startYear, this.endYear)
268
- },
269
- months() {
270
- return this.$pi.common.generateArray(0, 11)
271
- },
272
- days() {
230
+ columns() {
273
231
  const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
274
- return this.$pi.common.generateArray(1, monthDays)
275
- },
276
- hours() {
277
- return this.$pi.common.generateArray(0, 23)
278
- },
279
- minutes() {
280
- return this.$pi.common.generateArray(0, 59)
281
- },
282
- seconds() {
283
- return this.$pi.common.generateArray(0, 59)
232
+ let columns = [
233
+ {
234
+ field: 'year',
235
+ unit: '年',
236
+ key: 'year',
237
+ setMethod: 'setYear',
238
+ items: this.$pi.common.generateArray(this.startYear, this.endYear)
239
+ },
240
+ {
241
+ field: 'month',
242
+ unit: '月',
243
+ key: 'month',
244
+ setMethod: 'setMonth',
245
+ items: this.$pi.common.generateArray(1, 12)
246
+ },
247
+ {
248
+ field: 'day',
249
+ unit: '日',
250
+ key: 'date',
251
+ setMethod: 'setDate',
252
+ items: this.$pi.common.generateArray(1, monthDays)
253
+ },
254
+ {
255
+ field: 'hour',
256
+ unit: '时',
257
+ key: 'hour',
258
+ setMethod: 'setHours',
259
+ type: 'time',
260
+ items: this.$pi.common.generateArray(0, 23)
261
+ },
262
+ {
263
+ field: 'minute',
264
+ unit: '分',
265
+ key: 'minute',
266
+ setMethod: 'setMinutes',
267
+ type: 'time',
268
+ items: this.$pi.common.generateArray(0, 59)
269
+ },
270
+ {
271
+ field: 'second',
272
+ unit: '秒',
273
+ key: 'second',
274
+ setMethod: 'setSeconds',
275
+ type: 'time',
276
+ items: this.$pi.common.generateArray(0, 59)
277
+ }
278
+ ]
279
+
280
+ columns = columns.filter((col, index) => {
281
+ return FIELDS.slice(index).includes(this.field)
282
+ })
283
+
284
+ if (this.dateType === 'time') {
285
+ columns = columns.filter(col => col.type === 'time')
286
+ }
287
+
288
+ return columns
284
289
  },
285
290
  pickerValue() {
286
- const dateFieldMaps = [
287
- { key: 'year', dataKey: 'years', showKey: 'showYear' },
288
- { key: 'month', dataKey: 'months', showKey: 'showMonth' },
289
- { key: 'date', dataKey: 'days', showKey: 'showDay' },
290
- { key: 'hour', dataKey: 'hours', showKey: 'showHour' },
291
- { key: 'minute', dataKey: 'minutes', showKey: 'showMinute' },
292
- { key: 'second', dataKey: 'seconds', showKey: 'showSecond' }
293
- ]
294
291
  const pickerValue = []
295
- dateFieldMaps.forEach(map => {
292
+ this.columns.forEach(col => {
296
293
  // 当前日期字段
297
- let value = this.date[map.key]
298
- if (this[map.showKey] && value) {
299
- if (map.key === 'month') value--
294
+ const value = this.date[col.key]
295
+ if (value !== null) {
300
296
  // 查找当前picker中索引对应的真实值
301
297
  const intValue = parseInt(value, 10)
302
- const val = this[map.dataKey].findIndex(m => m === intValue)
298
+ const val = col.items.findIndex(m => m === intValue)
303
299
  pickerValue.push(val)
304
300
  }
305
301
  })
@@ -338,9 +334,10 @@ export default {
338
334
  values.forEach((value, index) => {
339
335
  if (value !== null) {
340
336
  // value为picker列的索引值
341
- const field = FIELD_MAPS[index] // day
342
- const val = this[field.getMethod][value] // days[index] 取出对应picker值
343
- time[field.setMethod](val) // 调用原生date方法赋值
337
+ const col = this.columns[index]
338
+ let val = col.items[value] // 取出对应picker值
339
+ if (col.field === 'month') val--
340
+ time[col.setMethod](val) // 调用原生date方法赋值
344
341
  }
345
342
  })
346
343
  // 重新解析