com-time-select.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <style>
  2. .com-time-select {
  3. width: 760px;
  4. margin-top: 12px;
  5. border: 1px solid #cccccc;
  6. }
  7. .item-box {
  8. display: flex;
  9. }
  10. .top-box {
  11. height: 50px;
  12. border-bottom: 1px solid #cccccc;
  13. }
  14. .bottom-box {
  15. height: 250px;
  16. }
  17. .left-box {
  18. width: 22%;
  19. background-color: #f5f6fa;
  20. border-right: 1px solid #cccccc;
  21. }
  22. .right-box {
  23. width: 78%;
  24. }
  25. .el-dropdown-link {
  26. cursor: pointer;
  27. color: #409EFF;
  28. }
  29. .el-icon-arrow-down {
  30. font-size: 12px;
  31. }
  32. .not-scroll {
  33. display: flex;
  34. justify-content: center;
  35. align-items: center;
  36. }
  37. .scroll-box {
  38. overflow-y: scroll;
  39. }
  40. .date-item {
  41. padding: 10px 4px;
  42. text-align: center;
  43. border-bottom: 1px solid #cccccc;
  44. cursor: pointer;
  45. }
  46. .selected {
  47. background-color: #ffffff;
  48. font-weight: bold;
  49. }
  50. .date-item:last-child {
  51. border-bottom: none;
  52. }
  53. .top-right {
  54. display: flex;
  55. justify-content: space-between;
  56. align-items: center;
  57. }
  58. .bottom-right {
  59. }
  60. .time-select-box {
  61. }
  62. .time-select-item {
  63. display: flex;
  64. align-items: center;
  65. }
  66. .label-box {
  67. }
  68. .select-box {
  69. margin-right: 12px;
  70. }
  71. .time {
  72. display: inline-block;
  73. margin-bottom: 10px;
  74. margin-right: 10px;
  75. padding: 4px 10px;
  76. border: 1px solid #409EFF;
  77. border-radius: 6px;
  78. }
  79. .time-txt {
  80. display: inline-block;
  81. }
  82. .del-btn {
  83. display: inline-block;
  84. width: 18px;
  85. height: 18px;
  86. margin-left: 6px;
  87. border-radius: 50%;
  88. text-align: center;
  89. line-height: 18px;
  90. background-color: #666666;
  91. font-size: 18px;
  92. color: #ffffff;
  93. cursor: pointer;
  94. }
  95. .right-top-form {
  96. height: 50px;
  97. display: flex;
  98. align-items: center;
  99. }
  100. .form-item {
  101. width: 48%;
  102. }
  103. .btn {
  104. width: 9%;
  105. }
  106. .right-bottom-list {
  107. margin-top: 6px;
  108. }
  109. .all-select {
  110. }
  111. .all-box {
  112. height: 140px;
  113. overflow-y: scroll;
  114. }
  115. </style>
  116. <template id="com-time-select">
  117. <div class="com-time-select">
  118. <div class="item-box top-box">
  119. <div class="left-box not-scroll">
  120. <el-dropdown @command="handleCommand">
  121. <span class="el-dropdown-link">
  122. {{settingType.name}}<i class="el-icon-arrow-down el-icon--right"></i>
  123. </span>
  124. <el-dropdown-menu slot="dropdown">
  125. <el-dropdown-item v-for="(item,index) in settingTypes" :key="index" :command="item.val">{{item.name}}</el-dropdown-item>
  126. </el-dropdown-menu>
  127. </el-dropdown>
  128. </div>
  129. <div class="right-box top-right">
  130. <div>设置时间段</div>
  131. <div v-if="slotType == 1" style="color: #409EFF;cursor: pointer;" @click="onShowAdd">+ 添加时间段</div>
  132. </div>
  133. </div>
  134. <div class="item-box bottom-box">
  135. <div v-if="settingType.val == 1" class="left-box scroll-box">
  136. <div v-for="(item,index) in selectedDates" :key="index" class="date-item" :class="item.isSelect ? 'selected' : ''" @click="onDate(index)">{{item.date}}</div>
  137. </div>
  138. <div v-if="settingType.val == 2" class="left-box not-scroll">每天</div>
  139. <div v-if="slotType == 1 && timeList && timeList.length" class="right-box bottom-right scroll-box">
  140. <span v-for="(item,index) in timeList" :key="index" class="time">
  141. <span class="time-txt">{{item}}</span>
  142. <span class="del-btn" @click="delTimeItem(index)">×</span>
  143. </span>
  144. </div>
  145. <div v-if="slotType == 1 && timeList && !timeList.length" class="right-box">请选择时间段</div>
  146. <div v-if="slotType == 2" class="right-box">
  147. <div class="right-top-form">
  148. <div class="form-item">起止时间:
  149. <el-time-picker is-range v-model="timeRange" range-separator="-" :value-format="pickerFormatText" :format="pickerFormatText" :picker-options="{ selectableRange: '00:00:00 - 23:59:00', format: pickerFormatText }" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围" size="small" style="width: 200px;" @change="onAutoRangeChange"></el-time-picker>
  150. </div>
  151. <div class="form-item" style="width: 41%;">时间跨度:
  152. <el-input placeholder="请输入时间跨度" v-model="timeSpan" style="width: 150px;">
  153. <template slot="append">分钟</template>
  154. </el-input>
  155. </div>
  156. <div class="btn">
  157. <el-button type="primary" @click="getAutoRange">确定</el-button>
  158. </div>
  159. </div>
  160. <div class="right-bottom-list">
  161. <div v-if="intervalList.length">
  162. <div class="all-select">
  163. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
  164. </div>
  165. <div class="all-box">
  166. <el-checkbox-group v-model="checkedIntervalList" @change="handleCheckedIntervalChange">
  167. <el-checkbox v-for="item in intervalList" :label="item" :key="item">{{item}}</el-checkbox>
  168. </el-checkbox-group>
  169. </div>
  170. </div>
  171. <div v-else class="nodata"><el-alert title="暂无可用时间段" type="warning" :closable="false"></el-alert></div>
  172. </div>
  173. </div>
  174. </div>
  175. <el-dialog title="添加时间段" :visible.sync="dialogFormVisible" :modal="false" width="40%">
  176. <el-form>
  177. <div class="time-select-box">
  178. <div class="time-select-item">
  179. <div class="label-box">开始时间:</div>
  180. <div class="select-box">
  181. <el-time-picker v-model="startTime" placeholder="开始时间" :value-format="pickerFormatText" :format="pickerFormatText"
  182. :picker-options="{ selectableRange: '00:00:00 - 23:59:00', format: pickerFormatText }" @change="changeTime"></el-time-picker>
  183. </div>
  184. </div>
  185. <div class="time-select-item">
  186. <div class="label-box">结束时间:</div>
  187. <div class="select-box">
  188. <el-select v-model="isNextDay" placeholder="请选择">
  189. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  190. </el-select>
  191. </div>
  192. <div class="select-box">
  193. <el-time-picker v-model="endTime" placeholder="结束时间" :value-format="pickerFormatText" :format="pickerFormatText"
  194. :picker-options="{ selectableRange: `${minPickerTime} - 23:59:00`, format: pickerFormatText }"></el-time-picker>
  195. </div>
  196. </div>
  197. </div>
  198. </el-form>
  199. <div slot="footer" class="dialog-footer">
  200. <el-button @click="dialogFormVisible = false">取 消</el-button>
  201. <el-button type="primary" @click="addTime">确 定</el-button>
  202. </div>
  203. </el-dialog>
  204. </div>
  205. </template>
  206. <script>
  207. Vue.component('com-time-select', {
  208. template: '#com-time-select',
  209. props: {
  210. slotType: {
  211. type: Number,
  212. default: 1
  213. },
  214. dateList: {
  215. type: Array,
  216. default: () => {
  217. return []
  218. }
  219. },
  220. priceType: {
  221. type: Number,
  222. default: 0
  223. },
  224. preSelectedDates: {
  225. type: Array,
  226. default: () => {
  227. return []
  228. }
  229. },
  230. currentSetting: {
  231. type: Array,
  232. default: () => {
  233. return []
  234. }
  235. },
  236. selectListStr: {
  237. type: String,
  238. default: ''
  239. }
  240. },
  241. data() {
  242. return {
  243. settingTypes: [
  244. {
  245. val: 1,
  246. name: '逐天进行设置'
  247. },
  248. {
  249. val: 2,
  250. name: '每天设置相同时间段'
  251. }
  252. ],
  253. settingType: {
  254. val: 1,
  255. name: '逐天进行设置'
  256. },
  257. selectedDates: [],
  258. dialogFormVisible: false,
  259. startTime: '',
  260. endTime: '',
  261. minPickerTime: '00:00:00',
  262. pickerFormatText: 'HH:mm',
  263. options: [{
  264. value: 1,
  265. label: '今日'
  266. }, {
  267. value: 2,
  268. label: '次日'
  269. }],
  270. isNextDay: 1,
  271. timeList: [],
  272. currentTime: {},
  273. timeRange: ['',''],
  274. timeSpan: 30,
  275. intervalList: [],
  276. checkAll: false,
  277. isIndeterminate: true,
  278. checkedIntervalList: [],
  279. }
  280. },
  281. watch: {
  282. dateList: {
  283. handler(newvalue,oldvalue) {
  284. console.log('watch dateList', newvalue, oldvalue)
  285. this.$nextTick(() => {
  286. this.initData();
  287. });
  288. },
  289. immediate: true,
  290. deep: true
  291. },
  292. currentTime: {
  293. handler(newvalue,oldvalue) {
  294. this.timeList = this.currentTime.children;
  295. },
  296. immediate: true,
  297. deep: true
  298. },
  299. priceType: {
  300. handler(newvalue,oldvalue) {
  301. if(newvalue){
  302. this.$emit('select', this.selectedDates);
  303. }
  304. },
  305. immediate: true,
  306. deep: true
  307. },
  308. slotType: {
  309. handler(newvalue,oldvalue) {
  310. this.$emit('select', this.selectedDates);
  311. },
  312. immediate: true,
  313. deep: true
  314. },
  315. },
  316. methods: {
  317. initData() {
  318. let newArr = [...new Set(this.dateList)];
  319. console.log('com time select', this.dateList, this.priceType, this.currentSetting)
  320. if(this.currentSetting.length && (this.priceType == 1 || this.priceType == 0)){
  321. this.selectedDates = [];
  322. this.currentSetting.forEach(item => {
  323. this.selectedDates.push({
  324. date: item.date,
  325. isSelect: item.isSelect,
  326. children: item.times,
  327. intervalList: item.times,
  328. checkAll: true,
  329. isIndeterminate: true,
  330. checkedIntervalList: item.times
  331. });
  332. });
  333. let rarr2 = [];
  334. this.selectedDates.forEach(item => {
  335. if(newArr.indexOf(item.date) > -1){
  336. rarr2.push(item);
  337. }
  338. });
  339. this.selectedDates = JSON.parse(JSON.stringify(rarr2));
  340. let oldDates2 = [];
  341. this.selectedDates.forEach(item => {
  342. oldDates2.push(item.date);
  343. });
  344. for(let i = 0;i < newArr.length;i++){
  345. if(oldDates2.indexOf(newArr[i]) < 0){
  346. this.selectedDates.push({
  347. date: newArr[i],
  348. isSelect: false,
  349. children: [],
  350. intervalList: [],
  351. checkAll: false,
  352. isIndeterminate: true,
  353. checkedIntervalList: []
  354. });
  355. }
  356. }
  357. }else{
  358. if(this.selectListStr && this.selectListStr != '[]'){
  359. console.log('this.selectListStr', this.selectListStr)
  360. this.selectedDates = JSON.parse(this.selectListStr);
  361. let rarr1 = [];
  362. this.selectedDates.forEach(item => {
  363. if(newArr.indexOf(item.date) > -1){
  364. rarr1.push(item);
  365. }
  366. });
  367. this.selectedDates = JSON.parse(JSON.stringify(rarr1));
  368. let oldDates = [];
  369. this.selectedDates.forEach(item => {
  370. oldDates.push(item.date);
  371. });
  372. for(let i = 0;i < newArr.length;i++){
  373. if(oldDates.indexOf(newArr[i]) < 0){
  374. this.selectedDates.push({
  375. date: newArr[i],
  376. isSelect: false,
  377. children: [],
  378. intervalList: [],
  379. checkAll: false,
  380. isIndeterminate: true,
  381. checkedIntervalList: []
  382. });
  383. }
  384. }
  385. }else if(this.preSelectedDates.length){
  386. this.selectedDates = JSON.parse(JSON.stringify(this.preSelectedDates));
  387. let rarr1 = [];
  388. this.selectedDates.forEach(item => {
  389. if(newArr.indexOf(item.date) > -1){
  390. rarr1.push(item);
  391. }
  392. });
  393. this.selectedDates = JSON.parse(JSON.stringify(rarr1));
  394. let oldDates = [];
  395. this.selectedDates.forEach(item => {
  396. oldDates.push(item.date);
  397. });
  398. for(let i = 0;i < newArr.length;i++){
  399. if(oldDates.indexOf(newArr[i]) < 0){
  400. this.selectedDates.push({
  401. date: newArr[i],
  402. isSelect: false,
  403. children: [],
  404. intervalList: [],
  405. checkAll: false,
  406. isIndeterminate: true,
  407. checkedIntervalList: []
  408. });
  409. }
  410. }
  411. }else{
  412. let rarr = [];
  413. this.selectedDates.forEach(item => {
  414. if(newArr.indexOf(item.date) > -1){
  415. rarr.push(item);
  416. }
  417. });
  418. this.selectedDates = JSON.parse(JSON.stringify(rarr));
  419. let oldDates = [];
  420. this.selectedDates.forEach(item => {
  421. oldDates.push(item.date);
  422. });
  423. for(let i = 0;i < newArr.length;i++){
  424. if(oldDates.indexOf(newArr[i]) < 0){
  425. this.selectedDates.push({
  426. date: newArr[i],
  427. isSelect: false,
  428. children: [],
  429. intervalList: [],
  430. checkAll: false,
  431. isIndeterminate: true,
  432. checkedIntervalList: []
  433. });
  434. }
  435. }
  436. }
  437. }
  438. this.selectedDates.sort(function (a, b) {
  439. return new Date(a.date) - new Date(b.date);
  440. })
  441. this.selectedDates.forEach(item => {
  442. item.isSelect = false;
  443. });
  444. if(this.selectedDates.length){
  445. this.selectedDates.sort(function (a, b) {
  446. // a.date - b.date
  447. return new Date(a) - new Date(b);
  448. })
  449. this.selectedDates[0].isSelect = true;
  450. console.log('this.selectedDates[0]this.selectedDates[0]', this.selectedDates[0])
  451. this.currentTime = this.selectedDates[0];
  452. this.intervalList = this.selectedDates[0].intervalList;
  453. this.checkedIntervalList = this.selectedDates[0].checkedIntervalList;
  454. this.checkAll = this.selectedDates[0].checkAll;
  455. this.isIndeterminate = this.selectedDates[0].isIndeterminate;
  456. }
  457. this.$emit('select', this.selectedDates);
  458. },
  459. handleCommand(command) {
  460. if(this.settingType.val != command) {
  461. this.settingTypes.forEach(item => {
  462. if(item.val == command) {
  463. this.settingType.val = item.val;
  464. this.settingType.name = item.name;
  465. }
  466. });
  467. if(command == 1){
  468. this.selectedDates.forEach(item => {
  469. item.isSelect = false;
  470. });
  471. this.selectedDates[0].isSelect = true;
  472. this.currentTime = this.selectedDates[0];
  473. }
  474. if(command == 2){
  475. this.selectedDates.forEach(item => {
  476. item.children = [];
  477. item.intervalList = [];
  478. item.checkAll = false;
  479. item.isIndeterminate = true;
  480. item.checkedIntervalList = [];
  481. });
  482. this.intervalList = [];
  483. this.checkAll = false;
  484. this.isIndeterminate = true;
  485. this.checkedIntervalList = [];
  486. }
  487. this.$emit('select', this.selectedDates);
  488. }
  489. },
  490. onDate(index) {
  491. this.selectedDates.forEach(item => {
  492. item.isSelect = false;
  493. });
  494. this.selectedDates[index].isSelect = true;
  495. this.currentTime = this.selectedDates[index];
  496. this.intervalList = this.selectedDates[index].intervalList;
  497. this.checkedIntervalList = this.selectedDates[index].checkedIntervalList;
  498. this.checkAll = this.selectedDates[index].checkAll;
  499. this.isIndeterminate = this.selectedDates[index].isIndeterminate;
  500. },
  501. changeTime(event) {
  502. this.minPickerTime = `${event}:00`
  503. },
  504. delTimeItem(index) {
  505. this.timeList.splice(index,1);
  506. if(this.settingType.val == 2) {
  507. this.selectedDates.forEach(item => {
  508. item.children = this.timeList;
  509. });
  510. }
  511. if(this.settingType.val == 1) {
  512. this.selectedDates.forEach(item => {
  513. if(item.isSelect){
  514. item.children = this.timeList;
  515. }
  516. });
  517. }
  518. this.$emit('select', this.selectedDates);
  519. },
  520. onShowAdd() {
  521. if(this.selectedDates.length){
  522. this.dialogFormVisible = true;
  523. }else{
  524. this.$message.error('请先选择可预约日期');
  525. }
  526. },
  527. addTime() {
  528. let str = '';
  529. if (this.startTime === '') {
  530. this.$message.error("请选择开始时间")
  531. return
  532. }
  533. if (this.endTime === '') {
  534. this.$message.error("请选择结束时间")
  535. return
  536. }
  537. if(this.isNextDay == 2){
  538. str = this.startTime + '-次日' + this.endTime;
  539. }else{
  540. str = this.startTime + '-' + this.endTime;
  541. }
  542. if(str){
  543. if(this.settingType.val == 2) {
  544. this.selectedDates.forEach(item => {
  545. if (item.children.indexOf(str) === -1) item.children.push(str);
  546. });
  547. }
  548. if(this.settingType.val == 1) {
  549. this.selectedDates.forEach(item => {
  550. if(item.isSelect){
  551. if (item.children.indexOf(str) === -1) item.children.push(str);
  552. }
  553. });
  554. }
  555. this.$emit('select', this.selectedDates);
  556. }
  557. this.dialogFormVisible = false;
  558. },
  559. onAutoRangeChange() {},
  560. getAutoRange() {
  561. if(this.selectedDates.length){
  562. this.intervalList = [];
  563. let interval = parseInt(this.timeSpan);
  564. if(this.timeRange.length == 2 && this.timeRange[0] && this.timeRange[1] && interval){
  565. this.intervalList = this.createTimeArray(this.timeRange[0], this.timeRange[1], interval, 'h:m');
  566. this.checkedIntervalList = this.intervalList;
  567. this.checkAll = true;
  568. this.isIndeterminate = false;
  569. if(this.settingType.val == 2) {
  570. this.selectedDates.forEach(item => {
  571. item.intervalList = this.intervalList;
  572. item.checkedIntervalList = this.checkedIntervalList;
  573. item.checkAll = this.checkAll;
  574. item.isIndeterminate = this.isIndeterminate;
  575. });
  576. }
  577. if(this.settingType.val == 1) {
  578. this.selectedDates.forEach(item => {
  579. if(item.isSelect){
  580. item.intervalList = this.intervalList;
  581. item.checkedIntervalList = this.checkedIntervalList;
  582. item.checkAll = this.checkAll;
  583. item.isIndeterminate = this.isIndeterminate;
  584. }
  585. });
  586. }
  587. this.$emit('select', this.selectedDates);
  588. }else{
  589. this.$message.error('请先填写所需信息');
  590. }
  591. }else{
  592. this.$message.error('请先选择可预约日期');
  593. }
  594. },
  595. handleCheckAllChange(val) {
  596. this.checkedIntervalList = val ? this.intervalList : [];
  597. this.isIndeterminate = false;
  598. if(this.settingType.val == 2) {
  599. this.selectedDates.forEach(item => {
  600. item.checkedIntervalList = [];
  601. this.checkedIntervalList.forEach(it => {
  602. item.checkedIntervalList.push(it);
  603. });
  604. item.isIndeterminate = false;
  605. item.checkAll = this.checkAll;
  606. });
  607. }
  608. if(this.settingType.val == 1) {
  609. this.selectedDates.forEach(item => {
  610. if(item.isSelect){
  611. item.checkedIntervalList = [];
  612. this.checkedIntervalList.forEach(it => {
  613. item.checkedIntervalList.push(it);
  614. });
  615. item.isIndeterminate = false;
  616. item.checkAll = this.checkAll;
  617. }
  618. });
  619. }
  620. this.$emit('select', this.selectedDates);
  621. },
  622. handleCheckedIntervalChange(value) {
  623. let checkedCount = value.length;
  624. this.checkAll = checkedCount === this.intervalList.length;
  625. this.isIndeterminate = checkedCount > 0 && checkedCount < this.intervalList.length;
  626. if(this.settingType.val == 2) {
  627. this.selectedDates.forEach(item => {
  628. item.checkAll = this.checkAll;
  629. item.isIndeterminate = this.isIndeterminate;
  630. item.checkedIntervalList = [];
  631. this.checkedIntervalList.forEach(it => {
  632. item.checkedIntervalList.push(it);
  633. });
  634. });
  635. }
  636. if(this.settingType.val == 1) {
  637. this.selectedDates.forEach(item => {
  638. if(item.isSelect){
  639. item.checkAll = this.checkAll;
  640. item.isIndeterminate = this.isIndeterminate;
  641. item.checkedIntervalList = [];
  642. this.checkedIntervalList.forEach(it => {
  643. item.checkedIntervalList.push(it);
  644. });
  645. }
  646. });
  647. }
  648. this.$emit('select', this.selectedDates);
  649. },
  650. // 格式化时间-小于10补0
  651. formatDigit(n) {
  652. return n.toString().replace(/^(\d)$/, '0$1');
  653. },
  654. formatDate(timestamp, formats) {
  655. /*formats格式
  656. 1. Y-M-D
  657. 2. Y-M-D h:m:s
  658. 3. Y年M月D日
  659. 4. Y年M月D日 h时m分
  660. 5. Y年M月D日 h时m分s秒
  661. 示例:console.log(this.formatDate(new Date().getTime(), 'Y年M月D日 h:m:s')) ==> 2023年5月17日 11:00:00
  662. */
  663. formats = formats || 'Y-M-D';
  664. let myDate = undefined;
  665. if (timestamp) {
  666. if (typeof (timestamp) != 'string') {
  667. myDate = timestamp;
  668. } else {
  669. myDate = new Date(timestamp);
  670. }
  671. } else {
  672. myDate = new Date();
  673. }
  674. const year = myDate.getFullYear();
  675. const month = this.formatDigit(myDate.getMonth() + 1);
  676. const day = this.formatDigit(myDate.getDate());
  677. const hour = this.formatDigit(myDate.getHours());
  678. const minute = this.formatDigit(myDate.getMinutes());
  679. const second = this.formatDigit(myDate.getSeconds());
  680. return formats.replace(/Y|M|D|h|m|s/g, (matches) => {
  681. return {
  682. Y: year,
  683. M: month,
  684. D: day,
  685. h: hour,
  686. m: minute,
  687. s: second
  688. } [matches];
  689. });
  690. },
  691. //获取时间段范围
  692. createTimeArray(startTime, endTime, minutes, formats, date = new Date()) {
  693. //格式化标准时间
  694. const frontTime = this.formatDate(date, 'Y/M/D')
  695. //获得时间戳
  696. let startDate = new Date(frontTime + ' ' + this.formatDigit(startTime)).getTime();
  697. let endDate = new Date(frontTime + ' ' + this.formatDigit(endTime)).getTime();
  698. //所隔时间
  699. const space = minutes * 60 * 1000;
  700. let mod = endDate - startDate;
  701. let modNum = mod / space
  702. let dateArray = [];
  703. for (let i = 0; i + 1 <= modNum; i++) {
  704. const start = startDate + space * i
  705. const end = startDate + space * (i + 1)
  706. let final = this.formatDate(new Date(start), formats) + '-' + this.formatDate(new Date(end), formats)
  707. dateArray.push(final)
  708. }
  709. return dateArray
  710. },
  711. }
  712. })
  713. </script>