sadais-piui 1.2.6-beta4 → 1.2.6-beta7

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.
@@ -0,0 +1,200 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 11:08:49
4
+ * @LastEditTime: 2022-05-18 16:38:07
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
+ // 删除之前的钩子, 如果定义了则使用钩子删除文件
156
+ const parseValue = parseValueFn(this.val)
157
+ return parseValue
158
+ }
159
+ if (!this.dateFormat) {
160
+ console.warn('使用pi-calendar-input组件,请设置.dateFormat,否则无法正常显示')
161
+ }
162
+ if (this.$pi.lang.isEmpty(this.val)) return ''
163
+ // 常规字段正常返回
164
+ if (this.$pi.lang.isString(this.val) || this.$pi.lang.isNumber(this.val)) {
165
+ return this.val
166
+ }
167
+ // 如果是日期对象,返回格式化后的日期
168
+ if (this.calendar.calendarPanel.type === 'date') {
169
+ return this.$pi.date.formatDate(new Date(this.val), this.dateFormat)
170
+ }
171
+ if (this.calendar.calendarPanel.type === 'range') {
172
+ return this.val
173
+ .map(date => {
174
+ return this.$pi.date.formatDate(new Date(date), this.dateFormat)
175
+ })
176
+ .join(` ${this.rangeSplit} `)
177
+ }
178
+ return ''
179
+ }
180
+ },
181
+ methods: {
182
+ handlePopupClose() {
183
+ this.val = false
184
+ // 关闭
185
+ this.$emit('close')
186
+ this.handleEmitChange()
187
+ },
188
+ handleCalendarConfirm(value) {
189
+ this.val = value
190
+ this.handleEmitChange()
191
+ }
192
+ }
193
+ }
194
+ </script>
195
+
196
+ <style lang="scss" scoped>
197
+ .pi-calendar-input {
198
+ width: 100%;
199
+ }
200
+ </style>
@@ -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="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
  // 如果父组件做了可选数量限制
@@ -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: {
@@ -2,7 +2,7 @@
2
2
  <view
3
3
  class="pi-form-item"
4
4
  :style="[customStyle, itemStyle]"
5
- :class="[...getFormItemClass, customClass]"
5
+ :class="getFormItemClass"
6
6
  @tap="handleItemClick"
7
7
  >
8
8
  <!-- 表单标题 -->
@@ -85,6 +85,12 @@ const alignFlexMap = {
85
85
  right: 'flex-end'
86
86
  }
87
87
 
88
+ const verticalAlignFlexMap = {
89
+ top: 'pi-align-start',
90
+ center: 'pi-align-center',
91
+ bottom: 'pi-align-end'
92
+ }
93
+
88
94
  export default {
89
95
  name: 'PiFormItem',
90
96
  mixins: [extendPiFrom, Emitter], // 注入inheritProps
@@ -352,7 +358,7 @@ export default {
352
358
  }
353
359
  },
354
360
  getFormItemClass() {
355
- const classList = []
361
+ const classList = [this.customClass]
356
362
  if (this.getDisabled) {
357
363
  classList.push('disabled')
358
364
  }
@@ -360,7 +366,7 @@ export default {
360
366
  classList.push('border')
361
367
  }
362
368
  if (!this.getWrap && this.getItemVerticalAlign) {
363
- classList.push(`pi-align-${this.getItemVerticalAlign}`)
369
+ classList.push(verticalAlignFlexMap[this.getItemVerticalAlign])
364
370
  }
365
371
  return classList
366
372
  }
@@ -569,5 +575,8 @@ export default {
569
575
  text-align: right;
570
576
  }
571
577
  }
578
+ ::v-deep pi-calendar-input {
579
+ width: 100%;
580
+ }
572
581
  }
573
582
  </style>
@@ -63,6 +63,20 @@
63
63
  @confirm="handleConfirm"
64
64
  @keyboardheightchange="$emit('keyboardheightchange', $event)"
65
65
  />
