diff --git a/app.json b/app.json index dce82e5..894c131 100644 --- a/app.json +++ b/app.json @@ -21,7 +21,9 @@ "pages/exchange/index", "pages/creditOperate/index", "pages/goHtml/goHtml", - "pages/orderUrl/orderUrl" + "pages/orderUrl/orderUrl", + "pages/Appointment/appointment", + "pages/appointDetail/appointDetail" ], "window": { "backgroundTextStyle": "light", diff --git a/config/config.js b/config/config.js index def6738..08aa8dc 100644 --- a/config/config.js +++ b/config/config.js @@ -5,14 +5,14 @@ let url = extConfig.attr.configUrl; var apiPrefix = url + '/B'; let config = { - apiPrefix:apiPrefix, + apiPrefix: apiPrefix, api: { // 获取进件 页面地址 findTt: "/api/merchant/getTtReceiverUrl", /** - * 接口用途:login - */ + * 接口用途:login + */ login: '/api/user/login', /** * B端用户详情 @@ -118,13 +118,25 @@ let config = { */ getMicroPayAmountOnDate: '/api/micropay/getMicroPayAmountOnDate', /** - * 首页账单列表 - */ + * 首页账单列表 + */ listBillOweAndWaitPay: "/api/bill/listBillOweAndWaitPay", /** * 账单 */ listBill: "/api/bill/listBill", + /** + * 预约列表 + */ + appointmentList: "/api/wxCouponOrderReservation/list", + /** + * 预约详情 + */ + appointDetail: "/api/wxCouponOrderReservation/detail", + /** + * 预约确认 + */ + appointConfirm: "/api/wxCouponOrderReservation/updateStatus", /** * 获得openId */ @@ -210,8 +222,8 @@ let config = { */ getCreditList: "/api/credit/list", /** - * 查询账户信息 - */ + * 查询账户信息 + */ findAccountById: "/api/merchant/findAccountById", /** * 更新收款账户信息 @@ -306,12 +318,12 @@ let config = { */ addbatch: "/api/wxCouponChannel/addbatch", /** - * B端发卷-下架 - */ + * B端发卷-下架 + */ soldOut: "/api/wxCouponChannel/update", /** - * B端发卷-作废 - */ + * B端发卷-作废 + */ cancellation: "/api/coupon/update", /** * B端发卷-查询审批历史记录 @@ -332,7 +344,7 @@ let config = { /** * 导出订单记录 */ - exportUrl: "/api/couponOrder/getVerifiedExportUrl", + exportUrl: "/api/couponOrder/getVerifiedExportUrl", }, weapp: { @@ -345,6 +357,6 @@ let config = { for (var key in config.api) { config.api[key] = apiPrefix + config.api[key]; } -console.log(config,"config"); +console.log(config, "config"); module.exports = config; \ No newline at end of file diff --git a/ext.json b/ext.json index 7a5df93..7705460 100644 --- a/ext.json +++ b/ext.json @@ -2,10 +2,10 @@ "ext": { "attr": { "configUrl": "https://btest.malls.iformall.com", - "datatowerurl": "https://mobile.malls.iformall.com" + "datatowerurl": "https://mobiletest.malls.iformall.com" }, - "name": "富茂券券集团商户端", - "weappId": "tt60d3166effed27cc01", + "name": "富茂家政商户端", + "weappId": "tt80b0f60d1f8c7bda01", "appVersion": "Btest.5.1.0" }, "debug": false, @@ -29,7 +29,7 @@ "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#52A0FD" }, - "extAppid": "tt60d3166effed27cc01", + "extAppid": "tt80b0f60d1f8c7bda01", "extEnable": true, "permission": { "scope.userLocation": { diff --git a/pages/Appointment/appointment.js b/pages/Appointment/appointment.js new file mode 100644 index 0000000..a6247c0 --- /dev/null +++ b/pages/Appointment/appointment.js @@ -0,0 +1,107 @@ +// c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttb\pages\Appointment\appointment\appointment.js +const config = require('../../config/config.js') +const Http = require('../../utils/http.js') +const HttpBasics = require('../../utils/HttpBasics.js') +const util = require('../../utils/util') +var app = getApp() +Page({ + data: { + currentID: "", + pickedTime: "", + startTime: "开始时间", + endTime: "结束时间", + pageNum: 1, + status: 0, + list: [] + }, + + onLoad(options) { + this.getList() + }, + + getList(status, startTime, endTime) { + const that = this + const data = { + pageNum: this.data.pageNum, + pageSize: 20, + } + + if (startTime && endTime) { + data.serchStartDate = startTime + data.serchEndDate = endTime + } + + if (status) { + data.status = status + } + + HttpBasics.get({ + url: config.api.appointmentList, + data + }) + .then(res => { + console.log(res, 'res'); + res.data.list.forEach(item => { + const appointStart = util.timestampToTime(item.startDate, 'YYYY-MM-DD hh:mm:ss') + const appointEnd = util.timestampToTime(item.endDate, 'hh:mm:ss') + item.appointTime = appointStart + ' - ' + appointEnd + }) + that.setData({ + list: res.data.list, + }) + }).catch(err => { + console.log(err, 'err'); + }) + }, + + setNav(e) { + const id = e.currentTarget.dataset.id + this.setData({ + currentID: id == this.data.currentID ? '' : id + }) + + console.log(this.data.currentID, 'currentID'); + }, + + setType(e) { + const type = e.currentTarget.dataset.type * 1 + this.setData({ + currentID: '', + }) + this.getList(type) + }, + + setStartTime(e) { + console.log(e.detail.value, 'e'); + this.setData({ + startTime: e.detail.value + }) + }, + + setEndTime(e) { + console.log(e.detail.value, 'e'); + this.setData({ + endTime: e.detail.value + }) + }, + + search() { + if (this.data.startTime == '开始时间' || this.data.endTime == '结束时间') { + return + } + const startTime = this.data.startTime + " 00:00:00" + const endTime = this.data.endTime + " 23:59:59" + this.getList(false, startTime, endTime) + }, + + goDetail(e) { + const id = e.currentTarget.dataset.id + tt.navigateTo({ + url: `/pages/appointDetail/appointDetail?id=${id}`, + }); + }, + + onShow() { + this.getList() + } +}) \ No newline at end of file diff --git a/pages/Appointment/appointment.json b/pages/Appointment/appointment.json new file mode 100644 index 0000000..2bbb353 --- /dev/null +++ b/pages/Appointment/appointment.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "预约管理", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark", + "navigationBarTextStyle": "white", + "navigationBarBackgroundColor": "#52A0FD", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/Appointment/appointment.ttml b/pages/Appointment/appointment.ttml new file mode 100644 index 0000000..0adeedc --- /dev/null +++ b/pages/Appointment/appointment.ttml @@ -0,0 +1,50 @@ + + + + 类型 + + + + 日期 + + + + + + + 全部 + 未确认 + 已确认 + 已完成 + + + + {{ startTime }}{{ endTime }} + + + + + + + 订单编号:{{ item.couponOrderId }} + 未确认 + 已退款 + 已确认 + 已完成 + + + 商品名称:{{ item.couponTitle }} + 用户手机号码:{{ item.userPhone }} + 服务预约时间: + {{ item.appointTime }} + + + + + + + 暂无记录 + + + \ No newline at end of file diff --git a/pages/Appointment/appointment.ttss b/pages/Appointment/appointment.ttss new file mode 100644 index 0000000..f4faf04 --- /dev/null +++ b/pages/Appointment/appointment.ttss @@ -0,0 +1,157 @@ +.nav { + display: flex; + justify-content: space-between; + padding: 20rpx 150rpx; + background-color: #f7f7f7; +} + +.nav .item image { + position: relative; + bottom: 5rpx; + width: 30rpx; + margin-left: 20rpx; +} + +.nav .currentItem { + color: #52a0fd; +} + +.nav .currentItem image { + position: relative; + bottom: 5rpx; + width: 30rpx; + margin-left: 20rpx; + transform: rotate(180deg); + transition: all 0.3s; +} + +.type { + text-align: center; + padding: 40rpx; + transform: translateY(-150%); + opacity: 0; + transition: all 0.3s; + background-color: #ffffff86; + z-index: 99; +} + +.type.active { + transform: translateY(0); + opacity: 1; +} + +.type .item { + color: #ffffff; + background-color: #52a0fd; + border-radius: 5rpx; + padding: 10rpx 0; + margin-bottom: 40rpx; +} + +.type .item.center { + margin: 30rpx 0; +} + +.pickedTime { + position: relative; + bottom: 480rpx; + text-align: center; +} + +.pickedTime .picker { + display: inline-block; + background-color: #529ffd86; + padding: 10rpx; + border-radius: 10rpx; + color: #ffffff; +} + +.pickedTime .search { + display: inline-block; + width: 120rpx; + height: 60rpx; + line-height: 60rpx; + padding: 5rpx; + margin-left: 40rpx; +} + +.list { + position: relative; + bottom: 480rpx; + margin-top: 20rpx; + z-index: -1; +} + +.list.active { + z-index: 1; +} + +.list .item { + width: 90%; + border: 1px solid #ffffff93; + margin: auto; + overflow: hidden; + background-color: #0000000a; + border-radius: 20rpx; + margin-bottom: 30rpx; +} + +.list .itemXX { + text-align: center; +} + +.list .item .head { + position: relative; + padding: 20rpx; + font-size: 30rpx; + border-bottom: 1px solid #ffffff93; +} + +.notice { + position: absolute; + width: 250rpx; + text-align: center; + top: 28rpx; + right: -80rpx; + transform: rotate(45deg); + font-size: 35rpx; +} + +.notice.noAppoint { + color: red; + background-color: #ffcc66; +} + +.notice.confirm { + color: #ffffff; + background-color: #ffcc66; +} + +.notice.refund { + color: #ffffff; + background-color: #ff0000; +} + +.notice.complete { + color: #ffffff; + background-color: #19be27; +} + +.list .item .body { + padding: 20rpx 20rpx; + border-bottom: 1px solid #ffffff93; +} + +.list .item .body .items { + margin-bottom: 10rpx; +} + + +.list .item .footer { + margin: 25rpx 0; + padding: 0 170rpx; +} + +.list .item .footer button { + background-color: #52a0fd; +} \ No newline at end of file diff --git a/pages/appointDetail/appointDetail.js b/pages/appointDetail/appointDetail.js new file mode 100644 index 0000000..0fee461 --- /dev/null +++ b/pages/appointDetail/appointDetail.js @@ -0,0 +1,117 @@ +// c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttb\pages\appointDetail\appointDetail.js +const config = require('../../config/config.js') +const Http = require('../../utils/http.js') +const HttpBasics = require('../../utils/HttpBasics.js') +const util = require('../../utils/util') +var app = getApp() + +Page({ + data: { + id: "", + detail: null + }, + + onLoad(options) { + console.log(options, 'options'); + if (options.id) { + this.setData({ + id: options.id + }) + this.getDetail(options.id) + } + }, + + getDetail(id) { + const that = this + const data = { + id + } + HttpBasics.get({ + url: config.api.appointDetail, + data + }) + .then(res => { + console.log(res, 'res'); + const appointStart = util.timestampToTime(res.data.startDate, 'YYYY-MM-DD hh:mm:ss') + const appointEnd = util.timestampToTime(res.data.endDate, 'hh:mm:ss') + res.data.appointTime = appointStart + ' - ' + appointEnd + that.setData({ + detail: res.data + }) + }).catch(err => { + console.log(err, 'err'); + }) + }, + + back() { + tt.navigateBack(); + }, + + cancel() { + const that = this + tt.showModal({ + title: "提示", + content: "是否与用户取得联系并取消预约?", + showCancel: true, + confirmText: "确认取消", + confirmColor: "#52a0fd", + cancelText: "返回", + success(res) { + if (res.confirm) { + that.goChange(that.data.id, 0) + } + if (res.cancel) { + return + } + } + }); + }, + + confirm() { + const that = this + tt.showModal({ + title: "提示", + content: "是否与用户取得联系并完成预约?", + showCancel: true, + confirmText: "确认完成", + confirmColor: "#52a0fd", + cancelText: "关闭", + success(res) { + if (res.confirm) { + that.goChange(that.data.id, 5) + } + if (res.cancel) { + return + } + } + }); + }, + + goChange(id, status) { + const data = { + id, + status + } + HttpBasics.post({ + url: config.api.appointConfirm, + data + }) + .then(res => { + console.log(res, 'res'); + tt.showToast({ + title: status == 5 ? '确认成功!' : '取消成功!', + icon: "success", + duration: 2000 + }); + setTimeout(() => { + tt.navigateBack(); + }, 2000); + }).catch(err => { + console.log(err, 'err'); + tt.showToast({ + title: err.message, + icon: "none" + }); + }) + } +}) \ No newline at end of file diff --git a/pages/appointDetail/appointDetail.json b/pages/appointDetail/appointDetail.json new file mode 100644 index 0000000..0b24f1a --- /dev/null +++ b/pages/appointDetail/appointDetail.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "预约详情", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark", + "navigationBarTextStyle": "white", + "navigationBarBackgroundColor": "#52A0FD", + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/appointDetail/appointDetail.ttml b/pages/appointDetail/appointDetail.ttml new file mode 100644 index 0000000..531e69c --- /dev/null +++ b/pages/appointDetail/appointDetail.ttml @@ -0,0 +1,18 @@ + + + + 订单编号:{{ detail.couponOrderId }} + 商品名称:{{ detail.couponTitle }} + 服务预约时间:{{ detail.appointTime }} + 服务预约地址:{{ detail.userAddress }} + 用户手机号码:{{ detail.userPhone }} + 备注:{{ detail.describeStr }} + + + + + + + + + \ No newline at end of file diff --git a/pages/appointDetail/appointDetail.ttss b/pages/appointDetail/appointDetail.ttss new file mode 100644 index 0000000..9d11fe8 --- /dev/null +++ b/pages/appointDetail/appointDetail.ttss @@ -0,0 +1,32 @@ +/* c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttb\pages\appointDetail\appointDetail.ttss */ +.card { + width: 95%; + border: 1px solid #00000063; + margin: 40rpx auto; + padding: 20rpx; + border-radius: 15rpx; + box-sizing: border-box; +} + +.card .item { + margin-bottom: 20rpx; +} + +.btns { + position: fixed; + width: 95%; + left: 50%; + bottom: 130rpx; + transform: translateX(-50%); + padding: 0 80rpx; + box-sizing: border-box; +} + +.btns .back { + margin-bottom: 40rpx; +} + +.btns .confirm { + color: #ffffff; + background-color: #52a0fd; +} \ No newline at end of file diff --git a/pages/main/main.js b/pages/main/main.js index 08daa49..ebc2f2a 100644 --- a/pages/main/main.js +++ b/pages/main/main.js @@ -288,7 +288,7 @@ Page({ // id: 8 // } { - text: '预约服务', + text: '服务预约', icon: 'iconfont icon-lingquanzhongxin', id: 9 }, @@ -520,7 +520,7 @@ Page({ }) } else if (id == 9) { //服务预约 tt.navigateTo({ - url: '/pages/marktingsettlement/marktingsettlement', + url: '/pages/Appointment/appointment', }) } }, diff --git a/pages/marktingsettlement/marktingsettlement.js b/pages/marktingsettlement/marktingsettlement.js index 8938f7b..46e2f40 100644 --- a/pages/marktingsettlement/marktingsettlement.js +++ b/pages/marktingsettlement/marktingsettlement.js @@ -15,25 +15,25 @@ Page({ flagdate: null, list: [], tabTxt: [{ - title: '全部', - idss: 0 - }, - { - title: '日期', - idss: 1 - }, - { - title: '类型', - idss: 2 - }, - { - title: '状态', - idss: 3 - }, - { - title: '来源', - idss: 4 - } + title: '全部', + idss: 0 + }, + { + title: '日期', + idss: 1 + }, + { + title: '类型', + idss: 2 + }, + { + title: '状态', + idss: 3 + }, + { + title: '来源', + idss: 4 + } ], showList: null, loading: "", @@ -43,37 +43,36 @@ Page({ hasMore: false, //加载更多按钮 moreTxt: '点击加载更多', dataNull: true, - status:'', - type:'', - source:'', + status: '', + type: '', + source: '', date: "", date2: "", idss: 0, - subsidy:'', + subsidy: '', pageNum: 1, //第几页 height: null, billtypes: [{ - name: '自主结算', - billTypeValue: 1, - id: 1 - }, - { - name: '微信分账', - billTypeValue: 2, - id: 2 - } + name: '自主结算', + billTypeValue: 1, + id: 1 + }, + { + name: '微信分账', + billTypeValue: 2, + id: 2 + } ], - statustypes: [ - { - name: '未结算', - status: 0, - id: 0 - }, - { - name: '已结算', - status: 1, - id: 1 - } + statustypes: [{ + name: '未结算', + status: 0, + id: 0 + }, + { + name: '已结算', + status: 1, + id: 1 + } ], //结算来源 auditWayOptions: [ @@ -132,7 +131,7 @@ Page({ idss: e.target.dataset.idss || e.currentTarget.dataset.idss, pageNum: 1 }) - if (e.currentTarget.dataset.idss===0){ + if (e.currentTarget.dataset.idss === 0) { this.setData({ source: '', type: '', @@ -144,14 +143,14 @@ Page({ this.getTotleData() } var data = [true, true, true, true, true], - index = e.currentTarget.dataset.index; + index = e.currentTarget.dataset.index; data[index] = !that.data.tab[index]; that.setData({ tab: data }) }, bindDateChange1: function (e) { - if (new Date(e.detail.value).getTime() > new Date(this.data.date2).getTime()){ + if (new Date(e.detail.value).getTime() > new Date(this.data.date2).getTime()) { tt.showToast({ title: '抱歉,开始日期不能大于结束日期', icon: 'none', @@ -178,19 +177,19 @@ Page({ date2: e.detail.value }) }, - search(e){ + search(e) { console.log(e.currentTarget.dataset.ids) let type = e.currentTarget.dataset.ids; - if(type==0){ + if (type == 0) { this.setData({ - source:'', - type:'', - status:'', - date:'', - date2:'' + source: '', + type: '', + status: '', + date: '', + date2: '' }) - } else if(type == 1){ - if(!this.data.date){ + } else if (type == 1) { + if (!this.data.date) { tt.showToast({ title: '抱歉请选择开始日期', icon: 'none', @@ -198,7 +197,7 @@ Page({ mask: false }); return; - } else if (!this.data.date2){ + } else if (!this.data.date2) { tt.showToast({ title: '抱歉请选择结束日期', icon: 'none', @@ -209,7 +208,7 @@ Page({ } } else if (type == 2) { this.setData({ - type:e.currentTarget.dataset.id + type: e.currentTarget.dataset.id }) } else if (type == 3) { console.log(e.currentTarget.dataset.id) @@ -259,22 +258,22 @@ Page({ }) console.log(arr, 888888888888) }, - getTotleData(){ + getTotleData() { let _this = this; Http.get({ - url: config.api.getSubsidySummary, - data: { - startdate: this.data.date?this.data.date + " 00:00:00":'', - enddate: this.data.date2?this.data.date2 + " 23:59:59":'', - source: this.data.source, - type: this.data.type, - status: this.data.status - } - }) + url: config.api.getSubsidySummary, + data: { + startdate: this.data.date ? this.data.date + " 00:00:00" : '', + enddate: this.data.date2 ? this.data.date2 + " 23:59:59" : '', + source: this.data.source, + type: this.data.type, + status: this.data.status + } + }) .then(res => { - console.log(res,777) + console.log(res, 777) _this.setData({ - subsidy: Number(Number(res.data.subsidy)/100).toFixed(2) + subsidy: Number(Number(res.data.subsidy) / 100).toFixed(2) }) tt.stopPullDownRefresh(); }) @@ -291,17 +290,17 @@ Page({ getList: function (page) { let _this = this; Http.get({ - url: config.api.getSubsidyList, - data: { - pageNum: page, - pageSize: 10, - startdate: this.data.date ? this.data.date + " 00:00:00" : '', - enddate: this.data.date2 ? this.data.date2 + " 23:59:59" : '', - source: this.data.source, - type: this.data.type, - status: this.data.status - } - }) + url: config.api.getSubsidyList, + data: { + pageNum: page, + pageSize: 10, + startdate: this.data.date ? this.data.date + " 00:00:00" : '', + enddate: this.data.date2 ? this.data.date2 + " 23:59:59" : '', + source: this.data.source, + type: this.data.type, + status: this.data.status + } + }) .then(res => { tt.stopPullDownRefresh(); let data = res.data.list; @@ -316,7 +315,7 @@ Page({ item.createDate01 = util.formatTime(item.createDate, 'yyyy-MM-dddd hh:mm:ss') item.sourceStr = this.data.auditWayOptions.filter(e => e.value == item.source).length > 0 ? this.data.auditWayOptions.filter(e => e.value == item.source)[0].name : ''; item.typeStr = this.data.billtypes.filter(e => e.id == item.type).length > 0 ? this.data.billtypes.filter(e => e.id == item.type)[0].name : ''; - item.statusStr = item.status===0?'未结算' : "已结算"; + item.statusStr = item.status === 0 ? '未结算' : "已结算"; allBillList.map((item02, index02) => { if (item02.id == item.id) { haveIf = true; @@ -326,7 +325,7 @@ Page({ allBillList.push(item) } }) - console.log(allBillList,444) + console.log(allBillList, 444) if (res.data.pages <= page) { _this.setData({ allBillList, diff --git a/project.private.config.json b/project.private.config.json new file mode 100644 index 0000000..3980d3d --- /dev/null +++ b/project.private.config.json @@ -0,0 +1,27 @@ +{ + "condition": { + "miniprogram": { + "current": -1, + "list": [ + { + "id": 1687232092199, + "name": "pages/Appointment/appointment", + "pathName": "pages/Appointment/appointment", + "query": "", + "scene": "990001", + "launchFrom": "scan", + "location": "qr_code" + }, + { + "id": 1687252858255, + "name": "pages/appointDetail/appointDetail", + "pathName": "pages/appointDetail/appointDetail", + "query": "id=831011125579538432", + "scene": "990001", + "launchFrom": "scan", + "location": "qr_code" + } + ] + } + } +} diff --git a/utils/util.js b/utils/util.js index 62980e9..78f985b 100644 --- a/utils/util.js +++ b/utils/util.js @@ -8,10 +8,11 @@ function convertUTCTimeToLocalTime(UTCDateString) { if (!UTCDateString) { return '-'; } - function formatFunc(str) { //格式化显示 + + function formatFunc(str) { //格式化显示 return str > 9 ? str : '0' + str } - var date2 = new Date(UTCDateString); //这步是关键 + var date2 = new Date(UTCDateString); //这步是关键 var year = date2.getFullYear(); var mon = formatFunc(date2.getMonth() + 1); var day = formatFunc(date2.getDate()); @@ -20,7 +21,7 @@ function convertUTCTimeToLocalTime(UTCDateString) { hour = hour >= 24 ? hour - 24 : hour; hour = formatFunc(hour); var min = formatFunc(date2.getMinutes()); - var dateStr = ' ' + hour + ':' + min ; + var dateStr = ' ' + hour + ':' + min; return dateStr; } @@ -29,15 +30,15 @@ function convertUTCTimeToLocalTime(UTCDateString) { // return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''); // } -function moodsText(Num){//人气值处理 Num人气值 返回字符串 处理到万位 +function moodsText(Num) { //人气值处理 Num人气值 返回字符串 处理到万位 let sing = "" - if(Num>10000){ - sing = (Num/10000).toFixed(2)+"w" - - }else{ - sing =Num - } - return sing + if (Num > 10000) { + sing = (Num / 10000).toFixed(2) + "w" + + } else { + sing = Num + } + return sing } const formatTime = (date, fmt) => { @@ -69,9 +70,9 @@ const formatTime = (date, fmt) => { if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace( RegExp.$1, - RegExp.$1.length == 1 - ? o[k] - : ("00" + o[k]).substr(("" + o[k]).length) + RegExp.$1.length == 1 ? + o[k] : + ("00" + o[k]).substr(("" + o[k]).length) ); return fmt; } catch (error) { @@ -97,6 +98,61 @@ function barc(id, code, width, height) { ); } +/** + * @description 根据时间戳获取时间 + * @param {*} timestamp 必传,number类型,时间戳数据(10位及以下,10位至13位);若不传,则返回:“无时间戳” + * @param {*} format 选传,string类型,提供以下时间格式:YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日、hh:mm:ss、hh:mm;若不传,则默认为:YYYY-MM-DD + * @returns 根据要求的时间格式 + * @version V 1.0, Created by YWQ, 2022.10.20 + */ +function timestampToTime(timestamp, format) { + if (!timestamp) return false + //时间戳为10位需*1000,时间戳为13位不需乘1000 + const length = timestamp ? timestamp.length : '' + + if (length <= 10) { + var date = new Date(timestamp * 1000) + } else { + var date = new Date(timestamp) + } + + + let Y = String(date.getFullYear()) + let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate()) + let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours()) + let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds()) + // return Y + M + D + h + m + s + if (format == "YYYY-MM-DD hh:mm:ss") { + return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s + } else if (format == "YYYY/MM/DD hh:mm:ss") { + return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s + } else if (format == "YYYY.MM.DD hh:mm:ss") { + return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s + } else if (format == "YYYY MM DD hh:mm:ss") { + return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s + } else if (format == "YYYY年MM月DD日 hh:mm:ss") { + return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s + } else if (format == "YYYY-MM-DD") { + return Y + "-" + M + "-" + D + } else if (format == "YYYY/MM/DD") { + return Y + "/" + M + "/" + D + } else if (format == "YYYY.MM.DD") { + return Y + "." + M + "." + D + } else if (format == "YYYY MM DD") { + return Y + " " + M + " " + D + } else if (format == "YYYY年MM月DD日") { + return Y + "年" + M + "月" + D + "日" + } else if (format == "hh:mm:ss") { + return h + ":" + m + ":" + s + } else if (format == "hh:mm") { + return h + ":" + m + } else { + return Y + "-" + M + "-" + D + } +} + function qrc(id, code, width, height) { qrcode.api.draw(code, { ctx: tt.createCanvasContext(id), @@ -137,20 +193,20 @@ function timechuo(startTime) { var minute = Math.floor(runTime / 60); var runTime = runTime % 60; var second = runTime; - if (day && !year && !month){ + if (day && !year && !month) { return (day + '天' + hour + "小时" + minute + "分钟") - } else if (month && !year){ - return ((month*30+day) +'天' + hour + "小时" + minute + "分钟") + } else if (month && !year) { + return ((month * 30 + day) + '天' + hour + "小时" + minute + "分钟") } else if (year) { - return ((year*365 + month*30+ day) + '天' + hour + "小时" + minute + "分钟") - }else{ + return ((year * 365 + month * 30 + day) + '天' + hour + "小时" + minute + "分钟") + } else { return (hour + "小时" + minute + "分钟") } } //计算时间差 -function timecha(endTime,startTime) { +function timecha(endTime, startTime) { var s1 = new Date(endTime.replace(/-/g, "/")); var s2 = new Date(startTime.replace(/-/g, "/")); var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000); @@ -165,8 +221,9 @@ function timecha(endTime,startTime) { var minute = Math.floor(runTime / 60); var runTime = runTime % 60; var second = runTime; - return (month+"月"+day+"天"+hour+"小时"+minute+"分钟") + return (month + "月" + day + "天" + hour + "小时" + minute + "分钟") } + function isJSON(str) { if (typeof str == 'string') { console.log("string") @@ -202,6 +259,7 @@ module.exports = { // fmtDate: fmtDate, timechuo: timechuo, timecha: timecha, - moodsText:moodsText, - convertUTCTimeToLocalTime: convertUTCTimeToLocalTime -}; + moodsText: moodsText, + convertUTCTimeToLocalTime: convertUTCTimeToLocalTime, + timestampToTime: timestampToTime +}; \ No newline at end of file