@10yun/cv-mobile-ui 0.5.19 → 0.5.21

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 (137) hide show
  1. package/other/mpvue-picker/mpvuePicker.vue +402 -0
  2. package/{uni-ui/lib → other}/mpvue-picker/style.css +0 -1
  3. package/{uni-ui/lib → other}/tab-nvue/style.css +0 -1
  4. package/other/uParse/components/style.css +1 -0
  5. package/other/uParse/components/wxParseAudio.vue +1 -0
  6. package/other/uParse/components/wxParseImg.vue +86 -0
  7. package/other/uParse/components/wxParseTable.vue +54 -0
  8. package/other/uParse/components/wxParseTemplate0.vue +98 -0
  9. package/other/uParse/components/wxParseTemplate1.vue +81 -0
  10. package/other/uParse/components/wxParseTemplate10.vue +81 -0
  11. package/other/uParse/components/wxParseTemplate11.vue +79 -0
  12. package/other/uParse/components/wxParseTemplate2.vue +81 -0
  13. package/other/uParse/components/wxParseTemplate3.vue +81 -0
  14. package/other/uParse/components/wxParseTemplate4.vue +81 -0
  15. package/other/uParse/components/wxParseTemplate5.vue +81 -0
  16. package/other/uParse/components/wxParseTemplate6.vue +81 -0
  17. package/other/uParse/components/wxParseTemplate7.vue +81 -0
  18. package/other/uParse/components/wxParseTemplate8.vue +81 -0
  19. package/other/uParse/components/wxParseTemplate9.vue +81 -0
  20. package/other/uParse/components/wxParseVideo.vue +14 -0
  21. package/other/uParse/editor.css +495 -0
  22. package/{uni-ui/lib/uParse/src → other/uParse}/libs/html2json.js +19 -22
  23. package/{uni-ui/lib/uParse/src → other/uParse}/libs/htmlparser.js +12 -5
  24. package/{uni-ui/lib/uParse/src → other/uParse}/libs/wxDiscode.js +2 -2
  25. package/other/uParse/wxParse.vue +196 -0
  26. package/package.json +1 -1
  27. package/plugins/map/amqp-wx.js +173 -0
  28. package/{uni-ui/lib/mpvueGestureLock/index.vue → ui-cv/components/cv-draw-gesture-lock/cv-draw-gesture-lock.vue} +4 -1
  29. package/ui-cv/components/cv-draw-gesture-lock/gestureLock.js +169 -0
  30. package/{uni-ui/lib/mpvueGestureLock → ui-cv/components/cv-draw-gesture-lock}/style.css +0 -1
  31. package/{uni-ui/lib/mpvue-citypicker → ui-cv/components/cv-geo-region}/style.css +0 -1
  32. package/ui-cv/components/cv-grid-item/cv-grid-item.vue +1 -1
  33. package/uni-ui/lib/uni-badge/uni-badge.vue +150 -1
  34. package/uni-ui/lib/uni-breadcrumb/uni-breadcrumb.vue +37 -1
  35. package/uni-ui/lib/uni-breadcrumb-item/uni-breadcrumb-item.vue +83 -1
  36. package/uni-ui/lib/uni-calendar/uni-calendar-item.vue +122 -1
  37. package/uni-ui/lib/uni-calendar/uni-calendar.vue +366 -1
  38. package/uni-ui/lib/uni-card/uni-card.vue +124 -1
  39. package/uni-ui/lib/uni-col/uni-col.vue +1 -1
  40. package/uni-ui/lib/uni-collapse/uni-collapse.vue +135 -1
  41. package/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue +266 -1
  42. package/uni-ui/lib/uni-combox/uni-combox.vue +1 -1
  43. package/uni-ui/lib/uni-countdown/uni-countdown.vue +239 -1
  44. package/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue +487 -1
  45. package/uni-ui/lib/uni-data-picker/uni-data-picker.vue +530 -1
  46. package/uni-ui/lib/uni-data-pickerview/uni-data-picker.js +157 -150
  47. package/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue +166 -1
  48. package/uni-ui/lib/uni-data-select/uni-data-select.vue +289 -1
  49. package/uni-ui/lib/uni-datetime-picker/calendar-item.vue +70 -1
  50. package/uni-ui/lib/uni-datetime-picker/calendar.vue +629 -1
  51. package/uni-ui/lib/uni-datetime-picker/time-picker.vue +741 -1
  52. package/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +847 -1
  53. package/uni-ui/lib/uni-drawer/uni-drawer.vue +115 -1
  54. package/uni-ui/lib/uni-easyinput/uni-easyinput.vue +515 -1
  55. package/uni-ui/lib/uni-fab/uni-fab.vue +257 -1
  56. package/uni-ui/lib/uni-fav/uni-fav.vue +123 -1
  57. package/uni-ui/lib/uni-file-picker/uni-file-picker.vue +642 -1
  58. package/uni-ui/lib/uni-file-picker/upload-file.vue +177 -1
  59. package/uni-ui/lib/uni-file-picker/upload-image.vue +176 -1
  60. package/uni-ui/lib/uni-forms/uni-forms.vue +375 -1
  61. package/uni-ui/lib/uni-forms-item/uni-forms-item.vue +429 -1
  62. package/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue +129 -1
  63. package/uni-ui/lib/uni-grid/uni-grid.vue +115 -1
  64. package/uni-ui/lib/uni-grid-item/uni-grid-item.vue +78 -1
  65. package/uni-ui/lib/uni-group/uni-group.vue +85 -1
  66. package/uni-ui/lib/uni-icons/uni-icons.vue +85 -1
  67. package/uni-ui/lib/uni-indexed-list/uni-indexed-list-item.vue +68 -1
  68. package/uni-ui/lib/uni-indexed-list/uni-indexed-list.vue +294 -1
  69. package/uni-ui/lib/uni-list/uni-list.vue +81 -1
  70. package/uni-ui/lib/uni-list-ad/uni-list-ad.vue +77 -1
  71. package/uni-ui/lib/uni-list-chat/uni-list-chat.vue +294 -1
  72. package/uni-ui/lib/uni-list-item/uni-list-item.vue +346 -1
  73. package/uni-ui/lib/uni-load-more/uni-load-more.vue +172 -1
  74. package/uni-ui/lib/uni-nav-bar/uni-nav-bar.vue +205 -1
  75. package/uni-ui/lib/uni-nav-bar/uni-status-bar.vue +18 -1
  76. package/uni-ui/lib/uni-notice-bar/uni-notice-bar.vue +331 -1
  77. package/uni-ui/lib/uni-number-box/uni-number-box.vue +166 -1
  78. package/uni-ui/lib/uni-pagination/uni-pagination.vue +323 -1
  79. package/uni-ui/lib/uni-popup/uni-popup.vue +1 -1
  80. package/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue +173 -1
  81. package/uni-ui/lib/uni-popup-message/uni-popup-message.vue +74 -1
  82. package/uni-ui/lib/uni-popup-share/uni-popup-share.vue +106 -1
  83. package/uni-ui/lib/uni-rate/uni-rate.vue +322 -1
  84. package/uni-ui/lib/uni-row/uni-row.vue +1 -1
  85. package/uni-ui/lib/uni-search-bar/uni-search-bar.vue +236 -1
  86. package/uni-ui/lib/uni-section/uni-section.vue +109 -1
  87. package/uni-ui/lib/uni-segmented-control/uni-segmented-control.vue +103 -1
  88. package/uni-ui/lib/uni-status-bar/uni-status-bar.vue +1 -1
  89. package/uni-ui/lib/uni-steps/uni-steps.vue +120 -1
  90. package/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +226 -3
  91. package/uni-ui/lib/uni-swiper-dot/uni-swiper-dot.vue +167 -1
  92. package/uni-ui/lib/uni-table/uni-table.vue +297 -1
  93. package/uni-ui/lib/uni-tag/uni-tag.vue +100 -1
  94. package/uni-ui/lib/uni-td/uni-td.vue +78 -1
  95. package/uni-ui/lib/uni-th/filter-dropdown.vue +1 -1
  96. package/uni-ui/lib/uni-th/uni-th.vue +224 -1
  97. package/uni-ui/lib/uni-thead/uni-thead.vue +77 -1
  98. package/uni-ui/lib/uni-tr/table-checkbox.vue +79 -1
  99. package/uni-ui/lib/uni-tr/uni-tr.vue +135 -1
  100. package/uni-ui/lib/amap-wx/js/util.js +0 -181
  101. package/uni-ui/lib/marked/index.js +0 -1
  102. package/uni-ui/lib/mpvue-citypicker/city-data/area.js +0 -12542
  103. package/uni-ui/lib/mpvue-citypicker/city-data/city.js +0 -1503
  104. package/uni-ui/lib/mpvue-citypicker/city-data/province.js +0 -139
  105. package/uni-ui/lib/mpvue-picker/mpvuePicker.vue +0 -3
  106. package/uni-ui/lib/mpvueGestureLock/gestureLock.js +0 -175
  107. package/uni-ui/lib/uParse/src/components/style.css +0 -2
  108. package/uni-ui/lib/uParse/src/components/wxParseAudio.vue +0 -1
  109. package/uni-ui/lib/uParse/src/components/wxParseImg.vue +0 -1
  110. package/uni-ui/lib/uParse/src/components/wxParseTable.vue +0 -3
  111. package/uni-ui/lib/uParse/src/components/wxParseTemplate0.vue +0 -1
  112. package/uni-ui/lib/uParse/src/components/wxParseTemplate1.vue +0 -1
  113. package/uni-ui/lib/uParse/src/components/wxParseTemplate10.vue +0 -1
  114. package/uni-ui/lib/uParse/src/components/wxParseTemplate11.vue +0 -1
  115. package/uni-ui/lib/uParse/src/components/wxParseTemplate2.vue +0 -1
  116. package/uni-ui/lib/uParse/src/components/wxParseTemplate3.vue +0 -1
  117. package/uni-ui/lib/uParse/src/components/wxParseTemplate4.vue +0 -1
  118. package/uni-ui/lib/uParse/src/components/wxParseTemplate5.vue +0 -1
  119. package/uni-ui/lib/uParse/src/components/wxParseTemplate6.vue +0 -1
  120. package/uni-ui/lib/uParse/src/components/wxParseTemplate7.vue +0 -1
  121. package/uni-ui/lib/uParse/src/components/wxParseTemplate8.vue +0 -1
  122. package/uni-ui/lib/uParse/src/components/wxParseTemplate9.vue +0 -1
  123. package/uni-ui/lib/uParse/src/components/wxParseVideo.vue +0 -1
  124. package/uni-ui/lib/uParse/src/editor.css +0 -495
  125. package/uni-ui/lib/uParse/src/wxParse.vue +0 -1
  126. /package/{uni-ui/lib → other}/api-set-tabbar.nvue +0 -0
  127. /package/{uni-ui/lib → other}/mpvue-echarts/src/echarts.vue +0 -0
  128. /package/{uni-ui/lib → other}/mpvue-echarts/src/style.css +0 -0
  129. /package/{uni-ui/lib → other}/mpvue-echarts/src/wx-canvas.js +0 -0
  130. /package/{uni-ui/lib → other}/product.vue +0 -0
  131. /package/{uni-ui/lib → other}/style.css +0 -0
  132. /package/{uni-ui/lib → other}/tab-nvue/mediaList.vue +0 -0
  133. /package/{uni-ui/lib → other}/u-charts/u-charts.js +0 -0
  134. /package/{uni-ui/lib/uParse/src → other/uParse}/wxParse.css +0 -0
  135. /package/{uni-ui/lib/amap-wx → plugins/map}/lib/amap-wx.js +0 -0
  136. /package/{uni-ui/lib/mpvue-citypicker → ui-cv/components/cv-geo-region}/mpvueCityPicker.vue +0 -0
  137. /package/{uni-ui/lib/marked → ui-cv/components/cv-markdown-show}/lib/marked.js +0 -0
@@ -1 +1,629 @@
1
- <template>
2
1
  <view class="uni-calendar" @mouseleave="leaveCale">
3
2
  <view
4
3
  v-if="!insert && show"
5
4
  class="uni-calendar__mask"
6
5
  :class="{ 'uni-calendar--mask-show': aniMaskShow }"
7
6
  @click="maskClick"
8
7
  ></view>
9
8
  <view
10
9
  v-if="insert || show"
11
10
  class="uni-calendar__content"
12
11
  :class="{
13
12
  'uni-calendar--fixed': !insert,
14
13
  'uni-calendar--ani-show': aniMaskShow,
15
14
  'uni-calendar__content-mobile': aniMaskShow
16
15
  }"
17
16
  >
18
17
  <view class="uni-calendar__header" :class="{ 'uni-calendar__header-mobile': !insert }">
19
18
  <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('pre')">
20
19
  <view class="uni-calendar__header-btn uni-calendar--left"></view>
21
20
  </view>
22
21
  <picker mode="date" :value="date" fields="month" @change="bindDateChange">
23
22
  <text class="uni-calendar__header-text">{{ (nowDate.year || '') + yearText + (nowDate.month || '') + monthText }}</text>
24
23
  </picker>
25
24
  <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('next')">
26
25
  <view class="uni-calendar__header-btn uni-calendar--right"></view>
27
26
  </view>
28
27
  <view v-if="!insert" class="dialog-close" @click="close">
29
28
  <view class="dialog-close-plus" data-id="close"></view>
30
29
  <view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
31
30
  </view>
32
31
  </view>
33
32
  <view class="uni-calendar__box">
34
33
  <view v-if="showMonth" class="uni-calendar__box-bg">
35
34
  <text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
36
35
  </view>
37
36
  <view class="uni-calendar__weeks" style="padding-bottom: 7px">
38
37
  <view class="uni-calendar__weeks-day">
39
38
  <text class="uni-calendar__weeks-day-text">{{ SUNText }}</text>
40
39
  </view>
41
40
  <view class="uni-calendar__weeks-day">
42
41
  <text class="uni-calendar__weeks-day-text">{{ MONText }}</text>
43
42
  </view>
44
43
  <view class="uni-calendar__weeks-day">
45
44
  <text class="uni-calendar__weeks-day-text">{{ TUEText }}</text>
46
45
  </view>
47
46
  <view class="uni-calendar__weeks-day">
48
47
  <text class="uni-calendar__weeks-day-text">{{ WEDText }}</text>
49
48
  </view>
50
49
  <view class="uni-calendar__weeks-day">
51
50
  <text class="uni-calendar__weeks-day-text">{{ THUText }}</text>
52
51
  </view>
53
52
  <view class="uni-calendar__weeks-day">
54
53
  <text class="uni-calendar__weeks-day-text">{{ FRIText }}</text>
55
54
  </view>
56
55
  <view class="uni-calendar__weeks-day">
57
56
  <text class="uni-calendar__weeks-day-text">{{ SATText }}</text>
58
57
  </view>
59
58
  </view>
60
59
  <view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
61
60
  <view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
62
61
  <calendar-item
63
62
  class="uni-calendar-item--hook"
64
63
  :weeks="weeks"
65
64
  :calendar="calendar"
66
65
  :selected="selected"
67
66
  :checkHover="range"
68
67
  @change="choiceDate"
69
68
  @handleMouse="handleMouse"
70
69
  ></calendar-item>
71
70
  </view>
72
71
  </view>
73
72
  </view>
74
73
  <view v-if="!insert && !range && hasTime" class="uni-date-changed uni-calendar--fixed-top" style="padding: 0 80px">
75
74
  <view class="uni-date-changed--time-date">{{ tempSingleDate ? tempSingleDate : selectDateText }}</view>
76
75
  <time-picker
77
76
  type="time"
78
77
  :start="timepickerStartTime"
79
78
  :end="timepickerEndTime"
80
79
  v-model="time"
81
80
  :disabled="!tempSingleDate"
82
81
  :border="false"
83
82
  :hide-second="hideSecond"
84
83
  class="time-picker-style"
85
84
  ></time-picker>
86
85
  </view>
87
86
  <view v-if="!insert && range && hasTime" class="uni-date-changed uni-calendar--fixed-top">
88
87
  <view class="uni-date-changed--time-start">
89
88
  <view class="uni-date-changed--time-date">{{ tempRange.before ? tempRange.before : startDateText }}</view>
90
89
  <time-picker
91
90
  type="time"
92
91
  :start="timepickerStartTime"
93
92
  v-model="timeRange.startTime"
94
93
  :border="false"
95
94
  :hide-second="hideSecond"
96
95
  :disabled="!tempRange.before"
97
96
  class="time-picker-style"
98
97
  ></time-picker>
99
98
  </view>
100
99
  <view style="line-height: 50px">
101
100
  <uni-icons type="arrowthinright" color="#999"></uni-icons>
102
101
  </view>
103
102
  <view class="uni-date-changed--time-end">
104
103
  <view class="uni-date-changed--time-date">{{ tempRange.after ? tempRange.after : endDateText }}</view>
105
104
  <time-picker
106
105
  type="time"
107
106
  :end="timepickerEndTime"
108
107
  v-model="timeRange.endTime"
109
108
  :border="false"
110
109
  :hide-second="hideSecond"
111
110
  :disabled="!tempRange.after"
112
111
  class="time-picker-style"
113
112
  ></time-picker>
114
113
  </view>
115
114
  </view>
116
115
  <view v-if="!insert" class="uni-date-changed uni-date-btn--ok">
117
116
  <view class="uni-datetime-picker--btn" @click="confirm">{{ confirmText }}</view>
118
117
  </view>
119
118
  </view>
120
119
  </view>
121
120
  * Calendar 日历
122
121
  * @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
123
122
  * @tutorial https://ext.dcloud.net.cn/plugin?id=56
124
123
  * @property {String} date 自定义当前时间,默认为今天
125
124
  * @property {String} startDate 日期选择范围-开始日期
126
125
  * @property {String} endDate 日期选择范围-结束日期
127
126
  * @property {Boolean} range 范围选择
128
127
  * @property {Boolean} insert = [true|false] 插入模式,默认为false
129
128
  * @value true 弹窗模式
130
129
  * @value false 插入模式
131
130
  * @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
132
131
  * @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
133
132
  * @property {Boolean} showMonth 是否选择月份为背景
134
133
  * @property {[String} defaultValue 选择器打开时默认显示的时间
135
134
  * @event {Function} change 日期改变,`insert :ture` 时生效
136
135
  * @event {Function} confirm 确认选择`insert :false` 时生效
137
136
  * @event {Function} monthSwitch 切换月份时触发
138
137
  * @example <uni-calendar :insert="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
139
138
  */
140
139
  components: {
141
140
  calendarItem,
142
141
  timePicker
143
142
  },
144
143
  props: {
145
144
  date: {
146
145
  type: String,
147
146
  default: ''
148
147
  },
149
148
  defTime: {
150
149
  type: [String, Object],
151
150
  default: ''
152
151
  },
153
152
  selectableTimes: {
154
153
  type: [Object],
155
154
  default() {
156
155
  return {};
157
156
  }
158
157
  },
159
158
  selected: {
160
159
  type: Array,
161
160
  default() {
162
161
  return [];
163
162
  }
164
163
  },
165
164
  startDate: {
166
165
  type: String,
167
166
  default: ''
168
167
  },
169
168
  endDate: {
170
169
  type: String,
171
170
  default: ''
172
171
  },
173
172
  startPlaceholder: {
174
173
  type: String,
175
174
  default: ''
176
175
  },
177
176
  endPlaceholder: {
178
177
  type: String,
179
178
  default: ''
180
179
  },
181
180
  range: {
182
181
  type: Boolean,
183
182
  default: false
184
183
  },
185
184
  hasTime: {
186
185
  type: Boolean,
187
186
  default: false
188
187
  },
189
188
  insert: {
190
189
  type: Boolean,
191
190
  default: true
192
191
  },
193
192
  showMonth: {
194
193
  type: Boolean,
195
194
  default: true
196
195
  },
197
196
  clearDate: {
198
197
  type: Boolean,
199
198
  default: true
200
199
  },
201
200
  checkHover: {
202
201
  type: Boolean,
203
202
  default: true
204
203
  },
205
204
  hideSecond: {
206
205
  type: [Boolean],
207
206
  default: false
208
207
  },
209
208
  pleStatus: {
210
209
  type: Object,
211
210
  default() {
212
211
  return {
213
212
  before: '',
214
213
  after: '',
215
214
  data: [],
216
215
  fulldate: ''
217
216
  };
218
217
  }
219
218
  },
220
219
  defaultValue: {
221
220
  type: [String, Object, Array],
222
221
  default: ''
223
222
  }
224
223
  },
225
224
  data() {
226
225
  return {
227
226
  show: false,
228
227
  weeks: [],
229
228
  calendar: {},
230
229
  nowDate: {},
231
230
  aniMaskShow: false,
232
231
  firstEnter: true,
233
232
  time: '',
234
233
  timeRange: {
235
234
  startTime: '',
236
235
  endTime: ''
237
236
  },
238
237
  tempSingleDate: '',
239
238
  tempRange: {
240
239
  before: '',
241
240
  after: ''
242
241
  },
243
242
  isPhone: false
244
243
  };
245
244
  },
246
245
  watch: {
247
246
  date: {
248
247
  immediate: true,
249
248
  handler(newVal) {
250
249
  if (!this.range) {
251
250
  this.tempSingleDate = newVal;
252
251
  setTimeout(() => {
253
252
  this.init(newVal);
254
253
  }, 100);
255
254
  }
256
255
  }
257
256
  },
258
257
  defTime: {
259
258
  immediate: true,
260
259
  handler(newVal) {
261
260
  if (!this.range) {
262
261
  this.time = newVal;
263
262
  } else {
264
263
  this.timeRange.startTime = newVal.start;
265
264
  this.timeRange.endTime = newVal.end;
266
265
  }
267
266
  }
268
267
  },
269
268
  startDate(val) {
270
269
  // 字节小程序 watch 早于 created
271
270
  if (!this.cale) {
272
271
  return;
273
272
  }
274
273
  this.cale.setStartDate(val);
275
274
  this.cale.setDate(this.nowDate.fullDate);
276
275
  this.weeks = this.cale.weeks;
277
276
  },
278
277
  endDate(val) {
279
278
  // 字节小程序 watch 早于 created
280
279
  if (!this.cale) {
281
280
  return;
282
281
  }
283
282
  this.cale.setEndDate(val);
284
283
  this.cale.setDate(this.nowDate.fullDate);
285
284
  this.weeks = this.cale.weeks;
286
285
  },
287
286
  selected(newVal) {
288
287
  // 字节小程序 watch 早于 created
289
288
  if (!this.cale) {
290
289
  return;
291
290
  }
292
291
  this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
293
292
  this.weeks = this.cale.weeks;
294
293
  },
295
294
  pleStatus: {
296
295
  immediate: true,
297
296
  handler(newVal) {
298
297
  const { before, after, fulldate, which } = newVal;
299
298
  this.tempRange.before = before;
300
299
  this.tempRange.after = after;
301
300
  setTimeout(() => {
302
301
  if (fulldate) {
303
302
  this.cale.setHoverMultiple(fulldate);
304
303
  if (before && after) {
305
304
  this.cale.lastHover = true;
306
305
  if (this.rangeWithinMonth(after, before)) return;
307
306
  this.setDate(before);
308
307
  } else {
309
308
  this.cale.setMultiple(fulldate);
310
309
  this.setDate(this.nowDate.fullDate);
311
310
  this.calendar.fullDate = '';
312
311
  this.cale.lastHover = false;
313
312
  }
314
313
  } else {
315
314
  // 字节小程序 watch 早于 created
316
315
  if (!this.cale) {
317
316
  return;
318
317
  }
319
318
  this.cale.setDefaultMultiple(before, after);
320
319
  if (which === 'left' && before) {
321
320
  this.setDate(before);
322
321
  this.weeks = this.cale.weeks;
323
322
  } else if (after) {
324
323
  this.setDate(after);
325
324
  this.weeks = this.cale.weeks;
326
325
  }
327
326
  this.cale.lastHover = true;
328
327
  }
329
328
  }, 16);
330
329
  }
331
330
  }
332
331
  },
333
332
  computed: {
334
333
  timepickerStartTime() {
335
334
  const activeDate = this.range ? this.tempRange.before : this.calendar.fullDate;
336
335
  return activeDate === this.startDate ? this.selectableTimes.start : '';
337
336
  },
338
337
  timepickerEndTime() {
339
338
  const activeDate = this.range ? this.tempRange.after : this.calendar.fullDate;
340
339
  return activeDate === this.endDate ? this.selectableTimes.end : '';
341
340
  },
342
341
  /**
343
342
  * for i18n
344
343
  */
345
344
  selectDateText() {
346
345
  return t('uni-datetime-picker.selectDate');
347
346
  },
348
347
  startDateText() {
349
348
  return this.startPlaceholder || t('uni-datetime-picker.startDate');
350
349
  },
351
350
  endDateText() {
352
351
  return this.endPlaceholder || t('uni-datetime-picker.endDate');
353
352
  },
354
353
  okText() {
355
354
  return t('uni-datetime-picker.ok');
356
355
  },
357
356
  yearText() {
358
357
  return t('uni-datetime-picker.year');
359
358
  },
360
359
  monthText() {
361
360
  return t('uni-datetime-picker.month');
362
361
  },
363
362
  MONText() {
364
363
  return t('uni-calender.MON');
365
364
  },
366
365
  TUEText() {
367
366
  return t('uni-calender.TUE');
368
367
  },
369
368
  WEDText() {
370
369
  return t('uni-calender.WED');
371
370
  },
372
371
  THUText() {
373
372
  return t('uni-calender.THU');
374
373
  },
375
374
  FRIText() {
376
375
  return t('uni-calender.FRI');
377
376
  },
378
377
  SATText() {
379
378
  return t('uni-calender.SAT');
380
379
  },
381
380
  SUNText() {
382
381
  return t('uni-calender.SUN');
383
382
  },
384
383
  confirmText() {
385
384
  return t('uni-calender.confirm');
386
385
  }
387
386
  },
388
387
  created() {
389
388
  // 获取日历方法实例
390
389
  this.cale = new Calendar({
391
390
  selected: this.selected,
392
391
  startDate: this.startDate,
393
392
  endDate: this.endDate,
394
393
  range: this.range
395
394
  });
396
395
  // 选中某一天
397
396
  this.init(this.date);
398
397
  },
399
398
  mounted() {
400
399
  if (typeof navigator !== 'undefined') {
401
400
  this.isPhone = navigator.userAgent.toLowerCase().indexOf('mobile') !== -1;
402
401
  return;
403
402
  }
404
403
  const { windowWidth } = uni.getSystemInfoSync();
405
404
  this.isPhone = windowWidth <= 500;
406
405
  },
407
406
  methods: {
408
407
  leaveCale() {
409
408
  this.firstEnter = true;
410
409
  },
411
410
  handleMouse(weeks) {
412
411
  if (weeks.disable) return;
413
412
  if (this.cale.lastHover) return;
414
413
  let { before, after } = this.cale.multipleStatus;
415
414
  if (!before) return;
416
415
  this.calendar = weeks;
417
416
  // 设置范围选
418
417
  this.cale.setHoverMultiple(this.calendar.fullDate);
419
418
  this.weeks = this.cale.weeks;
420
419
  // hover时,进入一个日历,更新另一个
421
420
  if (this.firstEnter) {
422
421
  this.$emit('firstEnterCale', this.cale.multipleStatus);
423
422
  this.firstEnter = false;
424
423
  }
425
424
  },
426
425
  rangeWithinMonth(A, B) {
427
426
  const [yearA, monthA] = A.split('-');
428
427
  const [yearB, monthB] = B.split('-');
429
428
  return yearA === yearB && monthA === monthB;
430
429
  },
431
430
  // 蒙版点击事件
432
431
  maskClick() {
433
432
  this.close();
434
433
  this.$emit('maskClose');
435
434
  },
436
435
  clearCalender() {
437
436
  if (this.range) {
438
437
  this.timeRange.startTime = '';
439
438
  this.timeRange.endTime = '';
440
439
  this.tempRange.before = '';
441
440
  this.tempRange.after = '';
442
441
  this.cale.multipleStatus.before = '';
443
442
  this.cale.multipleStatus.after = '';
444
443
  this.cale.multipleStatus.data = [];
445
444
  this.cale.lastHover = false;
446
445
  } else {
447
446
  this.time = '';
448
447
  this.tempSingleDate = '';
449
448
  }
450
449
  this.calendar.fullDate = '';
451
450
  this.setDate(new Date());
452
451
  },
453
452
  bindDateChange(e) {
454
453
  const value = e.detail.value + '-1';
455
454
  this.setDate(value);
456
455
  },
457
456
  /**
458
457
  * 初始化日期显示
459
458
  * @param {Object} date
460
459
  */
461
460
  init(date) {
462
461
  // 字节小程序 watch 早于 created
463
462
  if (!this.cale) {
464
463
  return;
465
464
  }
466
465
  this.cale.setDate(date || new Date());
467
466
  this.weeks = this.cale.weeks;
468
467
  this.nowDate = this.cale.getInfo(date);
469
468
  this.calendar = { ...this.nowDate };
470
469
  if (!date) {
471
470
  // 优化date为空默认不选中今天
472
471
  this.calendar.fullDate = '';
473
472
  if (this.defaultValue && !this.range) {
474
473
  // 暂时只支持移动端非范围选择
475
474
  const defaultDate = new Date(this.defaultValue);
476
475
  const fullDate = getDate(defaultDate);
477
476
  const year = defaultDate.getFullYear();
478
477
  const month = defaultDate.getMonth() + 1;
479
478
  const date = defaultDate.getDate();
480
479
  const day = defaultDate.getDay();
481
480
  (this.calendar = {
482
481
  fullDate,
483
482
  year,
484
483
  month,
485
484
  date,
486
485
  day
487
486
  }),
488
487
  (this.tempSingleDate = fullDate);
489
488
  this.time = getTime(defaultDate, this.hideSecond);
490
489
  }
491
490
  }
492
491
  },
493
492
  /**
494
493
  * 打开日历弹窗
495
494
  */
496
495
  open() {
497
496
  // 弹窗模式并且清理数据
498
497
  if (this.clearDate && !this.insert) {
499
498
  this.cale.cleanMultipleStatus();
500
499
  this.init(this.date);
501
500
  }
502
501
  this.show = true;
503
502
  this.$nextTick(() => {
504
503
  setTimeout(() => {
505
504
  this.aniMaskShow = true;
506
505
  }, 50);
507
506
  });
508
507
  },
509
508
  /**
510
509
  * 关闭日历弹窗
511
510
  */
512
511
  close() {
513
512
  this.aniMaskShow = false;
514
513
  this.$nextTick(() => {
515
514
  setTimeout(() => {
516
515
  this.show = false;
517
516
  this.$emit('close');
518
517
  }, 300);
519
518
  });
520
519
  },
521
520
  /**
522
521
  * 确认按钮
523
522
  */
524
523
  confirm() {
525
524
  this.setEmit('confirm');
526
525
  this.close();
527
526
  },
528
527
  /**
529
528
  * 变化触发
530
529
  */
531
530
  change() {
532
531
  if (!this.insert) return;
533
532
  this.setEmit('change');
534
533
  },
535
534
  /**
536
535
  * 选择月份触发
537
536
  */
538
537
  monthSwitch() {
539
538
  let { year, month } = this.nowDate;
540
539
  this.$emit('monthSwitch', {
541
540
  year,
542
541
  month: Number(month)
543
542
  });
544
543
  },
545
544
  /**
546
545
  * 派发事件
547
546
  * @param {Object} name
548
547
  */
549
548
  setEmit(name) {
550
549
  if (!this.range) {
551
550
  if (!this.calendar.fullDate) {
552
551
  this.calendar = this.cale.getInfo(new Date());
553
552
  this.tempSingleDate = this.calendar.fullDate;
554
553
  }
555
554
  if (this.hasTime && !this.time) {
556
555
  this.time = getTime(new Date(), this.hideSecond);
557
556
  }
558
557
  }
559
558
  let { year, month, date, fullDate, extraInfo } = this.calendar;
560
559
  this.$emit(name, {
561
560
  range: this.cale.multipleStatus,
562
561
  year,
563
562
  month,
564
563
  date,
565
564
  time: this.time,
566
565
  timeRange: this.timeRange,
567
566
  fulldate: fullDate,
568
567
  extraInfo: extraInfo || {}
569
568
  });
570
569
  },
571
570
  /**
572
571
  * 选择天触发
573
572
  * @param {Object} weeks
574
573
  */
575
574
  choiceDate(weeks) {
576
575
  if (weeks.disable) return;
577
576
  this.calendar = weeks;
578
577
  this.calendar.userChecked = true;
579
578
  // 设置多选
580
579
  this.cale.setMultiple(this.calendar.fullDate, true);
581
580
  this.weeks = this.cale.weeks;
582
581
  this.tempSingleDate = this.calendar.fullDate;
583
582
  const beforeDate = new Date(this.cale.multipleStatus.before).getTime();
584
583
  const afterDate = new Date(this.cale.multipleStatus.after).getTime();
585
584
  // 这里返回的 before after 为什么要做替换?导致PC端如果开始结束日期都是今天,第一次选择开始日期早于今天,开始日期不更新
586
585
  if (beforeDate > afterDate && afterDate && !this.isPhone) {
587
586
  this.tempRange.before = this.cale.multipleStatus.after;
588
587
  this.tempRange.after = this.cale.multipleStatus.before;
589
588
  } else {
590
589
  this.tempRange.before = this.cale.multipleStatus.before;
591
590
  this.tempRange.after = this.cale.multipleStatus.after;
592
591
  }
593
592
  this.change();
594
593
  },
595
594
  changeMonth(type) {
596
595
  let newDate;
597
596
  if (type === 'pre') {
598
597
  newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate;
599
598
  } else if (type === 'next') {
600
599
  newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate;
601
600
  }
602
601
  this.setDate(newDate);
603
602
  this.monthSwitch();
604
603
  },
605
604
  /**
606
605
  * 设置日期
607
606
  * @param {Object} date
608
607
  */
609
608
  setDate(date) {
610
609
  this.cale.setDate(date);
611
610
  this.weeks = this.cale.weeks;
612
611
  this.nowDate = this.cale.getInfo(date);
613
612
  }
614
613
  }
614
+ <template>
615
+ <view class="uni-calendar" @mouseleave="leaveCale">
616
+ <view
617
+ v-if="!insert && show"
618
+ class="uni-calendar__mask"
619
+ :class="{ 'uni-calendar--mask-show': aniMaskShow }"
620
+ @click="maskClick"
621
+ ></view>
622
+ <view
623
+ v-if="insert || show"
624
+ class="uni-calendar__content"
625
+ :class="{
626
+ 'uni-calendar--fixed': !insert,
627
+ 'uni-calendar--ani-show': aniMaskShow,
628
+ 'uni-calendar__content-mobile': aniMaskShow
629
+ }"
630
+ >
631
+ <view class="uni-calendar__header" :class="{ 'uni-calendar__header-mobile': !insert }">
632
+ <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('pre')">
633
+ <view class="uni-calendar__header-btn uni-calendar--left"></view>
634
+ </view>
635
+ <picker mode="date" :value="date" fields="month" @change="bindDateChange">
636
+ <text class="uni-calendar__header-text">{{ (nowDate.year || '') + yearText + (nowDate.month || '') + monthText }}</text>
637
+ </picker>
638
+ <view class="uni-calendar__header-btn-box" @click.stop="changeMonth('next')">
639
+ <view class="uni-calendar__header-btn uni-calendar--right"></view>
640
+ </view>
641
+ <view v-if="!insert" class="dialog-close" @click="close">
642
+ <view class="dialog-close-plus" data-id="close"></view>
643
+ <view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
644
+ </view>
645
+ </view>
646
+ <view class="uni-calendar__box">
647
+ <view v-if="showMonth" class="uni-calendar__box-bg">
648
+ <text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
649
+ </view>
650
+ <view class="uni-calendar__weeks" style="padding-bottom: 7px">
651
+ <view class="uni-calendar__weeks-day">
652
+ <text class="uni-calendar__weeks-day-text">{{ SUNText }}</text>
653
+ </view>
654
+ <view class="uni-calendar__weeks-day">
655
+ <text class="uni-calendar__weeks-day-text">{{ MONText }}</text>
656
+ </view>
657
+ <view class="uni-calendar__weeks-day">
658
+ <text class="uni-calendar__weeks-day-text">{{ TUEText }}</text>
659
+ </view>
660
+ <view class="uni-calendar__weeks-day">
661
+ <text class="uni-calendar__weeks-day-text">{{ WEDText }}</text>
662
+ </view>
663
+ <view class="uni-calendar__weeks-day">
664
+ <text class="uni-calendar__weeks-day-text">{{ THUText }}</text>
665
+ </view>
666
+ <view class="uni-calendar__weeks-day">
667
+ <text class="uni-calendar__weeks-day-text">{{ FRIText }}</text>
668
+ </view>
669
+ <view class="uni-calendar__weeks-day">
670
+ <text class="uni-calendar__weeks-day-text">{{ SATText }}</text>
671
+ </view>
672
+ </view>
673
+ <view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
674
+ <view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
675
+ <calendar-item
676
+ class="uni-calendar-item--hook"
677
+ :weeks="weeks"
678
+ :calendar="calendar"
679
+ :selected="selected"
680
+ :checkHover="range"
681
+ @change="choiceDate"
682
+ @handleMouse="handleMouse"
683
+ ></calendar-item>
684
+ </view>
685
+ </view>
686
+ </view>
687
+ <view v-if="!insert && !range && hasTime" class="uni-date-changed uni-calendar--fixed-top" style="padding: 0 80px">
688
+ <view class="uni-date-changed--time-date">{{ tempSingleDate ? tempSingleDate : selectDateText }}</view>
689
+ <time-picker
690
+ type="time"
691
+ :start="timepickerStartTime"
692
+ :end="timepickerEndTime"
693
+ v-model="time"
694
+ :disabled="!tempSingleDate"
695
+ :border="false"
696
+ :hide-second="hideSecond"
697
+ class="time-picker-style"
698
+ ></time-picker>
699
+ </view>
700
+ <view v-if="!insert && range && hasTime" class="uni-date-changed uni-calendar--fixed-top">
701
+ <view class="uni-date-changed--time-start">
702
+ <view class="uni-date-changed--time-date">{{ tempRange.before ? tempRange.before : startDateText }}</view>
703
+ <time-picker
704
+ type="time"
705
+ :start="timepickerStartTime"
706
+ v-model="timeRange.startTime"
707
+ :border="false"
708
+ :hide-second="hideSecond"
709
+ :disabled="!tempRange.before"
710
+ class="time-picker-style"
711
+ ></time-picker>
712
+ </view>
713
+ <view style="line-height: 50px">
714
+ <uni-icons type="arrowthinright" color="#999"></uni-icons>
715
+ </view>
716
+ <view class="uni-date-changed--time-end">
717
+ <view class="uni-date-changed--time-date">{{ tempRange.after ? tempRange.after : endDateText }}</view>
718
+ <time-picker
719
+ type="time"
720
+ :end="timepickerEndTime"
721
+ v-model="timeRange.endTime"
722
+ :border="false"
723
+ :hide-second="hideSecond"
724
+ :disabled="!tempRange.after"
725
+ class="time-picker-style"
726
+ ></time-picker>
727
+ </view>
728
+ </view>
729
+ <view v-if="!insert" class="uni-date-changed uni-date-btn--ok">
730
+ <view class="uni-datetime-picker--btn" @click="confirm">{{ confirmText }}</view>
731
+ </view>
732
+ </view>
733
+ </view>
734
+ </template>
735
+ <script>
736
+ import { Calendar, getDate, getTime } from './util.js';
737
+ import calendarItem from './calendar-item.vue';
738
+ import timePicker from './time-picker.vue';
739
+ import { initVueI18n } from '@dcloudio/uni-i18n';
740
+ import i18nMessages from './i18n/index.js';
741
+ const { t } = initVueI18n(i18nMessages);
742
+ /**
743
+ * Calendar 日历
744
+ * @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
745
+ * @tutorial https://ext.dcloud.net.cn/plugin?id=56
746
+ * @property {String} date 自定义当前时间,默认为今天
747
+ * @property {String} startDate 日期选择范围-开始日期
748
+ * @property {String} endDate 日期选择范围-结束日期
749
+ * @property {Boolean} range 范围选择
750
+ * @property {Boolean} insert = [true|false] 插入模式,默认为false
751
+ * @value true 弹窗模式
752
+ * @value false 插入模式
753
+ * @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
754
+ * @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
755
+ * @property {Boolean} showMonth 是否选择月份为背景
756
+ * @property {[String} defaultValue 选择器打开时默认显示的时间
757
+ * @event {Function} change 日期改变,`insert :ture` 时生效
758
+ * @event {Function} confirm 确认选择`insert :false` 时生效
759
+ * @event {Function} monthSwitch 切换月份时触发
760
+ * @example <uni-calendar :insert="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
761
+ */
762
+ export default {
763
+ components: {
764
+ calendarItem,
765
+ timePicker
766
+ },
767
+ props: {
768
+ date: {
769
+ type: String,
770
+ default: ''
771
+ },
772
+ defTime: {
773
+ type: [String, Object],
774
+ default: ''
775
+ },
776
+ selectableTimes: {
777
+ type: [Object],
778
+ default() {
779
+ return {};
780
+ }
781
+ },
782
+ selected: {
783
+ type: Array,
784
+ default() {
785
+ return [];
786
+ }
787
+ },
788
+ startDate: {
789
+ type: String,
790
+ default: ''
791
+ },
792
+ endDate: {
793
+ type: String,
794
+ default: ''
795
+ },
796
+ startPlaceholder: {
797
+ type: String,
798
+ default: ''
799
+ },
800
+ endPlaceholder: {
801
+ type: String,
802
+ default: ''
803
+ },
804
+ range: {
805
+ type: Boolean,
806
+ default: false
807
+ },
808
+ hasTime: {
809
+ type: Boolean,
810
+ default: false
811
+ },
812
+ insert: {
813
+ type: Boolean,
814
+ default: true
815
+ },
816
+ showMonth: {
817
+ type: Boolean,
818
+ default: true
819
+ },
820
+ clearDate: {
821
+ type: Boolean,
822
+ default: true
823
+ },
824
+ checkHover: {
825
+ type: Boolean,
826
+ default: true
827
+ },
828
+ hideSecond: {
829
+ type: [Boolean],
830
+ default: false
831
+ },
832
+ pleStatus: {
833
+ type: Object,
834
+ default() {
835
+ return {
836
+ before: '',
837
+ after: '',
838
+ data: [],
839
+ fulldate: ''
840
+ };
841
+ }
842
+ },
843
+ defaultValue: {
844
+ type: [String, Object, Array],
845
+ default: ''
846
+ }
847
+ },
848
+ data() {
849
+ return {
850
+ show: false,
851
+ weeks: [],
852
+ calendar: {},
853
+ nowDate: {},
854
+ aniMaskShow: false,
855
+ firstEnter: true,
856
+ time: '',
857
+ timeRange: {
858
+ startTime: '',
859
+ endTime: ''
860
+ },
861
+ tempSingleDate: '',
862
+ tempRange: {
863
+ before: '',
864
+ after: ''
865
+ },
866
+ isPhone: false
867
+ };
868
+ },
869
+ watch: {
870
+ date: {
871
+ immediate: true,
872
+ handler(newVal) {
873
+ if (!this.range) {
874
+ this.tempSingleDate = newVal;
875
+ setTimeout(() => {
876
+ this.init(newVal);
877
+ }, 100);
878
+ }
879
+ }
880
+ },
881
+ defTime: {
882
+ immediate: true,
883
+ handler(newVal) {
884
+ if (!this.range) {
885
+ this.time = newVal;
886
+ } else {
887
+ this.timeRange.startTime = newVal.start;
888
+ this.timeRange.endTime = newVal.end;
889
+ }
890
+ }
891
+ },
892
+ startDate(val) {
893
+ // 字节小程序 watch 早于 created
894
+ if (!this.cale) {
895
+ return;
896
+ }
897
+ this.cale.setStartDate(val);
898
+ this.cale.setDate(this.nowDate.fullDate);
899
+ this.weeks = this.cale.weeks;
900
+ },
901
+ endDate(val) {
902
+ // 字节小程序 watch 早于 created
903
+ if (!this.cale) {
904
+ return;
905
+ }
906
+ this.cale.setEndDate(val);
907
+ this.cale.setDate(this.nowDate.fullDate);
908
+ this.weeks = this.cale.weeks;
909
+ },
910
+ selected(newVal) {
911
+ // 字节小程序 watch 早于 created
912
+ if (!this.cale) {
913
+ return;
914
+ }
915
+ this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
916
+ this.weeks = this.cale.weeks;
917
+ },
918
+ pleStatus: {
919
+ immediate: true,
920
+ handler(newVal) {
921
+ const { before, after, fulldate, which } = newVal;
922
+ this.tempRange.before = before;
923
+ this.tempRange.after = after;
924
+ setTimeout(() => {
925
+ if (fulldate) {
926
+ this.cale.setHoverMultiple(fulldate);
927
+ if (before && after) {
928
+ this.cale.lastHover = true;
929
+ if (this.rangeWithinMonth(after, before)) return;
930
+ this.setDate(before);
931
+ } else {
932
+ this.cale.setMultiple(fulldate);
933
+ this.setDate(this.nowDate.fullDate);
934
+ this.calendar.fullDate = '';
935
+ this.cale.lastHover = false;
936
+ }
937
+ } else {
938
+ // 字节小程序 watch 早于 created
939
+ if (!this.cale) {
940
+ return;
941
+ }
942
+ this.cale.setDefaultMultiple(before, after);
943
+ if (which === 'left' && before) {
944
+ this.setDate(before);
945
+ this.weeks = this.cale.weeks;
946
+ } else if (after) {
947
+ this.setDate(after);
948
+ this.weeks = this.cale.weeks;
949
+ }
950
+ this.cale.lastHover = true;
951
+ }
952
+ }, 16);
953
+ }
954
+ }
955
+ },
956
+ computed: {
957
+ timepickerStartTime() {
958
+ const activeDate = this.range ? this.tempRange.before : this.calendar.fullDate;
959
+ return activeDate === this.startDate ? this.selectableTimes.start : '';
960
+ },
961
+ timepickerEndTime() {
962
+ const activeDate = this.range ? this.tempRange.after : this.calendar.fullDate;
963
+ return activeDate === this.endDate ? this.selectableTimes.end : '';
964
+ },
965
+ /**
966
+ * for i18n
967
+ */
968
+ selectDateText() {
969
+ return t('uni-datetime-picker.selectDate');
970
+ },
971
+ startDateText() {
972
+ return this.startPlaceholder || t('uni-datetime-picker.startDate');
973
+ },
974
+ endDateText() {
975
+ return this.endPlaceholder || t('uni-datetime-picker.endDate');
976
+ },
977
+ okText() {
978
+ return t('uni-datetime-picker.ok');
979
+ },
980
+ yearText() {
981
+ return t('uni-datetime-picker.year');
982
+ },
983
+ monthText() {
984
+ return t('uni-datetime-picker.month');
985
+ },
986
+ MONText() {
987
+ return t('uni-calender.MON');
988
+ },
989
+ TUEText() {
990
+ return t('uni-calender.TUE');
991
+ },
992
+ WEDText() {
993
+ return t('uni-calender.WED');
994
+ },
995
+ THUText() {
996
+ return t('uni-calender.THU');
997
+ },
998
+ FRIText() {
999
+ return t('uni-calender.FRI');
1000
+ },
1001
+ SATText() {
1002
+ return t('uni-calender.SAT');
1003
+ },
1004
+ SUNText() {
1005
+ return t('uni-calender.SUN');
1006
+ },
1007
+ confirmText() {
1008
+ return t('uni-calender.confirm');
1009
+ }
1010
+ },
1011
+ created() {
1012
+ // 获取日历方法实例
1013
+ this.cale = new Calendar({
1014
+ selected: this.selected,
1015
+ startDate: this.startDate,
1016
+ endDate: this.endDate,
1017
+ range: this.range
1018
+ });
1019
+ // 选中某一天
1020
+ this.init(this.date);
1021
+ },
1022
+ mounted() {
1023
+ if (typeof navigator !== 'undefined') {
1024
+ this.isPhone = navigator.userAgent.toLowerCase().indexOf('mobile') !== -1;
1025
+ return;
1026
+ }
1027
+ const { windowWidth } = uni.getSystemInfoSync();
1028
+ this.isPhone = windowWidth <= 500;
1029
+ },
1030
+ methods: {
1031
+ leaveCale() {
1032
+ this.firstEnter = true;
1033
+ },
1034
+ handleMouse(weeks) {
1035
+ if (weeks.disable) return;
1036
+ if (this.cale.lastHover) return;
1037
+ let { before, after } = this.cale.multipleStatus;
1038
+ if (!before) return;
1039
+ this.calendar = weeks;
1040
+ // 设置范围选
1041
+ this.cale.setHoverMultiple(this.calendar.fullDate);
1042
+ this.weeks = this.cale.weeks;
1043
+ // hover时,进入一个日历,更新另一个
1044
+ if (this.firstEnter) {
1045
+ this.$emit('firstEnterCale', this.cale.multipleStatus);
1046
+ this.firstEnter = false;
1047
+ }
1048
+ },
1049
+ rangeWithinMonth(A, B) {
1050
+ const [yearA, monthA] = A.split('-');
1051
+ const [yearB, monthB] = B.split('-');
1052
+ return yearA === yearB && monthA === monthB;
1053
+ },
1054
+ // 蒙版点击事件
1055
+ maskClick() {
1056
+ this.close();
1057
+ this.$emit('maskClose');
1058
+ },
1059
+ clearCalender() {
1060
+ if (this.range) {
1061
+ this.timeRange.startTime = '';
1062
+ this.timeRange.endTime = '';
1063
+ this.tempRange.before = '';
1064
+ this.tempRange.after = '';
1065
+ this.cale.multipleStatus.before = '';
1066
+ this.cale.multipleStatus.after = '';
1067
+ this.cale.multipleStatus.data = [];
1068
+ this.cale.lastHover = false;
1069
+ } else {
1070
+ this.time = '';
1071
+ this.tempSingleDate = '';
1072
+ }
1073
+ this.calendar.fullDate = '';
1074
+ this.setDate(new Date());
1075
+ },
1076
+ bindDateChange(e) {
1077
+ const value = e.detail.value + '-1';
1078
+ this.setDate(value);
1079
+ },
1080
+ /**
1081
+ * 初始化日期显示
1082
+ * @param {Object} date
1083
+ */
1084
+ init(date) {
1085
+ // 字节小程序 watch 早于 created
1086
+ if (!this.cale) {
1087
+ return;
1088
+ }
1089
+ this.cale.setDate(date || new Date());
1090
+ this.weeks = this.cale.weeks;
1091
+ this.nowDate = this.cale.getInfo(date);
1092
+ this.calendar = { ...this.nowDate };
1093
+ if (!date) {
1094
+ // 优化date为空默认不选中今天
1095
+ this.calendar.fullDate = '';
1096
+ if (this.defaultValue && !this.range) {
1097
+ // 暂时只支持移动端非范围选择
1098
+ const defaultDate = new Date(this.defaultValue);
1099
+ const fullDate = getDate(defaultDate);
1100
+ const year = defaultDate.getFullYear();
1101
+ const month = defaultDate.getMonth() + 1;
1102
+ const date = defaultDate.getDate();
1103
+ const day = defaultDate.getDay();
1104
+ (this.calendar = {
1105
+ fullDate,
1106
+ year,
1107
+ month,
1108
+ date,
1109
+ day
1110
+ }),
1111
+ (this.tempSingleDate = fullDate);
1112
+ this.time = getTime(defaultDate, this.hideSecond);
1113
+ }
1114
+ }
1115
+ },
1116
+ /**
1117
+ * 打开日历弹窗
1118
+ */
1119
+ open() {
1120
+ // 弹窗模式并且清理数据
1121
+ if (this.clearDate && !this.insert) {
1122
+ this.cale.cleanMultipleStatus();
1123
+ this.init(this.date);
1124
+ }
1125
+ this.show = true;
1126
+ this.$nextTick(() => {
1127
+ setTimeout(() => {
1128
+ this.aniMaskShow = true;
1129
+ }, 50);
1130
+ });
1131
+ },
1132
+ /**
1133
+ * 关闭日历弹窗
1134
+ */
1135
+ close() {
1136
+ this.aniMaskShow = false;
1137
+ this.$nextTick(() => {
1138
+ setTimeout(() => {
1139
+ this.show = false;
1140
+ this.$emit('close');
1141
+ }, 300);
1142
+ });
1143
+ },
1144
+ /**
1145
+ * 确认按钮
1146
+ */
1147
+ confirm() {
1148
+ this.setEmit('confirm');
1149
+ this.close();
1150
+ },
1151
+ /**
1152
+ * 变化触发
1153
+ */
1154
+ change() {
1155
+ if (!this.insert) return;
1156
+ this.setEmit('change');
1157
+ },
1158
+ /**
1159
+ * 选择月份触发
1160
+ */
1161
+ monthSwitch() {
1162
+ let { year, month } = this.nowDate;
1163
+ this.$emit('monthSwitch', {
1164
+ year,
1165
+ month: Number(month)
1166
+ });
1167
+ },
1168
+ /**
1169
+ * 派发事件
1170
+ * @param {Object} name
1171
+ */
1172
+ setEmit(name) {
1173
+ if (!this.range) {
1174
+ if (!this.calendar.fullDate) {
1175
+ this.calendar = this.cale.getInfo(new Date());
1176
+ this.tempSingleDate = this.calendar.fullDate;
1177
+ }
1178
+ if (this.hasTime && !this.time) {
1179
+ this.time = getTime(new Date(), this.hideSecond);
1180
+ }
1181
+ }
1182
+ let { year, month, date, fullDate, extraInfo } = this.calendar;
1183
+ this.$emit(name, {
1184
+ range: this.cale.multipleStatus,
1185
+ year,
1186
+ month,
1187
+ date,
1188
+ time: this.time,
1189
+ timeRange: this.timeRange,
1190
+ fulldate: fullDate,
1191
+ extraInfo: extraInfo || {}
1192
+ });
1193
+ },
1194
+ /**
1195
+ * 选择天触发
1196
+ * @param {Object} weeks
1197
+ */
1198
+ choiceDate(weeks) {
1199
+ if (weeks.disable) return;
1200
+ this.calendar = weeks;
1201
+ this.calendar.userChecked = true;
1202
+ // 设置多选
1203
+ this.cale.setMultiple(this.calendar.fullDate, true);
1204
+ this.weeks = this.cale.weeks;
1205
+ this.tempSingleDate = this.calendar.fullDate;
1206
+ const beforeDate = new Date(this.cale.multipleStatus.before).getTime();
1207
+ const afterDate = new Date(this.cale.multipleStatus.after).getTime();
1208
+ // 这里返回的 before after 为什么要做替换?导致PC端如果开始结束日期都是今天,第一次选择开始日期早于今天,开始日期不更新
1209
+ if (beforeDate > afterDate && afterDate && !this.isPhone) {
1210
+ this.tempRange.before = this.cale.multipleStatus.after;
1211
+ this.tempRange.after = this.cale.multipleStatus.before;
1212
+ } else {
1213
+ this.tempRange.before = this.cale.multipleStatus.before;
1214
+ this.tempRange.after = this.cale.multipleStatus.after;
1215
+ }
1216
+ this.change();
1217
+ },
1218
+ changeMonth(type) {
1219
+ let newDate;
1220
+ if (type === 'pre') {
1221
+ newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate;
1222
+ } else if (type === 'next') {
1223
+ newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate;
1224
+ }
1225
+ this.setDate(newDate);
1226
+ this.monthSwitch();
1227
+ },
1228
+ /**
1229
+ * 设置日期
1230
+ * @param {Object} date
1231
+ */
1232
+ setDate(date) {
1233
+ this.cale.setDate(date);
1234
+ this.weeks = this.cale.weeks;
1235
+ this.nowDate = this.cale.getInfo(date);
1236
+ }
1237
+ }
1238
+ };
1239
+ </script>
1240
+ <style>
1241
+ @import 'style.css';
1242
+ </style>