66
+ <!-- 清空icon -->
67
+ <pi-icon
68
+ v-if="clearable && val"
69
+ :custom-style="clearIcon.customStyle"
70
+ :custom-class="`pi-pd-left-8 ${clearIcon.customClass}`"
71
+ :name="clearIcon.name"
72
+ :dot="clearIcon.dot"
73
+ :dot-radius="clearIcon.dotRadius"
74
+ :badge="clearIcon.badge"
75
+ :color="clearIcon.color"
76
+ :size="clearIcon.size"
77
+ :class-prefix="clearIcon.classPrefix"
78
+ @tap="handleChange('')"
79
+ />
66
80
  </view>
67
81
  </template>
68
82
 
@@ -241,6 +255,19 @@ export default {
241
255
  type: Boolean,
242
256
  // false
243
257
  default: input.disableDefaultPadding
258
+ },
259
+ // 是否可清空
260
+ clearable: {
261
+ type: Boolean,
262
+ // false
263
+ default: input.clearable
264
+ },
265
+ // 清空图标设置
266
+ clearIcon: {
267
+ type: Object,
268
+ default() {
269
+ return input.clearIcon
270
+ }
244
271
  }
245
272
  },
246
273
  data() {
@@ -275,10 +302,7 @@ export default {
275
302
  handleInput: debounce(function(e) {
276
303
  let value = e.detail.value
277
304
  // 输入内容
278
- this.val = value
279
- this.handleEmitChange()
280
- this.dispatch('PiForm', 'form-change', value)
281
- this.dispatch('PiFormItem', 'form-change', value)
305
+ this.handleChange(value)
282
306
  }, 50),
283
307
  handleFocus() {
284
308
  this.focused = true
@@ -302,6 +326,12 @@ export default {
302
326
  handleConfirm(e) {
303
327
  // 输入完成事件
304
328
  this.$emit('confirm', e.detail.value)
329
+ },
330
+ handleChange(value) {
331
+ this.val = value
332
+ this.handleEmitChange()
333
+ this.dispatch('PiForm', 'form-change', value)
334
+ this.dispatch('PiFormItem', 'form-change', value)
305
335
  }
306
336
  }
307
337
  }
@@ -310,6 +340,8 @@ export default {
310
340
  <style lang="scss" scoped>
311
341
  .pi-input-wrap {
312
342
  width: 100%;
343
+ display: flex;
344
+ align-items: center;
313
345
  .pi-input,
314
346
  .pi-input-textarea {
315
347
  width: 100%;
@@ -10,9 +10,14 @@
10
10
  { stretch: getStretch },
11
11
  customClass
12
12
  ]"
13
- @tap="handleRadioToggle"
13
+ @tap="handleRadioToggle(true)"
14
14
  >
15
- <view v-if="!['text', 'button'].includes(getShape)" class="radio-icon" :style="[radioStyle]">
15
+ <view
16
+ v-if="!['text', 'button'].includes(getShape)"
17
+ class="radio-icon"
18
+ :style="[radioStyle]"
19
+ @tap="handleRadioToggle(false)"
20
+ >
16
21
  <view v-if="getShape === 'dot'" class="dot" />
17
22
  <pi-icon v-else name="blod-check" :size="getIconSize" />
18
23
  </view>
@@ -133,6 +138,12 @@ export default {
133
138
  type: Boolean,
134
139
  // false
135
140
  default: radio.canCancel
141
+ },
142
+ // 是否点击图标才能选中,默认点击整行都能选中
143
+ onlyIconSelect: {
144
+ type: [Boolean],
145
+ // null
146
+ default: radio.onlyIconSelect
136
147
  }
137
148
  },
138
149
  data() {
@@ -150,8 +161,8 @@ export default {
150
161
  return this.inheritProps.stretch
151
162
  },
152
163
  getBorderRadius() {
153
- return this._parent && this._parent.borderRadius
154
- ? this.$pi.common.addUnit(this._parent.borderRadius)
164
+ return this.inheritProps.borderRadius
165
+ ? this.$pi.common.addUnit(this.inheritProps.borderRadius)
155
166
  : this.$pi.common.addUnit(this.borderRadius)
156
167
  },
157
168
  getBorder() {
@@ -181,6 +192,11 @@ export default {
181
192
  getCanCancel() {
182
193
  return this.inheritProps.canCancel !== null ? this.inheritProps.canCancel : this.canCancel
183
194
  },
195
+ getOnlyIconSelect() {
196
+ return this.inheritProps.onlyIconSelect !== null
197
+ ? this.inheritProps.onlyIconSelect
198
+ : this.onlyIconSelect
199
+ },
184
200
  radioStyle() {
185
201
  const style = {
186
202
  width: this.getSize,
@@ -227,7 +243,8 @@ export default {
227
243
  }
228
244
  },
229
245
  methods: {
230
- handleRadioToggle() {
246
+ handleRadioToggle(isTapRow) {
247
+ if (this.getOnlyIconSelect && isTapRow) return
231
248
  if (this.getDisable) return
232
249
  if (this.readonly) return
233
250
  this._parent && this._parent.emitChange(this.name)
@@ -31,6 +31,7 @@ export default {
31
31
  parentInit([
32
32
  'val',
33
33
  'shape',
34
+ 'borderRadius',
34
35
  'stretch',
35
36
  'border',
36
37
  'disabled',
@@ -38,7 +39,8 @@ export default {
38
39
  'iconSize',
39
40
  'activeColor',
40
41
  'activeMode',
41
- 'canCancel'
42
+ 'canCancel',
43
+ 'onlyIconSelect'
42
44
  ])
43
45
  ], // 注入value与val,进行双向绑定
44
46
  options: {
@@ -91,6 +93,12 @@ export default {
91
93
  return ['', 'square', 'round', 'dot', 'text', 'button'].includes(value)
92
94
  }
93
95
  },
96
+ // 当shape为square的时候,设置圆角,值为数字时,单位默认rpx
97
+ borderRadius: {
98
+ type: [null, String, Number],
99
+ // 8
100
+ default: radioGroup.borderRadius
101
+ },
94
102
  // 当shape为button的时候,选项否均分布局,可选值 `true`
95
103
  stretch: {
96
104
  type: Boolean,
@@ -141,9 +149,15 @@ export default {
141
149
  },
142
150
  // 能否取消选中状态
143
151
  canCancel: {
144
- type: Boolean,
152
+ type: [Boolean, null],
145
153
  // null
146
154
  default: radioGroup.canCancel
155
+ },
156
+ // 是否点击图标才能选中,默认点击整行都能选中
157
+ onlyIconSelect: {
158
+ type: [Boolean, null],
159
+ // null
160
+ default: radioGroup.onlyIconSelect
147
161
  }
148
162
  },
149
163
  methods: {
@@ -0,0 +1,18 @@
1
+ import input from './input'
2
+ import calendar from './calendar'
3
+
4
+ export default {
5
+ customClass: '', // 自定义样式类,字符串形式('')
6
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
7
+ // input输入设置
8
+ input: {
9
+ ...input,
10
+ placeholder: '请选择',
11
+ disabled: true // 是否禁用
12
+ },
13
+ // 日历弹窗的配置,默认选项请参照calendar
14
+ calendar,
15
+ dateFormat: 'YYYY-MM-DD', // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
16
+ rangeSplit: '至', // 范围选择时间分隔符,默认('至')
17
+ parseValueFn: null // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
18
+ }
@@ -10,5 +10,6 @@ export default {
10
10
  size: 40, // checkbox大小,单位rpx
11
11
  iconSize: 28, // checkbox icon 大小,单位rpx
12
12
  activeColor: '', // 选中时图标的颜色
13
- activeMode: 'line' // 激活模式(line: 线框模式,fill: 实底模式)
13
+ activeMode: 'line', // 激活模式(line: 线框模式,fill: 实底模式)
14
+ onlyIconSelect: false // 是否点击图标才能选中,默认点击整行都能选中
14
15
  }
@@ -10,5 +10,6 @@ export default {
10
10
  size: 0, // checkbox大小,单位rpx
11
11
  iconSize: 0, // checkbox icon 大小,单位rpx
12
12
  activeColor: '', // 选中时图标的颜色
13
- activeMode: '' // 激活模式(line: 线框模式,fill: 实底模式)
13
+ activeMode: '', // 激活模式(line: 线框模式,fill: 实底模式)
14
+ onlyIconSelect: null // 是否点击图标才能选中,默认点击整行都能选中
14
15
  }
package/config/input.js CHANGED
@@ -1,3 +1,5 @@
1
+ import icon from './icon'
2
+
1
3
  export default {
2
4
  customClass: '', // 自定义样式类,字符串形式('')
3
5
  customStyle: {}, // 自定义样式,对象形式(默认值:{})
@@ -22,5 +24,12 @@ export default {
22
24
  showConfirmbar: true, // 是否显示键盘上方带有”完成“按钮那一栏
23
25
  autoHeight: false, // 是否自动增高
24
26
  fixed: false, // 如果 textarea 是在一个 position:fixed 的区域,需要显示指定属性 fixed 为 true
25
- disableDefaultPadding: false // 是否去掉 iOS 下的默认内边距
27
+ disableDefaultPadding: false, // 是否去掉 iOS 下的默认内边距
28
+ clearable: false, // 是否可以清空
29
+ clearIcon: {
30
+ // 清空图标设置
31
+ ...icon,
32
+ name: 'close-line',
33
+ color: '#cccccc'
34
+ }
26
35
  }
package/config/radio.js CHANGED
@@ -4,12 +4,13 @@ export default {
4
4
  name: '', // 标识符
5
5
  shape: 'round', // 形状,可选值为 square round dot text
6
6
  borderRadius: 8, // 当shape为square的时候,设置圆角,单位rpx
7
- border: 4, // 边框大小,单位rpx
7
+ border: 2, // 边框大小,单位rpx
8
8
  disabled: false, // 是否禁用复选框
9
9
  readonly: false, // 是否只读模式
10
- size: 36, // radio大小,单位rpx
10
+ size: 40, // radio大小,单位rpx
11
11
  iconSize: 28, // radio icon 大小,单位rpx
12
12
  activeColor: '', // 选中时图标的颜色
13
13
  activeMode: 'line', // 激活模式(line: 线框模式,fill: 实底模式)
14
- canCancel: false // 能否取消选中状态
14
+ canCancel: false, // 能否取消选中状态
15
+ onlyIconSelect: false // 是否点击图标才能选中,默认点击整行都能选中
15
16
  }
@@ -5,12 +5,13 @@ export default {
5
5
  direction: 'horizontal', // 排列方向,可选值为 horizontal vertical
6
6
  shape: '', // 形状,可选值为 square round dot text button
7
7
  stretch: false, // 当shape为button的时候,选项否均分布局,可选值 `true`
8
- borderRadius: 0, // 当shape为square的时候,设置圆角,单位rpx
8
+ borderRadius: null, // 当shape为square的时候,设置圆角,单位rpx
9
9
  border: 0, // 边框大小,单位rpx
10
10
  disabled: false, // 是否禁用复选框
11
11
  size: 0, // checkbox大小,单位rpx
12
12
  iconSize: 0, // checkbox icon 大小,单位rpx
13
13
  activeColor: '', // 选中时图标的颜色
14
14
  activeMode: '', // 激活模式(line: 线框模式,fill: 实底模式)
15
- canCancel: null // 能否取消选中状态
15
+ canCancel: null, // 能否取消选中状态
16
+ onlyIconSelect: null // 是否点击图标才能选中,默认点击整行都能选中
16
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.6beta4",
3
+ "version": "1.2.6beta7",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {