diff --git a/app.js b/app.js index 155a395..77a2a7c 100644 --- a/app.js +++ b/app.js @@ -2,50 +2,53 @@ var restAjax = require('./utils/restAjax.js'); var request = require('./utils/request.js'); App({ - restAjax: restAjax, - http: request, - apis: restAjax.apis, - urls:request.apis, - baseUrls: restAjax.baseUrl, - onLaunch() { - this.globalData.windowHeight = wx.getSystemInfoSync().windowHeight - //设置状态栏 - wx.getSystemInfo({ - success: e => { - this.globalData.StatusBar = e.statusBarHeight; - let capsule = wx.getMenuButtonBoundingClientRect(); - if (capsule) { - this.globalData.Custom = capsule; - this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight; - } else { - this.globalData.CustomBar = e.statusBarHeight + 50; - } - } - }) - - }, - - // 获取用户信息 - getUserInfo: function () { - var self = this - app.restAjax.get(app.restAjax.path('{loginUrl}app/user/get-app-user', [app.personIntroUrl]), {}, { - headers: { - token: app.globalData.token - } - }, function (code, data) { - app.globalData.userInfo = data - }, function (code, data) { - app.dialog.msg(data.msg); - }); - }, - - globalData: { - userIcon: '', - userInfo: {}, - currentCommunity: { - communityId: '', - communityName: '切换社区' + restAjax: restAjax, + http: request, + apis: restAjax.apis, + urls: request.apis, + baseUrls: restAjax.baseUrl, + onLaunch() { + var _self = this; + this.globalData.windowHeight = wx.getSystemInfoSync().windowHeight + //设置状态栏 + wx.getSystemInfo({ + success: e => { + this.globalData.StatusBar = e.statusBarHeight; + let capsule = wx.getMenuButtonBoundingClientRect(); + if (capsule) { + this.globalData.Custom = capsule; + this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight; + } else { + this.globalData.CustomBar = e.statusBarHeight + 50; + } + } + }) + //获取手机屏幕高度、宽度 + _self.globalData.windowHeight = wx.getSystemInfoSync().windowHeight + _self.globalData.windowWidth = wx.getSystemInfoSync().windowWidth }, - token: '' - } + + // 获取用户信息 + getUserInfo: function () { + var self = this + app.restAjax.get(app.restAjax.path('{loginUrl}app/user/get-app-user', [app.personIntroUrl]), {}, { + headers: { + token: app.globalData.token + } + }, function (code, data) { + app.globalData.userInfo = data + }, function (code, data) { + app.dialog.msg(data.msg); + }); + }, + + globalData: { + userIcon: '', + userInfo: {}, + currentCommunity: { + communityId: '', + communityName: '切换社区' + }, + token: '' + } }) \ No newline at end of file diff --git a/app.json b/app.json index 6c91016..4f34a18 100644 --- a/app.json +++ b/app.json @@ -1,5 +1,4 @@ { - "style": "v2", "sitemapLocation": "sitemap.json", "pages": [ "pages/index/index", @@ -97,6 +96,7 @@ "common/corpperimg/cropperimg" ] }], - "requiredPrivateInfos": ["chooseLocation","getLocation"] + "requiredPrivateInfos": ["chooseLocation","getLocation"], + "plugins": {"chooseLocation":{"version": "1.0.10","provider": "wx76a9a06e5b4e693e"}} } \ No newline at end of file diff --git a/packagecard/cardDetail/cardDetail.js b/packagecard/cardDetail/cardDetail.js index 05dd1b1..4ad9bc0 100755 --- a/packagecard/cardDetail/cardDetail.js +++ b/packagecard/cardDetail/cardDetail.js @@ -1,339 +1,487 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), t = getApp(); - -require("../../utils/util.js"); +const app = getApp() Page({ - data: { - preview: "", - showHide: !1, - isLoading: !1, - isMain: "", - cardPersonId: "", - choose_index: 0, - active: 0, - cardUrl: t.baseUrls.baseCardUrl, - areaList: [], - cardInfo: {}, - bgImg: "", - fontFamilyList: [], - useFontFamily: "", - cardId: "", - cardHeight: "", - shareTicket: "", - encryptedData: "", - iv: "", - isFromOut: !1, - token: "", - oldToken: "", - fromMine: !1, - imgTempSrc: "", - currentIndex: 0, - windowWidth: t.globalData.windowWidth, - scale: 1, - pageType: null - }, - tabChange: function(e) { - this.setData({ - active: e.detail - }), 0 == this.data.active || (1 == this.data.active ? 1 == t.globalData.servicePageType ? wx.redirectTo({ - url: "/pages/shop/catalog/bannerlist/bannerlist" - }) : 2 == t.globalData.servicePageType ? wx.redirectTo({ - url: "/pages/shop/catalog/column/column" - }) : 3 == t.globalData.servicePageType ? wx.redirectTo({ - url: "/pages/shop/catalog/list/list" - }) : 4 == t.globalData.servicePageType && wx.redirectTo({ - url: "/pages/shop/bespeak/bespeak" - }) : wx.redirectTo({ - url: "/pages/mine/index/index" - })); - }, - createMyCard: function() { - var e = this; - wx.showLoading({ - title: "生成中...", - success: function() { - e.setData({ - isLoading: !0 - }); - } - }); - for (var a = { - pictureTemplateId: e.data.cardId, - cardTemplateUseAreaList: [] - }, r = 0; r < e.data.areaList.length; r++) if ("1" != e.data.areaList[r].templateAreaType) { - var o = { - cardTemplateUseId: "", - picturesTemplateAreaId: e.data.areaList[r].picturesTemplateAreaId, - templateAreaFile: e.data.areaList[r].templateAreaFile, - templateAreaFontValue: e.data.areaList[r].templateAreaFontValue - }; - a.cardTemplateUseAreaList.push(o); - } - t.http.post(t.urls.creatCard, { - data: a, - header: { - token: t.globalData.token - } - }).then(function(t) { - console.log(t), "200" == t.statusCode && e.getMineCardList(); - }).catch(function(t) { - e.setData({ - isLoading: !1, - showHide: !1 - }); - }); - }, - getMineCardList: function() { - var e = this; - t.http.get(t.urls.getMyCard, { - header: { - token: t.globalData.token - }, - data: {} - }).then(function(t) { - e.setData({ - cardList: t.data - }), t.data.length > 0 && (e.setDefaultCard(t.data[0].cardTemplateUseId), console.log(e.data.pageType), - "org" == e.data.pageType ? e.saveOrgCard(t.data[0].cardTemplateUseId) : e.saveCardIdToSyzl(t.data[0].cardTemplateUseId)); - }).catch(function(t) { - wx.hideLoading({}), e.setData({ - isLoading: !1, - showHide: !1 - }); - }); - }, - saveCardIdToSyzl: function(e) { - console.log("设置网格员名片" + e); - var a = this; - t.restAjax.put(t.restAjax.path(t.apis.doUpdateCard, [ t.baseUrls.requestUrl, a.data.id ]), { - cardSysId: e - }, { - headers: { - token: t.globalData.token - } - }, function(e, t) { - console.log(e), console.log(t), "200" == e && a.onShowHintDialog(); - }, function(e, t) { - wx.hideLoading({}), wx.showToast({ - icon: "none", - title: "设置名片失败" - }), console.log(e), console.log(t); - }); - }, - saveOrgCard: function(e) { - var a = this; - t.restAjax.put(t.restAjax.path(t.apis.doUpdateOrg, [ t.baseUrls.requestUrl, a.data.id ]), { - cardSysId: e - }, { - headers: { - token: t.globalData.token - } - }, function(e, t) { - "200" == e && a.onShowHintDialog(); - }, function(e, t) { - wx.hideLoading({}), wx.showToast({ - icon: "none", - title: "设置名片失败" - }), console.log(t); - }); - }, - setDefaultCard: function(e) { - t.http.put(t.urls.setDefaultCard.format({ - cardTemplateUseId: e - }), { - header: { - token: t.globalData.token - } - }).then(function(e) {}).catch(function(e) {}); - }, - onShowHintDialog: function() { - var e = this; - wx.hideLoading({ - success: function(t) { - e.setData({ - isLoading: !1 - }), wx.showModal({ - content: "恭喜您名片创建成功,如需查看请到(我的 → 我的卡包)", - cancelText: "继续创建", - confirmText: "返回列表", - cancelColor: "#333333", - confirmColor: "#333333", - success: function(t) { - t.confirm ? e.backList() : e.continueCreate(); - } - }); - } - }); - }, - inputBlur: function(e) { - var t = e.detail.value, a = e.currentTarget.dataset.num, r = e.currentTarget.dataset.item, o = r.templateAreaFontLength; - "" != t && o > 0 && (t = t.substr(0, o), this.data.areaList[a].templateAreaFontValue = t, - this.data.areaList[a].focus = !1, this.setData({ - areaList: this.data.areaList - })), "1" != r.templateAreaServerLink && this.getFileId(a); - }, - choosePhoto: function(e) { - var t = e.currentTarget.dataset.cur, a = e.currentTarget.dataset.item; - console.log(t), this.setData({ - currentIndex: t - }); - var r = a.templateAreaWidth / a.templateAreaHeight; - wx.chooseImage({ - count: 1, - sourceType: [ "album", "camera" ], - success: function(e) { - wx.navigateTo({ - url: "/packagecard/common/corpperimg/cropperimg?imgSrc=" + e.tempFiles[0].path + "&scale=" + r - }); - } - }); - }, - doUploadImg: function(a) { - var r = this; - wx.showLoading({ - title: "上传中..." - }), t.http.upload(t.urls.doUploadImg, { - path: a, - name: "image", - header: { - token: t.globalData.token - } - }).then(function(t) { - wx.hideLoading({}), t = JSON.parse(t); - var a = "areaList[" + r.data.currentIndex + "].templateAreaFile"; - r.setData(e({}, a, t.data)), wx.showToast({ - title: "上传成功", - duration: 1500 - }), r.setData({ - imgTempSrc: "", - currentIndex: 0 - }); - }).catch(function(e) { - r.setData({ - imgTempSrc: "", - currentIndex: 0 - }); - }); - }, - getNameCard: function() { - var e = this; - e.data.fromMine && e.data.cardPersonId, t.http.get(t.urls.getCardDetail.format({ - cardTemplateId: e.data.cardId - }), { - header: { - token: t.globalData.token - }, - data: {} - }).then(function(t) { - var a = t.data.areaList, r = t.data.picturesTemplateWidth / e.data.windowWidth; - t.data.picturesTemplateWidth = t.data.picturesTemplateWidth / r, t.data.picturesTemplateHeight = t.data.picturesTemplateHeight / r; - for (var o = 0; o < a.length; o++) "1" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "left" : "2" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "center" : a[o].templateAreaFontCenter = "right", - "0" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "normal" : "1" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "bold" : a[o].templateAreaFontStyle = "italic", - a[o].templateAreaFontSize = a[o].templateAreaFontSize / r + "px", a[o].templateAreaHeight = a[o].templateAreaHeight / r, - a[o].templateAreaWidth = a[o].templateAreaWidth / r, a[o].templateAreaDown = a[o].templateAreaDown / r, - a[o].templateAreaTop = a[o].templateAreaTop / r, a[o].templateAreaRight = a[o].templateAreaRight / r, - a[o].templateAreaLeft = a[o].templateAreaLeft / r; - e.setData({ - cardInfo: t.data, - areaList: a - }); - }).catch(function(e) {}); - }, - getNameCradArea: function() { - var e = this, a = []; - t.restAjax.get(t.restAjax.path("{cardUrl}app/cardtemplatearea/listcardtemplateareabytemplateid/" + e.data.cardId, [ t.tradeUrl ]), {}, { - headers: { - token: t.globalData.token - } - }, function(t, r) { - for (var o = 0; o < r.length; o++) if (r[o].focus = !1, "1" != r[o].templateAreaType) a.push(r[o]); else { - var n = parseInt(r[o].templateAreaFontSize.replace("px", "")); - n = Math.floor(750 * n / wx.getSystemInfoSync().windowWidth) + "rpx", r[o].templateAreaFontSize = n, - a.push(r[o]); - } - e.setData({ - areaList: a - }); - }, function(e, a) { - t.dialog.msg(a.msg); - }); - }, - editInfo: function(t) { - var a = t.currentTarget.dataset.num, r = t.detail.value, o = "areaList[" + a + "].templateAreaFontValue"; - this.setData(e({}, o, r)); - }, - giveFocus: function(t) { - console.log(t.currentTarget.dataset.cur); - var a = "areaList[" + t.currentTarget.dataset.cur + "].focus"; - this.setData(e({}, a, !0)); - }, - continueCreate: function() { - this.setData({ - showHide: !1 - }); - }, - backList: function() { - wx.navigateBack({ - delta: 1 - }); - }, - getUserInfo: function() { - t.restAjax.get(t.restAjax.path("{loginUrl}app/user/get-app-user", [ t.personIntroUrl ]), {}, { - headers: { - token: t.globalData.token - } - }, function(e, a) { - t.globalData.userInfo = a; - }, function(e, a) { - t.dialog.msg(a.msg); - }); - }, - getFileId: function(a) { - var r = this, o = a, n = r.data.areaList[o].templateAreaFontValue; - console.log(n); - var i = r.data.areaList[o].picturesTemplateAreaId; - t.http.get(t.urls.getFileId.format({ - picturesTemplateAreaId: i - }), { - header: { - token: t.globalData.token - }, - data: { - content: n - } - }).then(function(t) { - console.log(t.data); - var a = "areaList[" + o + "].templateAreaFile"; - r.setData(e({}, a, t.data.data)); - }).catch(function(e) {}); - }, - onLoad: function(e) { - this.setData({ - cardId: e.id, - token: t.globalData.token, - pageType: e.type, - id: e.taskId - }), this.getNameCard(); - }, - postRecord: function(e) { - t.restAjax.post(t.restAjax.path("{loginUrl}app/cardtemplateforwardingrecord/savecardtemplateforwardingrecord", [ t.tradeUrl ]), { - encryptedData: e.encryptedData, - iv: e.iv, - templateUseId: this.data.cardId, - templateFromUserId: this.data.oldToken, - templateToUserId: this.data.token - }, { - headers: { - token: this.data.token - } - }, function(e, t) { - console.log("1" + t); - }, function(e, a) { - t.dialog.msg(a.msg); - }); - }, - openPage: function() {}, - onShow: function() { - console.log(this.data.imgTempSrc), "" != this.data.imgTempSrc && this.doUploadImg(this.data.imgTempSrc); + data: { + preview: '', + showHide: false, + isLoading: false, + isMain: '', + cardPersonId: '', + choose_index: 0, + active: 0, + cardUrl: app.baseUrls.baseCardUrl, + areaList: [], + cardInfo: {}, + bgImg: '', + fontFamilyList: [], + useFontFamily: '', + cardId: '', + cardHeight: '', + shareTicket: '', + encryptedData: '', + iv: '', + isFromOut: false, + token: '', + oldToken: '', + fromMine: false, + imgTempSrc: '', + currentIndex: 0, + windowWidth: app.globalData.windowWidth, + scale: 1, + pageType: null + }, + tabChange: function (e) { + this.setData({ + active: e.detail + }) + if (this.data.active == 0) { + } else if (this.data.active == 1) { + // 服务 + if (app.globalData.servicePageType == 1) { + wx.redirectTo({ + url: '/pages/shop/catalog/bannerlist/bannerlist', + }) + } else if (app.globalData.servicePageType == 2) { + wx.redirectTo({ + url: '/pages/shop/catalog/column/column', + }) + } else if (app.globalData.servicePageType == 3) { + wx.redirectTo({ + url: '/pages/shop/catalog/list/list', + }) + } else if (app.globalData.servicePageType == 4) { + wx.redirectTo({ + url: '/pages/shop/bespeak/bespeak', + }) + } + } else { + //我的 + wx.redirectTo({ + url: '/pages/mine/index/index', + }) } + // this.setData({ + // active: e.detail + // }), 0 == this.data.active || (1 == this.data.active ? 1 == app.globalData.servicePageType ? wx.redirectTo({ + // url: "/pages/shop/catalog/bannerlist/bannerlist" + // }) : 2 == app.globalData.servicePageType ? wx.redirectTo({ + // url: "/pages/shop/catalog/column/column" + // }) : 3 == app.globalData.servicePageType ? wx.redirectTo({ + // url: "/pages/shop/catalog/list/list" + // }) : 4 == app.globalData.servicePageType && wx.redirectTo({ + // url: "/pages/shop/bespeak/bespeak" + // }) : wx.redirectTo({ + // url: "/pages/mine/index/index" + // })); + }, + createMyCard: function () { + var self = this + wx.showLoading({ + title: '生成中...', + success() { + self.setData({ + isLoading: true + }) + } + }) + var content = { + pictureTemplateId: self.data.cardId, + cardTemplateUseAreaList: [] + } + for (let i = 0; i < self.data.areaList.length; i++) { + if (self.data.areaList[i].templateAreaType != '1') { + var info = { + cardTemplateUseId: "", + picturesTemplateAreaId: self.data.areaList[i].picturesTemplateAreaId, + templateAreaFile: self.data.areaList[i].templateAreaFile, + templateAreaFontValue: self.data.areaList[i].templateAreaFontValue + } + content.cardTemplateUseAreaList.push(info) + } + } + app.http.post(app.urls.creatCard, { + data: content, + header: { + token: app.globalData.token + } + }).then(res => { + console.log(res) + // "200" == t.statusCode && e.getMineCardList(); + if (res.statusCode == '200') { + self.getMineCardList(); + } + }).catch(res => { + console.log(res) + self.setData({ + isLoading: false, + showHide: false + }) + }) + // var e = this; + // wx.showLoading({ + // title: "生成中...", + // success: function () { + // e.setData({ + // isLoading: !0 + // }); + // } + // }); + // for (var a = { + // pictureTemplateId: e.data.cardId, + // cardTemplateUseAreaList: [] + // }, r = 0; r < e.data.areaList.length; r++) if ("1" != e.data.areaList[r].templateAreaType) { + // var o = { + // cardTemplateUseId: "", + // picturesTemplateAreaId: e.data.areaList[r].picturesTemplateAreaId, + // templateAreaFile: e.data.areaList[r].templateAreaFile, + // templateAreaFontValue: e.data.areaList[r].templateAreaFontValue + // }; + // a.cardTemplateUseAreaList.push(o); + // } + // app.http.post(t.urls.creatCard, { + // data: a, + // header: { + // token: t.globalData.token + // } + // }).then(function (t) { + // console.log(t), "200" == t.statusCode && e.getMineCardList(); + // }).catch(function (t) { + // e.setData({ + // isLoading: !1, + // showHide: !1 + // }); + // }); + }, + getMineCardList: function () { + var e = this; + app.http.get(app.urls.getMyCard, { + header: { + token: app.globalData.token + }, + data: {} + }).then(function (t) { + e.setData({ + cardList: t.data + }), t.data.length > 0 && (e.setDefaultCard(t.data[0].cardTemplateUseId), console.log(e.data.pageType), + "org" == e.data.pageType ? e.saveOrgCard(t.data[0].cardTemplateUseId) : e.saveCardIdToSyzl(t.data[0].cardTemplateUseId)); + }).catch(function (t) { + wx.hideLoading({}), e.setData({ + isLoading: !1, + showHide: !1 + }); + }); + }, + saveCardIdToSyzl: function (e) { + console.log("设置网格员名片" + e); + var a = this; + app.restAjax.put(app.restAjax.path(app.apis.doUpdateCard, [app.baseUrls.requestUrl, a.data.id]), { + cardSysId: e + }, { + headers: { + token: app.globalData.token + } + }, function (e, t) { + console.log(e), console.log(t), "200" == e && a.onShowHintDialog(); + }, function (e, t) { + wx.hideLoading({}), wx.showToast({ + icon: "none", + title: "设置名片失败" + }), console.log(e), console.log(t); + }); + }, + saveOrgCard: function (e) { + var a = this; + app.restAjax.put(app.restAjax.path(app.apis.doUpdateOrg, [app.baseUrls.requestUrl, a.data.id]), { + cardSysId: e + }, { + headers: { + token: app.globalData.token + } + }, function (e, t) { + "200" == e && a.onShowHintDialog(); + }, function (e, t) { + wx.hideLoading({}), wx.showToast({ + icon: "none", + title: "设置名片失败" + }), console.log(t); + }); + }, + setDefaultCard: function (e) { + app.http.put(app.urls.setDefaultCard.format({ + cardTemplateUseId: e + }), { + header: { + token: app.globalData.token + } + }).then(function (e) { }).catch(function (e) { }); + }, + onShowHintDialog: function () { + var e = this; + wx.hideLoading({ + success: function (t) { + e.setData({ + isLoading: !1 + }), wx.showModal({ + content: "恭喜您名片创建成功,如需查看请到(我的 → 我的卡包)", + cancelText: "继续创建", + confirmText: "返回列表", + cancelColor: "#333333", + confirmColor: "#333333", + success: function (t) { + t.confirm ? e.backList() : e.continueCreate(); + } + }); + } + }); + }, + inputBlur: function (e) { + var t = e.detail.value, a = e.currentTarget.dataset.num, r = e.currentTarget.dataset.item, o = r.templateAreaFontLength; + "" != t && o > 0 && (t = t.substr(0, o), this.data.areaList[a].templateAreaFontValue = t, + this.data.areaList[a].focus = !1, this.setData({ + areaList: this.data.areaList + })), "1" != r.templateAreaServerLink && this.getFileId(a); + }, + choosePhoto: function (e) { + var t = e.currentTarget.dataset.cur, a = e.currentTarget.dataset.item; + console.log(t), this.setData({ + currentIndex: t + }); + var r = a.templateAreaWidth / a.templateAreaHeight; + wx.chooseMedia({ + count: 1, + mediaType: ['image'], + sourceType: ['album', 'camera'], + success: function (e) { + console.log(e) + wx.navigateTo({ + url: "/packagecard/common/corpperimg/cropperimg?imgSrc=" + e.tempFiles[0].tempFilePath + "&scale=" + r + }); + } + }) + }, + doUploadImg: function (path) { + var _self = this + wx.showLoading({ + title: '上传中...', + }) + app.http.upload(app.urls.doUploadImg, { + path: path, + name: 'image', + header: { + token: app.globalData.token + } + }).then(res => { + wx.hideLoading({}) + res = JSON.parse(res) + var change = 'areaList[' + _self.data.currentIndex + '].templateAreaFile' + _self.setData({ + [change]: res.data + }) + wx.showToast({ + title: '上传成功', + duration: 1500 + }) + _self.setData({ + imgTempSrc: '', + currentIndex: 0 + }) + }).catch(res => { + _self.setData({ + imgTempSrc: '', + currentIndex: 0 + }) + }) + // var r = this; + // wx.showLoading({ + // title: "上传中..." + // }), app.http.upload(app.urls.doUploadImg, { + // path: a, + // name: "image", + // header: { + // token: app.globalData.token + // } + // }).then(function (t) { + // wx.hideLoading({}), t = JSON.parse(t); + // var a = "areaList[" + r.data.currentIndex + "].templateAreaFile"; + // r.setData(e({}, a, t.data)), wx.showToast({ + // title: "上传成功", + // duration: 1500 + // }), r.setData({ + // imgTempSrc: "", + // currentIndex: 0 + // }); + // }).catch(function (e) { + // r.setData({ + // imgTempSrc: "", + // currentIndex: 0 + // }); + // }); + }, + getNameCard: function () { + var self = this; + app.http.get(app.urls.getCardDetail.format({ + cardTemplateId: self.data.cardId + }), { + header: { + token: app.globalData.token + }, + data: {} + }).then(res => { + var area = res.data.areaList + var scale = res.data.picturesTemplateWidth / self.data.windowWidth + res.data.picturesTemplateWidth = res.data.picturesTemplateWidth / scale + res.data.picturesTemplateHeight = res.data.picturesTemplateHeight / scale + for (let i = 0; i < area.length; i++) { + if (area[i].templateAreaFontCenter == '1') { + area[i].templateAreaFontCenter = 'left' + } else if (area[i].templateAreaFontCenter == '2') { + area[i].templateAreaFontCenter = 'center' + } else { + area[i].templateAreaFontCenter = 'right' + } + if (area[i].templateAreaFontBold == '0') { + area[i].templateAreaFontBold = 'normal' + } else if (area[i].templateAreaFontBold == '1') { + area[i].templateAreaFontBold = 'bold' + } else { + area[i]['templateAreaFontStyle'] = 'italic' + } + area[i].templateAreaFontSize = area[i].templateAreaFontSize / scale + 'px' + area[i].templateAreaHeight = area[i].templateAreaHeight / scale + area[i].templateAreaWidth = area[i].templateAreaWidth / scale + area[i].templateAreaDown = area[i].templateAreaDown / scale + area[i].templateAreaTop = area[i].templateAreaTop / scale + area[i].templateAreaRight = area[i].templateAreaRight / scale + area[i].templateAreaLeft = area[i].templateAreaLeft / scale + } + self.setData({ + cardInfo: res.data, + areaList: area + }) + }) + .catch(err => { + + }) + // var e = this; + // e.data.fromMine && e.data.cardPersonId, app.http.get(app.urls.getCardDetail.format({ + // cardTemplateId: e.data.cardId + // }), { + // header: { + // token: app.globalData.token + // }, + // data: {} + // }).then(function (t) { + // var a = t.data.areaList, r = t.data.picturesTemplateWidth / e.data.windowWidth; + // t.data.picturesTemplateWidth = t.data.picturesTemplateWidth / r, t.data.picturesTemplateHeight = t.data.picturesTemplateHeight / r; + // for (var o = 0; o < a.length; o++) "1" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "left" : "2" == a[o].templateAreaFontCenter ? a[o].templateAreaFontCenter = "center" : a[o].templateAreaFontCenter = "right", + // "0" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "normal" : "1" == a[o].templateAreaFontBold ? a[o].templateAreaFontBold = "bold" : a[o].templateAreaFontStyle = "italic", + // a[o].templateAreaFontSize = a[o].templateAreaFontSize / r + "px", a[o].templateAreaHeight = a[o].templateAreaHeight / r, + // a[o].templateAreaWidth = a[o].templateAreaWidth / r, a[o].templateAreaDown = a[o].templateAreaDown / r, + // a[o].templateAreaTop = a[o].templateAreaTop / r, a[o].templateAreaRight = a[o].templateAreaRight / r, + // a[o].templateAreaLeft = a[o].templateAreaLeft / r; + // e.setData({ + // cardInfo: t.data, + // areaList: a + // }); + // }).catch(function (e) { }); + }, + getNameCradArea: function () { + var e = this, a = []; + app.restAjax.get(app.restAjax.path("{cardUrl}app/cardtemplatearea/listcardtemplateareabytemplateid/" + e.data.cardId, [app.tradeUrl]), {}, { + headers: { + token: app.globalData.token + } + }, function (t, r) { + for (var o = 0; o < r.length; o++) if (r[o].focus = !1, "1" != r[o].templateAreaType) a.push(r[o]); else { + var n = parseInt(r[o].templateAreaFontSize.replace("px", "")); + n = Math.floor(750 * n / wx.getSystemInfoSync().windowWidth) + "rpx", r[o].templateAreaFontSize = n, + a.push(r[o]); + } + e.setData({ + areaList: a + }); + }, function (e, a) { + t.dialog.msg(a.msg); + }); + }, + editInfo: function (t) { + var a = t.currentTarget.dataset.num, r = t.detail.value, o = "areaList[" + a + "].templateAreaFontValue"; + this.setData(e({}, o, r)); + }, + giveFocus: function (t) { + console.log(t.currentTarget.dataset.cur); + var a = "areaList[" + t.currentTarget.dataset.cur + "].focus"; + this.setData(e({}, a, !0)); + }, + continueCreate: function () { + this.setData({ + showHide: !1 + }); + }, + backList: function () { + wx.navigateBack({ + delta: 1 + }); + }, + getUserInfo: function () { + app.restAjax.get(app.restAjax.path("{loginUrl}app/user/get-app-user", [app.personIntroUrl]), {}, { + headers: { + token: app.globalData.token + } + }, function (e, a) { + app.globalData.userInfo = a; + }, function (e, a) { + app.dialog.msg(a.msg); + }); + }, + getFileId: function (a) { + var r = this, o = a, n = r.data.areaList[o].templateAreaFontValue; + console.log(n); + var i = r.data.areaList[o].picturesTemplateAreaId; + app.http.get(app.urls.getFileId.format({ + picturesTemplateAreaId: i + }), { + header: { + token: app.globalData.token + }, + data: { + content: n + } + }).then(function (t) { + console.log(t.data); + var a = "areaList[" + o + "].templateAreaFile"; + r.setData(e({}, a, t.data.data)); + }).catch(function (e) { }); + }, + onLoad: function (e) { + this.setData({ + cardId: e.id, + token: app.globalData.token, + pageType: e.type, + id: e.taskId + }); + console.log(app.globalData.token) + this.getNameCard(); + }, + postRecord: function (e) { + app.restAjax.post(app.restAjax.path("{loginUrl}app/cardtemplateforwardingrecord/savecardtemplateforwardingrecord", [app.tradeUrl]), { + encryptedData: e.encryptedData, + iv: e.iv, + templateUseId: this.data.cardId, + templateFromUserId: this.data.oldToken, + templateToUserId: this.data.token + }, { + headers: { + token: this.data.token + } + }, function (e, t) { + console.log("1" + t); + }, function (e, a) { + t.dialog.msg(a.msg); + }); + }, + openPage: function () { }, + onShow: function () { + console.log(this.data.imgTempSrc), "" != this.data.imgTempSrc && this.doUploadImg(this.data.imgTempSrc); + } }); \ No newline at end of file diff --git a/packagecard/cardDetail/cardDetail.wxml b/packagecard/cardDetail/cardDetail.wxml index bc72bbc..80bce02 100755 --- a/packagecard/cardDetail/cardDetail.wxml +++ b/packagecard/cardDetail/cardDetail.wxml @@ -1,55 +1,91 @@ - - - {{item.templateAreaFontValue}} - - - - - {{item.templateAreaFontValue}} - - + + + + + + {{item.templateAreaFontValue}} + + + + + + + + + + + {{item.templateAreaFontValue}} + + + + - 适用行业:{{cardInfo.templateIndustryName}} - - - - - - {{item.templateAreaName}} - 最多输入{{item.templateAreaFontLength}}个字符 - - - - - - - - - - {{item.templateAreaName}} - 最多输入1张图片 - - - - - + 适用行业:{{cardInfo.templateIndustryName}} + + + + + + {{item.templateAreaName}} + 最多输入{{item.templateAreaFontLength}}个字符 + + + + + + + + + + {{item.templateAreaName}} + 最多输入1张图片 + + + + + + + + - + - - 创建成功 - 恭喜您名片创建成功,如需查看请到(我的 → 我的卡包) - - 继续创建 - 返回模板 - + + 创建成功 + 恭喜您名片创建成功,如需查看请到(我的 → 我的卡包) + + 继续创建 + 返回模板 - + + \ No newline at end of file diff --git a/packagecard/cardDetail/cardDetail.wxss b/packagecard/cardDetail/cardDetail.wxss index 4f9bee1..a1b28f2 100755 --- a/packagecard/cardDetail/cardDetail.wxss +++ b/packagecard/cardDetail/cardDetail.wxss @@ -1,215 +1,223 @@ .card { - box-sizing: border-box; + width: 100%; height: 0; position: relative; - width: 100%; + box-sizing: border-box; z-index: 100; -} - -.card-bgImg { - height: 100%; - left: 0; + /* text-align: center; */ + } + + .card-bgImg { position: absolute; top: 0; + left: 0; width: 100%; -} - -.area-box { - background: none!important; - white-space: nowrap; - z-index: 111; -} - -.area-box image { height: 100%; + } + + .area-box { + background: none !important; + z-index: 111; + } + + .area-box image { width: 100%; -} - -.card-info { - margin-top: 15rpx; + height: 100%; + } + + .card-info { padding-bottom: 100rpx; width: 100%; -} - -.card-title { - background: #fff; + margin-top: 15rpx; + } + + .card-title { font-size: 30rpx; - padding: 15rpx; + background: #ffffff; width: 100%; -} - -.row { - background: #fff; -} - -.row,.row-ver { - border-bottom: 1rpx solid #f5f5f5; - display: flex; -} - -.row-ver { - background-color: #fff; - flex-direction: column; padding: 15rpx; -} - -.row-ver:nth-child(1) { - padding: 15rpx 15rpx 7.5rpx; -} - -.row-ver:last-child { - padding: 7.5rpx 15rpx 15rpx; -} - -.item-title { - color: grey; + } + + .row { + display: flex; + border-bottom: 1px solid #EEE; + background: #ffffff; + border-bottom: 1rpx solid #f5f5f5; + } + + .row-ver { + display: flex; + border-bottom: 1px solid #EEE; + border-bottom: 1rpx solid #f5f5f5; + flex-direction: column; + background-color: #ffffff; + padding: 15rpx; + } + + .row-ver:nth-child(1) { + padding: 15rpx 15rpx 7.5rpx 15rpx; + } + + .row-ver:last-child { + padding: 7.5rpx 15rpx 15rpx 15rpx; + } + + .item-title { flex: 1; font-size: 32rpx; line-height: 50rpx; -} - -.item-title-box { + color: #808080; + } + + .item-title-box { + display: flex; flex-direction: row; justify-content: space-between; - margin-top: 7.5rpx; -} - -.item-input,.item-title-box { align-items: center; - display: flex; -} - -.item-input { - box-sizing: border-box; + margin-top: 7.5rpx; + } + + .item-input { flex: 4; + box-sizing: border-box; + display: flex; + align-items: center; margin-top: 15rpx; -} - -.item-input input { - color: #333; - font-size: 32rpx; - height: 50rpx; - text-align: left; + } + + .item-input input { width: 100%; -} - -.item-input image { + text-align: left; + height: 50rpx; + font-size: 32rpx; + color: #333; + } + + .item-input image { max-width: 70%; -} - -.item-code-input image { - max-height: 160rpx; + /* max-height: 120rpx; */ + } + + .item-code-input image { max-width: 35%; -} - -.hide-link { - background: rgba(0,0,0,.6); + max-height: 160rpx; + } + + + + + .hide-link { + position: fixed; + top: 0; bottom: 0; left: 0; - position: fixed; right: 0; - top: 0; + background: rgba(0, 0, 0, 0.6); z-index: 1000; -} - -.hide { - background: #fff; - border-radius: 10rpx; - flex-direction: column; - left: 50%; + } + + .hide { position: absolute; top: 50%; - transform: translate(-50%,-50%); + left: 50%; width: 60%; -} - -.hide,.hide-btn { - align-items: center; - display: flex; - justify-content: center; -} - -.hide-btn { - background: #1d7ff0; - border-bottom-left-radius: 10rpx; - border-bottom-right-radius: 10rpx; - color: #fff; - font-size: 30rpx; - height: 60rpx; - width: 50%; -} - -.hide-btn:nth-child(1) { - background: #e6b980; - border-bottom-left-radius: 10rpx; - border-bottom-right-radius: 0rpx; -} - -.hide-btn:last-child { - border-bottom-left-radius: 0rpx; - border-bottom-right-radius: 10rpx; -} - -.hide-text { - color: #000; - font-size: 36rpx; - padding: 50rpx 30rpx; -} - -.hide-title { - color: #ffc107; - font-size: 43rpx; - padding: 10rpx; -} - -.hide-btn-box { - display: flex; - justify-content: space-between; - width: 100%; -} - -.input-box { - width: 100%; -} - -.content-box { - align-items: center; + transform: translate(-50%, -50%); + border-radius: 10rpx; + background: #fff; display: flex; flex-direction: column; justify-content: center; - padding: 15rpx; - width: 100%; -} - -.cuIcon-cameraadd { - font-size: 60rpx; -} - -.card-img-box { align-items: center; + } + + .hide-btn { + display: flex; + width: 50%; + height: 60rpx; + background: #1d7ff0; + color: #fff; + font-size: 30rpx; + justify-content: center; + align-items: center; + border-bottom-left-radius: 10rpx; + border-bottom-right-radius: 10rpx; + } + + .hide-btn:nth-child(1) { + background: #E6B980; + border-bottom-left-radius: 10rpx; + border-bottom-right-radius: 0rpx; + } + + .hide-btn:last-child { + border-bottom-left-radius: 0rpx; + border-bottom-right-radius: 10rpx; + } + + .hide-text { + font-size: 36rpx; + color: #000; + padding: 50rpx 30rpx; + } + + .hide-title { + font-size: 43rpx; + color: #ffC107; + padding: 10rpx; + } + + .hide-btn-box { + display: flex; + width: 100%; + justify-content: space-between; + } + + .input-box { + width: 100%; + } + + .content-box { + width: 100%; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + padding: 15rpx; + } + + .cuIcon-cameraadd { + font-size: 60rpx; + } + + .card-img-box { display: flex; flex-direction: row; - justify-content: space-between; + align-items: center; margin-right: 40rpx; -} - -.card-img-box image { - height: 200rpx; + justify-content: space-between; + } + + .card-img-box image { width: 200rpx; -} - -.hint-txt { + height: 200rpx; + } + + .hint-txt { + text-align: right; color: #fd9494; font-size: 24rpx; - text-align: right; -} - -.wrap-line { - white-space: pre-line; -} - -.wrap-center { + } + + + /* 换行 */ + .wrap-line { + overflow-wrap: break-word; + } + + /* 居中 */ + .wrap-center { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -} \ No newline at end of file + overflow-wrap: break-word; + } \ No newline at end of file diff --git a/packagecard/cardList/cardList.wxml b/packagecard/cardList/cardList.wxml index e82c4a7..a72fb58 100755 --- a/packagecard/cardList/cardList.wxml +++ b/packagecard/cardList/cardList.wxml @@ -42,4 +42,4 @@ - + \ No newline at end of file diff --git a/packagecard/common/corpperimg/cropperimg.js b/packagecard/common/corpperimg/cropperimg.js index 9cf3273..ff14a02 100755 --- a/packagecard/common/corpperimg/cropperimg.js +++ b/packagecard/common/corpperimg/cropperimg.js @@ -8,49 +8,56 @@ Page({ width: 250, height: 250 }, - onLoad: function(e) { + onLoad: function (e) { + console.log(e.imgSrc) wx.setNavigationBarTitle({ title: "图片裁剪" - }), this.cropper = this.selectComponent("#image-cropper"), this.setData({ - src: e.imgSrc - }), wx.showLoading({ + }); + this.cropper = this.selectComponent("#image-cropper"); + this.setData({ + src: e.imgSrc, + scale:e.scale + }); + wx.showLoading({ title: "加载中" }); }, - cropperload: function(e) { + cropperload: function (e) { console.log("cropper初始化完成"); }, - loadimage: function(e) { - console.log("图片加载完成", e.detail), wx.hideLoading(), this.cropper.imgReset(); + loadimage: function (e) { + console.log("图片加载完成", e.detail); + wx.hideLoading(); + this.cropper.imgReset(); }, - clickcut: function(e) { + clickcut: function (e) { console.log(e.detail); var t = getCurrentPages(); (t.length >= 2 ? t[t.length - 2] : void 0).setData({ imgTempSrc: e.detail.url }), wx.navigateBack({}); }, - cropperDone: function(e) { + cropperDone: function (e) { var t = e.detail, o = t.src, a = (t.cropperData, getCurrentPages()); (a.length >= 2 ? a[a.length - 2] : void 0).setData({ imgTempSrc: o }); }, - cropperCancel: function() { + cropperCancel: function () { wx.navigateBack({}); }, - doCropperDone: function(e) { + doCropperDone: function (e) { var t = getCurrentPages(); (t.length >= 2 ? t[t.length - 2] : void 0).setData({ imgTempSrc: e }), wx.navigateBack({}); }, - cropperFail: function(e) { + cropperFail: function (e) { e.detail; console.log(e), wx.showToast({ title: "裁剪失败,请重试", icon: "none", - success: function() { + success: function () { wx.navigateBack({}); } }); diff --git a/packagecard/common/corpperimg/cropperimg.json b/packagecard/common/corpperimg/cropperimg.json index 804c9e6..6603f4a 100644 --- a/packagecard/common/corpperimg/cropperimg.json +++ b/packagecard/common/corpperimg/cropperimg.json @@ -1,6 +1,6 @@ { "usingComponents": { - "image-cropper": "/vant/dist/cropper/index", + "image-cropper": "/vant/dist/cropper/image-cropper", "van-tabbar": "/vant/dist/tabbar/index", "van-tabbar-item": "/vant/dist/tabbar-item/index", "van-swipe-cell": "/vant/dist/swipe-cell/index", diff --git a/packagecard/moments/edit/momentedit.js b/packagecard/moments/edit/momentedit.js index 6481a00..2cceb40 100755 --- a/packagecard/moments/edit/momentedit.js +++ b/packagecard/moments/edit/momentedit.js @@ -1,846 +1,846 @@ -var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = wx.getRecorderManager(), i = wx.createInnerAudioContext(), s = requirePlugin("chooseLocation"), n = { - latitude: 39.89631551, - longitude: 116.323459711 +var a = getApp(); var e = wx.getRecorderManager(); var i = wx.createInnerAudioContext(); var s = requirePlugin("chooseLocation"); var n = { + latitude: 39.89631551, + longitude: 116.323459711 }; Page({ - data: { - uploadCount: 0, - uploadVideoCount: 0, - currentIndex: 0, - columnId: "", - uId: "", - fieldList: [], - textList: [], - textareaList: [], - audioList: [], - videoList: [], - photoList: [], - linkList: [], - locationList: [], - isShowText: !1, - isShowDesc: !1, - isShowPhoto: !1, - isShowLink: !1, - isShowAudio: !1, - isShowVideo: !1, - isShowTags: !1, - isShowType: !1, - tempText: "", - tempDesc: "", - linkStr: "", - map: null, - waitFlag: !1, - isStartRecord: !1, - speck_time: 0, - speedStep: 5, - setInter: "", - currentItem: void 0, - isAuthAudio: !1, - title: "栏目内容修改", - curLat: 0, - curLng: 0, - isRecording: !1, - maxDuration: 60, - displayType: [ { - name: "九宫格", - id: 1 - }, { - name: "轮播", - id: 2 - }, { - name: "轮播(自动)", - id: 3 - }, { - name: "平铺", - id: 4 - } ], - selDisplayType: 1, - displayTypeStr: "九宫格" - }, - onLoad: function(t) { - this.setData({ - columnId: t.id, - uId: t.uid, - title: t.title + "修改" - }), wx.setNavigationBarTitle({ - title: t.title + "修改" - }); - this.checkPermission(), this.getMomentContent(); - }, - getMomentContent: function() { - wx.showLoading({ - title: "加载中..." - }); - var t = this; - a.http.get(a.urls.getMomentsContent.format({ - configColumnId: t.data.columnId, - uid: t.data.uId - }), { - header: { - token: a.globalData.token + data: { + uploadCount: 0, + uploadVideoCount: 0, + currentIndex: 0, + columnId: "", + uId: "", + fieldList: [], + textList: [], + textareaList: [], + audioList: [], + videoList: [], + photoList: [], + linkList: [], + locationList: [], + isShowText: !1, + isShowDesc: !1, + isShowPhoto: !1, + isShowLink: !1, + isShowAudio: !1, + isShowVideo: !1, + isShowTags: !1, + isShowType: !1, + tempText: "", + tempDesc: "", + linkStr: "", + map: null, + waitFlag: !1, + isStartRecord: !1, + speck_time: 0, + speedStep: 5, + setInter: "", + currentItem: void 0, + isAuthAudio: !1, + title: "栏目内容修改", + curLat: 0, + curLng: 0, + isRecording: !1, + maxDuration: 60, + displayType: [{ + name: "九宫格", + id: 1 + }, { + name: "轮播", + id: 2 + }, { + name: "轮播(自动)", + id: 3 + }, { + name: "平铺", + id: 4 + }], + selDisplayType: 1, + displayTypeStr: "九宫格" + }, + onLoad: function (t) { + this.setData({ + columnId: t.id, + uId: t.uid, + title: t.title + "修改" + }), wx.setNavigationBarTitle({ + title: t.title + "修改" + }); + this.checkPermission(), this.getMomentContent(); + }, + getMomentContent: function () { + wx.showLoading({ + title: "加载中..." + }); + var t = this; + a.http.get(a.urls.getMomentsContent.format({ + configColumnId: t.data.columnId, + uid: t.data.uId + }), { + header: { + token: a.globalData.token + } + }).then(function (a) { + wx.hideLoading({}), t.buildDetail(a.data); + }).catch(function (t) { + wx.hideLoading({}), console.log(t); + }); + }, + buildDetail: function (t) { + var e = this; + t.list.forEach(function (t) { + switch (t.dataType) { + case "2": + var i = t.value.split("@"), s = i[0].split(","); + if (i.length > 1) switch (i[1]) { + case "1": + e.setData({ + selDisplayType: "1", + displayTypeStr: "九宫格" + }); + break; + + case "2": + e.setData({ + selDisplayType: "2", + displayTypeStr: "轮播" + }); + break; + + case "3": + e.setData({ + selDisplayType: "3", + displayTypeStr: "轮播(自动)" + }); + break; + + case "4": + e.setData({ + selDisplayType: "4", + displayTypeStr: "平铺" + }); + } + var n = []; + s.forEach(function (t) { + if (t.length > 0) { + var e = { + id: t, + path: a.baseUrls.baseCardUrl + t + }; + n.push(e); } - }).then(function(a) { - wx.hideLoading({}), t.buildDetail(a.data); - }).catch(function(t) { - wx.hideLoading({}), console.log(t); - }); - }, - buildDetail: function(t) { - var e = this; - t.list.forEach(function(t) { - switch (t.dataType) { - case "2": - var i = t.value.split("@"), s = i[0].split(","); - if (i.length > 1) switch (i[1]) { - case "1": - e.setData({ - selDisplayType: "1", - displayTypeStr: "九宫格" - }); - break; + }), t.valueList = n; + break; - case "2": - e.setData({ - selDisplayType: "2", - displayTypeStr: "轮播" - }); - break; - - case "3": - e.setData({ - selDisplayType: "3", - displayTypeStr: "轮播(自动)" - }); - break; - - case "4": - e.setData({ - selDisplayType: "4", - displayTypeStr: "平铺" - }); - } - var n = []; - s.forEach(function(t) { - if (t.length > 0) { - var e = { - id: t, - path: a.baseUrls.baseCardUrl + t - }; - n.push(e); - } - }), t.valueList = n; - break; - - case "4": - s = t.value.split(","), n = []; - for (var o = 0; o < s.length; o++) if (s[o].length > 0) { - var d = s[o].split("&"), r = a.baseUrls.baseCardUrl + d[0], l = a.baseUrls.baseCardUrl + d[1], u = { - id: d[0], - thumbId: d[1], - path: r, - imgPath: l - }; - n.push(u); - } - t.valueList = n; - break; - - case "3": - s = t.value.split(","), n = []; - s.forEach(function(t) { - if (t.length > 0) { - var e = t.split("&"), i = "00:00", s = 100; - if (e.length > 1) { - var o = e[1]; - s = o; - var d = parseInt(o / 60), r = parseInt(o % 60); - i = (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r); - } - var l = { - id: e[0], - path: a.baseUrls.baseCardUrl + e[0], - isPlay: !1, - duration: s, - curDuation: 0, - curDurationStr: "00:00", - totalDurationStr: i - }; - n.push(l); - } - }), t.valueList = n; - break; - - case "6": - s = t.value.split("-"), n = []; - s.forEach(function(t) { - if (t.length > 0) { - var a = t.split(","), e = { - name: "", - address: "", - latitude: a[0], - longitude: a[1] - }; - n.push(e); - } - }), t.valueList = n; - break; - - case "8": - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) && (t.selValue = a.dataName); - }); - break; - - case "9": - var c = ""; - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) ? (c += a.dataName + ",", a.isSel = !0) : a.isSel = !1; - }), c = c.substr(0, c.length - 1), t.selValue = c; - } - }), e.setData({ - fieldList: t.list - }); - }, - showMutliSel: function(t) { - this.setData({ - isShowTags: !0, - currentIndex: t.currentTarget.dataset.index - }); - }, - pickerChange: function(t) { - var a = t.currentTarget.dataset.index, e = t.detail.value; - this.data.fieldList[a].index = e, this.data.fieldList[a].value = this.data.fieldList[a].dictionariesList[e].dataId, - this.data.fieldList[a].selValue = this.data.fieldList[a].dictionariesList[e].dataName, - this.setData({ - fieldList: this.data.fieldList - }); - }, - inputText: function(t) { - var a = t.currentTarget.dataset.index; - this.data.fieldList[a].value = t.detail.value, this.setData({ - fieldList: this.data.fieldList - }); - }, - checkPermission: function() { - var t = this; - wx.getSetting({ - success: function(a) { - var e = a.authSetting["scope.record"]; - void 0 === e ? wx.authorize({ - scope: "scope.record", - success: function() { - t.setData({ - isAuthAudio: !0 - }); - }, - fail: function() { - t.setData({ - isAuthAudio: !1 - }); - } - }) : e || t.openSetting(); - } - }); - }, - openSetting: function() { - wx.showModal({ - title: "提示", - content: "发布内容需要您授权录音权限.", - success: function(t) { - t.confirm && wx.openSetting({ - withSubscriptions: !0 - }); - } - }); - }, - onShow: function() { - if (null != s.getLocation()) { - var t = this.data.fieldList[this.data.curMapIndex]; - t.valueList.length < t.maxCount && (this.data.fieldList[this.data.curMapIndex].valueList.push(s.getLocation()), - this.setData({ - fieldList: this.data.fieldList - })); - } - var a = this; - wx.getSetting({ - withSubscriptions: !0, - success: function(t) { - var e = t.authSetting["scope.record"]; - a.setData({ - isAuthAudio: e - }); - } - }); - }, - onUnload: function() { - s.setLocation(null), this.setData({ - map: null - }); - }, - chooseVideo: function(t) { - var a = this, e = t.currentTarget.dataset.item, i = e.maxCount - e.valueList.length, s = t.currentTarget.dataset.index; - wx.chooseMedia({ - count: Number.parseInt(i), - mediaType: [ "video" ], - sourceType: [ "camera", "album" ], - maxDuration: 60, - success: function(t) { - t.tempFiles.length > 0 && (t.tempFiles[0].duration <= a.data.maxDuration ? a.doUploadVideo(s, t.tempFiles, a.data.uploadVideoCount) : wx.showToast({ - title: "视频最长60秒", - icon: "none" - })); - }, - fail: function(t) {} - }); - }, - doUploadVideo: function(t, e, i) { - wx.showLoading({ - title: "上传中..." - }); - var s = this, n = e.length; - s.data.uploadVideoCount < n ? a.http.upload(a.urls.doUploadVideo, { - path: e[s.data.uploadVideoCount].tempFilePath, - name: "video", - header: { - token: a.globalData.token - } - }).then(function(a) { - wx.hideLoading({}); - var i = JSON.parse(a).data; - s.doUploadVideoImg(t, i, e, s.data.uploadVideoCount); - }).catch(function(a) { - wx.hideLoading({}), s.setData({ - uploadVideoCount: ++s.data.uploadVideoCount - }), s.doUploadVideo(t, e, s.data.uploadVideoCount); - }) : (wx.hideLoading({}), s.setData({ - uploadVideoCount: 0 - })); - }, - doUploadVideoImg: function(t, e, i, s) { - wx.showLoading({ - title: "上传中..." - }); - var n = this; - a.http.upload(a.urls.doUploadImg, { - path: i[n.data.uploadVideoCount].thumbTempFilePath, - name: "image", - header: { - token: a.globalData.token - } - }).then(function(s) { - console.log(s), wx.hideLoading({}); - var o = a.baseUrls.baseCardUrl + e, d = a.baseUrls.baseCardUrl + JSON.parse(s).data, r = JSON.parse(s).data, l = { - id: e, - thumbId: r, - path: o, - imgPath: d + case "4": + s = t.value.split(","), n = []; + for (var o = 0; o < s.length; o++) if (s[o].length > 0) { + var d = s[o].split("&"), r = a.baseUrls.baseCardUrl + d[0], l = a.baseUrls.baseCardUrl + d[1], u = { + id: d[0], + thumbId: d[1], + path: r, + imgPath: l }; - n.data.fieldList[t].valueList.push(l), n.setData({ - fieldList: n.data.fieldList - }), n.setData({ - uploadVideoCount: ++n.data.uploadVideoCount - }), n.doUploadVideo(t, i, n.data.uploadVideoCount); - }).catch(function(a) { - console.log(a), wx.hideLoading({}), n.setData({ - uploadVideoCount: ++n.data.uploadVideoCount - }), n.doUploadVideo(t, i, n.data.uploadVideoCount); - }); - }, - viewVideo: function(t) { - var a = [ { - url: t.currentTarget.dataset.url, - type: "video" - } ]; - wx.previewMedia({ - sources: a, - current: 0, - showmenu: !1 - }); - }, - delVideo: function(t) { - var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx; - wx.showModal({ - title: "提示", - content: "确定要删除该视频吗?", - cancelText: "取消", - confirmText: "确定", - success: function(t) { - t.confirm && (a.data.fieldList[e].valueList.splice(i, 1), a.setData({ - fieldList: a.data.fieldList - })); + n.push(u); + } + t.valueList = n; + break; + + case "3": + s = t.value.split(","), n = []; + s.forEach(function (t) { + if (t.length > 0) { + var e = t.split("&"), i = "00:00", s = 100; + if (e.length > 1) { + var o = e[1]; + s = o; + var d = parseInt(o / 60), r = parseInt(o % 60); + i = (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r); + } + var l = { + id: e[0], + path: a.baseUrls.baseCardUrl + e[0], + isPlay: !1, + duration: s, + curDuation: 0, + curDurationStr: "00:00", + totalDurationStr: i + }; + n.push(l); } - }); - }, - addLink: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("LINK" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.linkList.length < t.count) { - if ("" == this.data.linkStr) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.linkList.push(this.data.linkStr), this.setData({ - linkList: this.data.linkList, - linkStr: "" - }), this.data.linkList.length == t.count && this.setData({ - isShowLink: !1 - }); - } - }, - addDesc: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXTAREA" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.textareaList.length < t.count) { - if ("" == this.data.tempDesc) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.textareaList.push(this.data.tempDesc), this.setData({ - textareaList: this.data.textareaList, - tempDesc: "" - }), this.data.textareaList.length == t.count && this.setData({ - isShowDesc: !1 - }); - } - }, - addStr: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXT" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.textList.length < t.count) { - if ("" == this.data.tempText) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.textList.push(this.data.tempText), this.setData({ - textList: this.data.textList, - tempText: "" - }), this.data.textList.length == t.count && this.setData({ - isShowText: !1 - }); - } - }, - delText: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.textList.splice(t.currentTarget.dataset.index, 1), a.setData({ - textList: a.data.textList - })); + }), t.valueList = n; + break; + + case "6": + s = t.value.split("-"), n = []; + s.forEach(function (t) { + if (t.length > 0) { + var a = t.split(","), e = { + name: "", + address: "", + latitude: a[0], + longitude: a[1] + }; + n.push(e); } - }); - }, - delLink: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.linkList.splice(t.currentTarget.dataset.index, 1), a.setData({ - linkList: a.data.linkList - })); - } - }); - }, - delDesc: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.textareaList.splice(t.currentTarget.dataset.index, 1), a.setData({ - textareaList: a.data.textareaList - })); - } - }); - }, - confirmSel: function(t) { - var a = t.detail, e = (a.piacker, a.value); - this.setData({ - selDisplayType: e.id, - displayTypeStr: e.name, - isShowType: !1 - }); - }, - cancelSel: function(t) { - this.setData({ - isShowType: !1 - }); - }, - textInput: function(a) { - this.setData(t({}, a.currentTarget.id, a.detail.value)); - }, - onHide: function(t) { - this.setData({ - isShowText: !1, - isShowDesc: !1, - isShowPhoto: !1, - isShowLink: !1, - isShowAudio: !1, - isShowVideo: !1, - isShowTags: !1 - }); - }, - chooseTags: function(t) { - var a = t.currentTarget.dataset.idx; - this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel = !this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel, - this.setData({ - fieldList: this.data.fieldList - }); - var e = "", i = ""; - this.data.fieldList[this.data.currentIndex].dictionariesList.forEach(function(t) { - t.isSel && (e += t.dataName + ",", i += t.dataId + ","); - }), e = e.substr(0, e.length - 1), i = i.substr(0, i.length - 1), this.data.fieldList[this.data.currentIndex].selValue = e, - this.data.fieldList[this.data.currentIndex].value = i, this.setData({ - fieldList: this.data.fieldList - }); - }, - selTags: function() { - this.setData({ - isShowTags: !1 - }); - }, - choosePhoto: function(t) { - var a = this, e = t.currentTarget.dataset.item, i = t.currentTarget.dataset.index, s = e.maxCount - e.valueList.length; - wx.chooseImage({ - count: Number.parseInt(s), - sourceType: [ "album", "camera" ], - success: function(t) { - a.doUploadImg(i, t.tempFilePaths, a.data.uploadCount); - }, - fail: function(t) {} - }); - }, - delImg: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该图片吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.fieldList[t.currentTarget.dataset.itemindex].valueList.splice(t.currentTarget.dataset.index, 1), - a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - viewImg: function(t) { - var a = [ t.currentTarget.dataset.url ]; - wx.previewImage({ - urls: a, - current: t.currentTarget.dataset.url - }); - }, - doUploadImg: function(t, e, i) { - wx.showLoading({ - title: "上传中..." - }); - var s = this, n = e.length; - s.data.uploadCount < n ? a.http.upload(a.urls.doUploadImg, { - path: e[s.data.uploadCount], - name: "image", - header: { - token: a.globalData.token - } - }).then(function(i) { - wx.hideLoading({}); - var n = JSON.parse(i).data, o = { - id: n, - path: a.baseUrls.baseCardUrl + n - }; - s.data.fieldList[t].valueList.push(o), s.setData({ - fieldList: s.data.fieldList - }), s.setData({ - uploadCount: ++s.data.uploadCount - }), s.doUploadImg(t, e, s.data.uploadCount); - }).catch(function(a) { - wx.hideLoading({}), s.setData({ - uploadCount: ++s.data.uploadCount - }), s.doUploadImg(t, e, s.data.uploadCount); - }) : (wx.hideLoading({}), s.setData({ - uploadCount: 0 - })); - }, - chooseLocation: function(t) { - var a = t.currentTarget.dataset.index; - this.setData({ - curMapIndex: a - }); - var e = JSON.stringify(n); - wx.navigateTo({ - url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(e, "&category=").concat("生活服务,娱乐休闲") - }); - }, - delMap: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), - a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - delAudio: function(t) { - console.log(t); - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该音频吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), - a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - doStartRecord: function() { - var t = this; - wx.getSetting({ - success: function(a) { - a.authSetting["scope.record"] ? t.startRecord() : wx.authorize({ - scope: "scope.record", - success: function() { - t.startRecord(); - } - }); - } - }); - }, - startRecord: function() { - var t = this; - t.data.setInter = setInterval(function() { - var a = parseInt(t.data.speck_time + 1); + }), t.valueList = n; + break; + + case "8": + t.dictionariesList.forEach(function (a) { + -1 != t.value.indexOf(a.dataId) && (t.selValue = a.dataName); + }); + break; + + case "9": + var c = ""; + t.dictionariesList.forEach(function (a) { + -1 != t.value.indexOf(a.dataId) ? (c += a.dataName + ",", a.isSel = !0) : a.isSel = !1; + }), c = c.substr(0, c.length - 1), t.selValue = c; + } + }), e.setData({ + fieldList: t.list + }); + }, + showMutliSel: function (t) { + this.setData({ + isShowTags: !0, + currentIndex: t.currentTarget.dataset.index + }); + }, + pickerChange: function (t) { + var a = t.currentTarget.dataset.index, e = t.detail.value; + this.data.fieldList[a].index = e, this.data.fieldList[a].value = this.data.fieldList[a].dictionariesList[e].dataId, + this.data.fieldList[a].selValue = this.data.fieldList[a].dictionariesList[e].dataName, + this.setData({ + fieldList: this.data.fieldList + }); + }, + inputText: function (t) { + var a = t.currentTarget.dataset.index; + this.data.fieldList[a].value = t.detail.value, this.setData({ + fieldList: this.data.fieldList + }); + }, + checkPermission: function () { + var t = this; + wx.getSetting({ + success: function (a) { + var e = a.authSetting["scope.record"]; + void 0 === e ? wx.authorize({ + scope: "scope.record", + success: function () { t.setData({ - speck_time: parseInt(a), - isStartRecord: !0 - }), t.data.speck_time > 0 && t.data.speck_time <= 59 ? t.start() : (clearInterval(t.data.setInter), - t.stop(), wx.showToast({ - title: "录音最长60S哦!", - duration: 2e3, - icon: "none" - })); - }, 1e3); - }, - doEndRecord: function() { - clearInterval(this.data.setInter), this.data.speck_time > 3 ? (clearInterval(this.data.setInter), - this.stop(!0), this.setData({ - speck_time: "0", - isStartRecord: !1 - })) : (clearInterval(this.data.setInter), this.stop(!1), wx.showToast({ - title: "录制时间过短", - duration: 2e3, - icon: "none" - }), this.setData({ - speck_time: "0", - isStartRecord: !1 - })); - }, - start: function() { - e.start({ - duration: 6e4, - format: "mp3" - }), e.onStart(function() { - console.log("recorder start"); - }), e.onError(function(t) { - console.log(t), _self.stop(!1); + isAuthAudio: !0 + }); + }, + fail: function () { + t.setData({ + isAuthAudio: !1 + }); + } + }) : e || t.openSetting(); + } + }); + }, + openSetting: function () { + wx.showModal({ + title: "提示", + content: "发布内容需要您授权录音权限.", + success: function (t) { + t.confirm && wx.openSetting({ + withSubscriptions: !0 }); - }, - stop: function(t) { - var a = this; - e.stop(), e.onStop(function(e) { - t && a.doUploadAudio(e); - }); - }, - doUploadAudio: function(t) { - wx.showLoading({ - title: "上传中..." - }); - var e = this; - a.http.upload(a.urls.doUploadAudio, { - path: t.tempFilePath, - name: "audio", - header: { - token: a.globalData.token - } - }).then(function(i) { - if (wx.hideLoading({}), e.data.fieldList[e.data.currentIndex].valueList.length < e.data.currentItem.maxCount) { - wx.hideLoading({}); - var s = JSON.parse(i).data, n = a.baseUrls.baseCardUrl + s, o = parseInt(t.duration / 1e3), d = parseInt(o / 60), r = parseInt(o % 60), l = { - id: s, - path: n, - isPlay: !1, - duration: o, - curDuation: 0, - curDurationStr: "00:00", - totalDurationStr: (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r) - }; - e.data.fieldList[e.data.currentIndex].valueList.push(l), e.setData({ - fieldList: e.data.fieldList - }), e.data.fieldList[e.data.currentIndex].valueList.length == e.data.currentItem.maxCount && e.setData({ - isShowAudio: !1 - }); - } - }).catch(function(t) {}); - }, - play: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.item, n = this; - n.data.fieldList[a].valueList.forEach(function(t) { - t.isPlay && i.stop(), t.isPlay = !1, t.curDuation = 0, t.curDuationStr = "00:00"; - }), s.isPlay || ((i = wx.createInnerAudioContext()).src = n.data.fieldList[a].valueList[e].path, - i.autoplay = !0), i.onPlay(function() { - n.data.fieldList[a].valueList[e].isPlay = !0, n.setData({ - fieldList: n.data.fieldList - }); - }), i.onCanplay(function(t) {}), i.onStop(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList - }); - }), i.onEnded(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList - }); - }), i.onError(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList - }); - }), i.onSeeking(function() { - console.log(i.currentTime); - }), i.onWaiting(function() {}), i.onTimeUpdate(function() { - if (i.duration != 1 / 0) { - n.data.fieldList[a].valueList[e].curDuration = parseInt(i.currentTime), n.data.fieldList[a].valueList[e].duration = parseInt(i.duration), - console.log(i.duration); - var t = parseInt(i.currentTime / 60), s = parseInt(i.currentTime % 60), o = parseInt(i.duration / 60), d = parseInt(i.duration % 60), r = t > 9 ? t : "0" + t, l = s > 9 ? s : "0" + s, u = o > 9 ? o : "0" + o, c = +d > 9 ? d : "0" + d; - n.data.fieldList[a].valueList[e].curDurationStr = r + ":" + l, n.data.fieldList[a].valueList[e].totalDurationStr = u + ":" + c, - n.setData({ - fieldList: n.data.fieldList - }); - } - }); - }, - rewind: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; - t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration - this.data.speedStep, - i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ - fieldList: this.data.fieldList - })); - }, - speed: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; - t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration + this.data.speedStep, - i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ - fieldList: this.data.fieldList - })); - }, - slider4change: function(t) { - t.currentTarget.dataset.item.isPlay && i.seek(t.detail.value); - }, - showDialog: function(t) { - console.log(t), this.setData({ - isShowAudio: !0, - currentItem: t.currentTarget.dataset.item, - currentIndex: t.currentTarget.dataset.index - }); - }, - doPublish: function() { - if (this.checkParams()) { - wx.showToast({ - title: "保存中..." - }); - var t = this.buildParams(); - console.log(t), a.http.post(a.urls.doSaveMoments.format({ - configColumnId: this.data.columnId - }), { - data: t, - header: { - token: a.globalData.token - } - }).then(function(t) { - wx.hideLoading({}); - var a = getCurrentPages(); - a[a.length - 2].setData({ - isRefresh: !0 - }), wx.navigateBack({ - delta: 1 - }); - }).catch(function(t) { - console.log(t); - }); - } - }, - checkParams: function() { - for (var t = !0, a = 0; a < this.data.fieldList.length; a++) { - var e = this.data.fieldList[a]; - if (e.must) if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) { - if (e.value.length <= 0) { - wx.showToast({ - title: "请输入或选择" + e.comment, - icon: "none" - }), t = !1; - break; - } - } else if (e.valueList.length <= 0) { - wx.showToast({ - title: "请上传" + e.comment, - icon: "none" - }), t = !1; - break; - } - } - return t; - }, - buildParams: function() { - for (var t = { - uid: this.data.uId - }, a = 0; a < this.data.fieldList.length; a++) { - var e = this.data.fieldList[a]; - if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) e.value.length > 0 && (t[e.name] = e.value); else if (e.valueList.length > 0) { - var i = ""; - "6" == e.dataType ? e.valueList.forEach(function(t) { - i += t.latitude + "," + t.longitude + "-"; - }) : "4" == e.dataType ? e.valueList.forEach(function(t) { - i += t.id + "&" + t.thumbId + ","; - }) : "3" == e.dataType ? e.valueList.forEach(function(t) { - i += t.id + "&" + t.duration + ","; - }) : "2" == e.dataType ? (e.valueList.forEach(function(t) { - i += t.id + ","; - }), i = i.substr(0, i.length - 1), i += "@" + this.data.selDisplayType) : e.valueList.forEach(function(t) { - i += t.id + ","; - }), "2" != e.dataType && (i = i.substr(0, i.length - 1)), t[e.name] = i; - } - } - return t; - }, - showDisplayType: function(t) { + } + }); + }, + onShow: function () { + if (null != s.getLocation()) { + var t = this.data.fieldList[this.data.curMapIndex]; + t.valueList.length < t.maxCount && (this.data.fieldList[this.data.curMapIndex].valueList.push(s.getLocation()), this.setData({ - isShowType: !0 - }); + fieldList: this.data.fieldList + })); } + var a = this; + wx.getSetting({ + withSubscriptions: !0, + success: function (t) { + var e = t.authSetting["scope.record"]; + a.setData({ + isAuthAudio: e + }); + } + }); + }, + onUnload: function () { + s.setLocation(null), this.setData({ + map: null + }); + }, + chooseVideo: function (t) { + var a = this, e = t.currentTarget.dataset.item, i = e.maxCount - e.valueList.length, s = t.currentTarget.dataset.index; + wx.chooseMedia({ + count: Number.parseInt(i), + mediaType: ["video"], + sourceType: ["camera", "album"], + maxDuration: 60, + success: function (t) { + t.tempFiles.length > 0 && (t.tempFiles[0].duration <= a.data.maxDuration ? a.doUploadVideo(s, t.tempFiles, a.data.uploadVideoCount) : wx.showToast({ + title: "视频最长60秒", + icon: "none" + })); + }, + fail: function (t) { } + }); + }, + doUploadVideo: function (t, e, i) { + wx.showLoading({ + title: "上传中..." + }); + var s = this, n = e.length; + s.data.uploadVideoCount < n ? a.http.upload(a.urls.doUploadVideo, { + path: e[s.data.uploadVideoCount].tempFilePath, + name: "video", + header: { + token: a.globalData.token + } + }).then(function (a) { + wx.hideLoading({}); + var i = JSON.parse(a).data; + s.doUploadVideoImg(t, i, e, s.data.uploadVideoCount); + }).catch(function (a) { + wx.hideLoading({}), s.setData({ + uploadVideoCount: ++s.data.uploadVideoCount + }), s.doUploadVideo(t, e, s.data.uploadVideoCount); + }) : (wx.hideLoading({}), s.setData({ + uploadVideoCount: 0 + })); + }, + doUploadVideoImg: function (t, e, i, s) { + wx.showLoading({ + title: "上传中..." + }); + var n = this; + a.http.upload(a.urls.doUploadImg, { + path: i[n.data.uploadVideoCount].thumbTempFilePath, + name: "image", + header: { + token: a.globalData.token + } + }).then(function (s) { + console.log(s), wx.hideLoading({}); + var o = a.baseUrls.baseCardUrl + e, d = a.baseUrls.baseCardUrl + JSON.parse(s).data, r = JSON.parse(s).data, l = { + id: e, + thumbId: r, + path: o, + imgPath: d + }; + n.data.fieldList[t].valueList.push(l), n.setData({ + fieldList: n.data.fieldList + }), n.setData({ + uploadVideoCount: ++n.data.uploadVideoCount + }), n.doUploadVideo(t, i, n.data.uploadVideoCount); + }).catch(function (a) { + console.log(a), wx.hideLoading({}), n.setData({ + uploadVideoCount: ++n.data.uploadVideoCount + }), n.doUploadVideo(t, i, n.data.uploadVideoCount); + }); + }, + viewVideo: function (t) { + var a = [{ + url: t.currentTarget.dataset.url, + type: "video" + }]; + wx.previewMedia({ + sources: a, + current: 0, + showmenu: !1 + }); + }, + delVideo: function (t) { + var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx; + wx.showModal({ + title: "提示", + content: "确定要删除该视频吗?", + cancelText: "取消", + confirmText: "确定", + success: function (t) { + t.confirm && (a.data.fieldList[e].valueList.splice(i, 1), a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + addLink: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("LINK" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.linkList.length < t.count) { + if ("" == this.data.linkStr) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.linkList.push(this.data.linkStr), this.setData({ + linkList: this.data.linkList, + linkStr: "" + }), this.data.linkList.length == t.count && this.setData({ + isShowLink: !1 + }); + } + }, + addDesc: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXTAREA" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.textareaList.length < t.count) { + if ("" == this.data.tempDesc) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.textareaList.push(this.data.tempDesc), this.setData({ + textareaList: this.data.textareaList, + tempDesc: "" + }), this.data.textareaList.length == t.count && this.setData({ + isShowDesc: !1 + }); + } + }, + addStr: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXT" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.textList.length < t.count) { + if ("" == this.data.tempText) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.textList.push(this.data.tempText), this.setData({ + textList: this.data.textList, + tempText: "" + }), this.data.textList.length == t.count && this.setData({ + isShowText: !1 + }); + } + }, + delText: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.textList.splice(t.currentTarget.dataset.index, 1), a.setData({ + textList: a.data.textList + })); + } + }); + }, + delLink: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.linkList.splice(t.currentTarget.dataset.index, 1), a.setData({ + linkList: a.data.linkList + })); + } + }); + }, + delDesc: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.textareaList.splice(t.currentTarget.dataset.index, 1), a.setData({ + textareaList: a.data.textareaList + })); + } + }); + }, + confirmSel: function (t) { + var a = t.detail, e = (a.piacker, a.value); + this.setData({ + selDisplayType: e.id, + displayTypeStr: e.name, + isShowType: !1 + }); + }, + cancelSel: function (t) { + this.setData({ + isShowType: !1 + }); + }, + textInput: function (a) { + this.setData(t({}, a.currentTarget.id, a.detail.value)); + }, + onHide: function (t) { + this.setData({ + isShowText: !1, + isShowDesc: !1, + isShowPhoto: !1, + isShowLink: !1, + isShowAudio: !1, + isShowVideo: !1, + isShowTags: !1 + }); + }, + chooseTags: function (t) { + var a = t.currentTarget.dataset.idx; + this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel = !this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel, + this.setData({ + fieldList: this.data.fieldList + }); + var e = "", i = ""; + this.data.fieldList[this.data.currentIndex].dictionariesList.forEach(function (t) { + t.isSel && (e += t.dataName + ",", i += t.dataId + ","); + }), e = e.substr(0, e.length - 1), i = i.substr(0, i.length - 1), this.data.fieldList[this.data.currentIndex].selValue = e, + this.data.fieldList[this.data.currentIndex].value = i, this.setData({ + fieldList: this.data.fieldList + }); + }, + selTags: function () { + this.setData({ + isShowTags: !1 + }); + }, + choosePhoto: function (t) { + var a = this, e = t.currentTarget.dataset.item, i = t.currentTarget.dataset.index, s = e.maxCount - e.valueList.length; + wx.chooseImage({ + count: Number.parseInt(s), + sourceType: ["album", "camera"], + success: function (t) { + a.doUploadImg(i, t.tempFilePaths, a.data.uploadCount); + }, + fail: function (t) { } + }); + }, + delImg: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该图片吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.fieldList[t.currentTarget.dataset.itemindex].valueList.splice(t.currentTarget.dataset.index, 1), + a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + viewImg: function (t) { + var a = [t.currentTarget.dataset.url]; + wx.previewImage({ + urls: a, + current: t.currentTarget.dataset.url + }); + }, + doUploadImg: function (t, e, i) { + wx.showLoading({ + title: "上传中..." + }); + var s = this, n = e.length; + s.data.uploadCount < n ? a.http.upload(a.urls.doUploadImg, { + path: e[s.data.uploadCount], + name: "image", + header: { + token: a.globalData.token + } + }).then(function (i) { + wx.hideLoading({}); + var n = JSON.parse(i).data, o = { + id: n, + path: a.baseUrls.baseCardUrl + n + }; + s.data.fieldList[t].valueList.push(o), s.setData({ + fieldList: s.data.fieldList + }), s.setData({ + uploadCount: ++s.data.uploadCount + }), s.doUploadImg(t, e, s.data.uploadCount); + }).catch(function (a) { + wx.hideLoading({}), s.setData({ + uploadCount: ++s.data.uploadCount + }), s.doUploadImg(t, e, s.data.uploadCount); + }) : (wx.hideLoading({}), s.setData({ + uploadCount: 0 + })); + }, + chooseLocation: function (t) { + var a = t.currentTarget.dataset.index; + this.setData({ + curMapIndex: a + }); + var e = JSON.stringify(n); + wx.navigateTo({ + url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(e, "&category=").concat("生活服务,娱乐休闲") + }); + }, + delMap: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), + a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + delAudio: function (t) { + console.log(t); + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该音频吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), + a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + doStartRecord: function () { + var t = this; + wx.getSetting({ + success: function (a) { + a.authSetting["scope.record"] ? t.startRecord() : wx.authorize({ + scope: "scope.record", + success: function () { + t.startRecord(); + } + }); + } + }); + }, + startRecord: function () { + var t = this; + t.data.setInter = setInterval(function () { + var a = parseInt(t.data.speck_time + 1); + t.setData({ + speck_time: parseInt(a), + isStartRecord: !0 + }), t.data.speck_time > 0 && t.data.speck_time <= 59 ? t.start() : (clearInterval(t.data.setInter), + t.stop(), wx.showToast({ + title: "录音最长60S哦!", + duration: 2e3, + icon: "none" + })); + }, 1e3); + }, + doEndRecord: function () { + clearInterval(this.data.setInter), this.data.speck_time > 3 ? (clearInterval(this.data.setInter), + this.stop(!0), this.setData({ + speck_time: "0", + isStartRecord: !1 + })) : (clearInterval(this.data.setInter), this.stop(!1), wx.showToast({ + title: "录制时间过短", + duration: 2e3, + icon: "none" + }), this.setData({ + speck_time: "0", + isStartRecord: !1 + })); + }, + start: function () { + e.start({ + duration: 6e4, + format: "mp3" + }), e.onStart(function () { + console.log("recorder start"); + }), e.onError(function (t) { + console.log(t), _self.stop(!1); + }); + }, + stop: function (t) { + var a = this; + e.stop(), e.onStop(function (e) { + t && a.doUploadAudio(e); + }); + }, + doUploadAudio: function (t) { + wx.showLoading({ + title: "上传中..." + }); + var e = this; + a.http.upload(a.urls.doUploadAudio, { + path: t.tempFilePath, + name: "audio", + header: { + token: a.globalData.token + } + }).then(function (i) { + if (wx.hideLoading({}), e.data.fieldList[e.data.currentIndex].valueList.length < e.data.currentItem.maxCount) { + wx.hideLoading({}); + var s = JSON.parse(i).data, n = a.baseUrls.baseCardUrl + s, o = parseInt(t.duration / 1e3), d = parseInt(o / 60), r = parseInt(o % 60), l = { + id: s, + path: n, + isPlay: !1, + duration: o, + curDuation: 0, + curDurationStr: "00:00", + totalDurationStr: (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r) + }; + e.data.fieldList[e.data.currentIndex].valueList.push(l), e.setData({ + fieldList: e.data.fieldList + }), e.data.fieldList[e.data.currentIndex].valueList.length == e.data.currentItem.maxCount && e.setData({ + isShowAudio: !1 + }); + } + }).catch(function (t) { }); + }, + play: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.item, n = this; + n.data.fieldList[a].valueList.forEach(function (t) { + t.isPlay && i.stop(), t.isPlay = !1, t.curDuation = 0, t.curDuationStr = "00:00"; + }), s.isPlay || ((i = wx.createInnerAudioContext()).src = n.data.fieldList[a].valueList[e].path, + i.autoplay = !0), i.onPlay(function () { + n.data.fieldList[a].valueList[e].isPlay = !0, n.setData({ + fieldList: n.data.fieldList + }); + }), i.onCanplay(function (t) { }), i.onStop(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onEnded(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onError(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onSeeking(function () { + console.log(i.currentTime); + }), i.onWaiting(function () { }), i.onTimeUpdate(function () { + if (i.duration != 1 / 0) { + n.data.fieldList[a].valueList[e].curDuration = parseInt(i.currentTime), n.data.fieldList[a].valueList[e].duration = parseInt(i.duration), + console.log(i.duration); + var t = parseInt(i.currentTime / 60), s = parseInt(i.currentTime % 60), o = parseInt(i.duration / 60), d = parseInt(i.duration % 60), r = t > 9 ? t : "0" + t, l = s > 9 ? s : "0" + s, u = o > 9 ? o : "0" + o, c = +d > 9 ? d : "0" + d; + n.data.fieldList[a].valueList[e].curDurationStr = r + ":" + l, n.data.fieldList[a].valueList[e].totalDurationStr = u + ":" + c, + n.setData({ + fieldList: n.data.fieldList + }); + } + }); + }, + rewind: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; + t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration - this.data.speedStep, + i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ + fieldList: this.data.fieldList + })); + }, + speed: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; + t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration + this.data.speedStep, + i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ + fieldList: this.data.fieldList + })); + }, + slider4change: function (t) { + t.currentTarget.dataset.item.isPlay && i.seek(t.detail.value); + }, + showDialog: function (t) { + console.log(t), this.setData({ + isShowAudio: !0, + currentItem: t.currentTarget.dataset.item, + currentIndex: t.currentTarget.dataset.index + }); + }, + doPublish: function () { + if (this.checkParams()) { + wx.showToast({ + title: "保存中..." + }); + var t = this.buildParams(); + console.log(t), a.http.post(a.urls.doSaveMoments.format({ + configColumnId: this.data.columnId + }), { + data: t, + header: { + token: a.globalData.token + } + }).then(function (t) { + wx.hideLoading({}); + var a = getCurrentPages(); + a[a.length - 2].setData({ + isRefresh: !0 + }), wx.navigateBack({ + delta: 1 + }); + }).catch(function (t) { + console.log(t); + }); + } + }, + checkParams: function () { + for (var t = !0, a = 0; a < this.data.fieldList.length; a++) { + var e = this.data.fieldList[a]; + if (e.must) if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) { + if (e.value.length <= 0) { + wx.showToast({ + title: "请输入或选择" + e.comment, + icon: "none" + }), t = !1; + break; + } + } else if (e.valueList.length <= 0) { + wx.showToast({ + title: "请上传" + e.comment, + icon: "none" + }), t = !1; + break; + } + } + return t; + }, + buildParams: function () { + for (var t = { + uid: this.data.uId + }, a = 0; a < this.data.fieldList.length; a++) { + var e = this.data.fieldList[a]; + if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) e.value.length > 0 && (t[e.name] = e.value); else if (e.valueList.length > 0) { + var i = ""; + "6" == e.dataType ? e.valueList.forEach(function (t) { + i += t.latitude + "," + t.longitude + "-"; + }) : "4" == e.dataType ? e.valueList.forEach(function (t) { + i += t.id + "&" + t.thumbId + ","; + }) : "3" == e.dataType ? e.valueList.forEach(function (t) { + i += t.id + "&" + t.duration + ","; + }) : "2" == e.dataType ? (e.valueList.forEach(function (t) { + i += t.id + ","; + }), i = i.substr(0, i.length - 1), i += "@" + this.data.selDisplayType) : e.valueList.forEach(function (t) { + i += t.id + ","; + }), "2" != e.dataType && (i = i.substr(0, i.length - 1)), t[e.name] = i; + } + } + return t; + }, + showDisplayType: function (t) { + this.setData({ + isShowType: !0 + }); + } }); \ No newline at end of file diff --git a/packagecard/moments/publish/momentpublish.js b/packagecard/moments/publish/momentpublish.js index 6959ac7..693caa3 100755 --- a/packagecard/moments/publish/momentpublish.js +++ b/packagecard/moments/publish/momentpublish.js @@ -1,12 +1,22 @@ -var t = getApp(), a = wx.getRecorderManager(), e = wx.createInnerAudioContext(), i = requirePlugin("chooseLocation"), s = { +// var t = getApp(), a = wx.getRecorderManager(), , i = requirePlugin("chooseLocation"), s = { +// latitude: 39.90877, +// longitude: 116.39695 +// }; + + +const app = getApp() +const recorderManager = wx.getRecorderManager() +var e = wx.createInnerAudioContext(); +const chooseLocation = requirePlugin('chooseLocation'); +var location = { latitude: 39.90877, longitude: 116.39695 -}; +}; //默认坐标点 Page({ data: { - maringHeight: t.globalData.CustomBar, - fieldList: [ { + maringHeight: app.globalData.CustomBar, + fieldList: [{ type: "text" }, { type: "video" @@ -22,7 +32,7 @@ Page({ type: "link" }, { type: "photo" - } ], + }], valueList: [], isShowInput: !1, isShowPhoto: !1, @@ -50,7 +60,7 @@ Page({ speedStep: 5, sourceType: "add", insertIndex: -1, - optionsList: [ { + optionsList: [{ id: "1", name: "选项一", isSel: !1 @@ -70,35 +80,35 @@ Page({ id: "5", name: "选项五", isSel: !1 - } ] + }] }, - onLoad: function(t) { + onLoad: function (t) { this.setData({ columnId: t.id }), this.checkPermission(), this.countBoxHeight(); }, - countBoxHeight: function() { + countBoxHeight: function () { var t = this, a = wx.createSelectorQuery(); - a.select("#top-box").boundingClientRect(), a.exec(function(a) { + a.select("#top-box").boundingClientRect(), a.exec(function (a) { t.setData({ topBoxHeight: a[0].height + 7 }); }); }, - onShow: function() { + onShow: function () { var t = this; - if (null != i.getLocation()) { - var a = i.getLocation(), e = { + if (null != chooseLocation.getLocation()) { + var a = chooseLocation.getLocation(), e = { type: "map" }; - e.value = a, "add" == t.data.sourceType ? t.data.valueList.push(e) : t.data.valueList.splice(t.data.currentIndex, "edit" == t.data.sourceType ? 1 : 0, e), - t.setData({ - valueList: t.data.valueList - }); + e.value = a, "add" == t.data.sourceType ? t.data.valueList.push(e) : t.data.valueList.splice(t.data.currentIndex, "edit" == t.data.sourceType ? 1 : 0, e), + t.setData({ + valueList: t.data.valueList + }); } wx.getSetting({ withSubscriptions: !0, - success: function(a) { + success: function (a) { var e = a.authSetting["scope.record"]; t.setData({ isAuthAudio: e @@ -106,50 +116,50 @@ Page({ } }); }, - showType: function(t) { + showType: function (t) { switch (t.currentTarget.dataset.type) { - case "text": - case "textarea": - this.setData({ - isShowInput: !0 - }); - break; + case "text": + case "textarea": + this.setData({ + isShowInput: !0 + }); + break; - case "video": - this.chooseVideo(); - break; + case "video": + this.chooseVideo(); + break; - case "audio": - this.checkRecordPermission(); - break; + case "audio": + this.checkRecordPermission(); + break; - case "photo": - this.chooseImg(); - break; + case "photo": + this.chooseImg(); + break; - case "map": - this.doChooseLocation(); - break; + case "map": + this.doChooseLocation(); + break; - case "select": - this.setData({ - isShowSelect: !0 - }); - break; + case "select": + this.setData({ + isShowSelect: !0 + }); + break; - case "link": - this.setData({ - isShowLink: !0 - }); + case "link": + this.setData({ + isShowLink: !0 + }); } }, - chooseImg: function() { + chooseImg: function () { var t = this; wx.chooseImage({ count: 9, - sourceType: [ "album", "camera" ], - success: function(a) { - console.log(a), a.tempFilePaths.forEach(function(a) { + sourceType: ["album", "camera"], + success: function (a) { + console.log(a), a.tempFilePaths.forEach(function (a) { var e = {}; e.path = a, t.data.photoList.push(e); }), t.setData({ @@ -157,7 +167,7 @@ Page({ isShowPhoto: !0 }); }, - fail: function(t) { + fail: function (t) { -1 == t.errMsg.indexOf("fail cancel") && wx.showToast({ title: "请重新选择", icon: "error" @@ -165,15 +175,15 @@ Page({ } }); }, - chooseVideo: function() { + chooseVideo: function () { var t = this; wx.chooseMedia({ count: 9, - mediaType: [ "video" ], - sourceType: [ "album", "camera" ], + mediaType: ["video"], + sourceType: ["album", "camera"], maxDuration: 60, - success: function(a) { - a.tempFiles.forEach(function(a) { + success: function (a) { + a.tempFiles.forEach(function (a) { var e = {}; e.path = a.tempFilePath, e.coverPath = a.thumbTempFilePath, t.data.videoList.push(e); }), t.setData({ @@ -181,7 +191,7 @@ Page({ isShowVideo: !0 }); }, - fail: function(t) { + fail: function (t) { -1 == t.errMsg.indexOf("fail cancel") && wx.showToast({ title: "请重新选择", icon: "error" @@ -189,7 +199,7 @@ Page({ } }); }, - showEditBox: function(t) { + showEditBox: function (t) { var a = t.currentTarget.dataset.idx; this.data.currentIndex == a ? this.setData({ currentIndex: -1 @@ -197,132 +207,132 @@ Page({ currentIndex: a }); }, - chooseDirection: function(t) { + chooseDirection: function (t) { var a = t.currentTarget.dataset.idx; this.setData({ selDirection: a }); }, - choosePhotoDisplay: function(t) { + choosePhotoDisplay: function (t) { var a = t.currentTarget.dataset.type; this.setData({ curSelPhotoDisplay: a }); }, - chooseVideoDisplay: function(t) { + chooseVideoDisplay: function (t) { var a = t.currentTarget.dataset.type; this.setData({ curVideoDisplay: a }); }, - chooseTextAlign: function(t) { + chooseTextAlign: function (t) { var a = t.currentTarget.dataset.type; this.setData({ curTextAlign: a }); }, - chooseFieldType: function(t) { + chooseFieldType: function (t) { var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.type; this.setData({ curFieldTypeIndex: a, curFieldType: e }); }, - confirmPhoto: function() { + confirmPhoto: function () { if (this.data.photoList.length > 0) { var t = []; - this.data.photoList.forEach(function(a) { + this.data.photoList.forEach(function (a) { var e = {}; e.path = a.path, t.push(e); }); var a = { type: "photo" }; - a.valueList = t, a.displayType = this.data.curSelPhotoDisplay, "add" == this.data.sourceType ? this.data.valueList.push(a) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, a), - this.setData({ - valueList: this.data.valueList, - photoList: [], - curSelPhotoDisplay: 1, - isShowPhoto: !1 - }); + a.valueList = t, a.displayType = this.data.curSelPhotoDisplay, "add" == this.data.sourceType ? this.data.valueList.push(a) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, a), + this.setData({ + valueList: this.data.valueList, + photoList: [], + curSelPhotoDisplay: 1, + isShowPhoto: !1 + }); } else wx.showToast({ title: "请选择图片", icon: "error" }); }, - confirmVideo: function() { + confirmVideo: function () { if (this.data.videoList.length > 0) { var t = []; - this.data.videoList.forEach(function(a) { + this.data.videoList.forEach(function (a) { var e = {}; e.path = a.path, e.coverPath = a.coverPath, t.push(e); }); var a = { type: "video" }; - a.valueList = t, a.displayType = this.data.curVideoDisplay, "add" == this.data.sourceType ? this.data.valueList.push(a) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, a), - this.setData({ - valueList: this.data.valueList, - videoList: [], - curVideoDisplay: 1, - isShowVideo: !1, - currentIndex: -1, - sourceType: "add" - }); + a.valueList = t, a.displayType = this.data.curVideoDisplay, "add" == this.data.sourceType ? this.data.valueList.push(a) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, a), + this.setData({ + valueList: this.data.valueList, + videoList: [], + curVideoDisplay: 1, + isShowVideo: !1, + currentIndex: -1, + sourceType: "add" + }); } else wx.showToast({ title: "请选择视频", icon: "error" }); }, - doInsert: function() { + doInsert: function () { var t = -1; - switch (t = 1 == this.data.selDirection ? this.data.currentIndex : ++this.data.currentIndex, + switch (t = 1 == this.data.selDirection ? this.data.currentIndex : ++this.data.currentIndex, this.setData({ insertIndex: t, sourceType: "insert", isInsert: !1 }), this.data.curFieldType) { - case "text": - case "textarea": - this.setData({ - isShowInput: !0 - }); - break; + case "text": + case "textarea": + this.setData({ + isShowInput: !0 + }); + break; - case "video": - this.chooseVideo(); - break; + case "video": + this.chooseVideo(); + break; - case "audio": - this.checkRecordPermission(); - break; + case "audio": + this.checkRecordPermission(); + break; - case "photo": - this.chooseImg(); - break; + case "photo": + this.chooseImg(); + break; - case "map": - this.doChooseLocation(); - break; + case "map": + this.doChooseLocation(); + break; - case "select": - this.setData({ - isShowSelect: !0 - }); - break; + case "select": + this.setData({ + isShowSelect: !0 + }); + break; - case "link": - this.setData({ - isShowLink: !0 - }); + case "link": + this.setData({ + isShowLink: !0 + }); } }, - hideEditBox: function() { + hideEditBox: function () { this.setData({ currentIndex: -1 }); }, - onClose: function() { + onClose: function () { this.setData({ isShowInput: !1, isShowLink: !1, @@ -330,17 +340,17 @@ Page({ sourceType: "add" }); }, - inputWatch: function(t) { + inputWatch: function (t) { this.setData({ curTextValue: t.detail.value }); }, - inputLink: function(t) { + inputLink: function (t) { this.setData({ curLinkText: t.detail.value }); }, - doConfirmLink: function() { + doConfirmLink: function () { if ("" == this.data.curLinkText) wx.showToast({ title: "请输入链接", icon: "error" @@ -348,15 +358,15 @@ Page({ var t = { type: "link" }; - t.value = this.data.curLinkText, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), - this.setData({ - valueList: this.data.valueList, - curLinkText: "", - isShowLink: !1 - }); + t.value = this.data.curLinkText, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), + this.setData({ + valueList: this.data.valueList, + curLinkText: "", + isShowLink: !1 + }); } }, - doConfirmInput: function() { + doConfirmInput: function () { if ("" == this.data.curTextValue) wx.showToast({ title: "请输入内容", icon: "error" @@ -367,39 +377,39 @@ Page({ t.value = this.data.curTextValue; var a = "left"; switch (this.data.curTextAlign) { - case "1": - a = "left"; - break; + case "1": + a = "left"; + break; - case "2": - a = "center"; - break; + case "2": + a = "center"; + break; - case "3": - a = "right"; + case "3": + a = "right"; } - t.textAlign = a, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), - this.setData({ - valueList: this.data.valueList, - curTextValue: "", - isShowInput: !1, - curTextAlign: "1" - }); + t.textAlign = a, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), + this.setData({ + valueList: this.data.valueList, + curTextValue: "", + isShowInput: !1, + curTextAlign: "1" + }); } }, - checkPermission: function() { + checkPermission: function () { var t = this; wx.getSetting({ - success: function(a) { + success: function (a) { var e = a.authSetting["scope.record"]; void 0 === e ? wx.authorize({ scope: "scope.record", - success: function() { + success: function () { t.setData({ isAuthAudio: !0 }); }, - fail: function() { + fail: function () { t.setData({ isAuthAudio: !1 }); @@ -408,123 +418,123 @@ Page({ } }); }, - openSetting: function() { + openSetting: function () { wx.showModal({ title: "提示", content: "发布内容需要您授权录音权限.", - success: function(t) { + success: function (t) { t.confirm && wx.openSetting({ withSubscriptions: !0 }); } }); }, - viewPhoto: function(t) { + viewPhoto: function (t) { var a = t.currentTarget.dataset.url; wx.previewImage({ - urls: [ a ] + urls: [a] }); }, - delPhoto: function(t) { + delPhoto: function (t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该图片吗?", cancelText: "取消", confirmText: "确定", - success: function(e) { + success: function (e) { e.confirm && (a.data.photoList.splice(t.currentTarget.dataset.index, 1), a.setData({ photoList: a.data.photoList })); } }); }, - viewVideo: function(t) { + viewVideo: function (t) { var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.index, i = this.data.valueList[e].valueList[a].path, s = {}; s.url = i, s.type = "video", wx.previewMedia({ - sources: [ s ] + sources: [s] }); }, - delVideo: function(t) { + delVideo: function (t) { var a = this, e = t.currentTarget.dataset.index; wx.showModal({ title: "提示", content: "确定要删除该视频吗?", - success: function(t) { + success: function (t) { t.confirm && (a.data.videoList.splice(e, 1), a.setData({ videoList: a.data.videoList })); } }); }, - doChooseLocation: function(t) { + doChooseLocation: function (t) { var a = JSON.stringify(s); wx.navigateTo({ url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(a, "&category=").concat("生活服务,娱乐休闲") }); }, - editItem: function(t) { + editItem: function (t) { var a = t.currentTarget.dataset.index; switch (this.setData({ sourceType: "edit" }), this.data.valueList[a].type) { - case "text": - case "textarea": - var e = "1"; - e = "left" == this.data.valueList[a].textAlign ? "1" : "center" == this.data.valueList[a].textAlign ? "2" : "3", - this.setData({ - isShowInput: !0, - curTextValue: this.data.valueList[a].value, - curTextAlign: e - }); - break; + case "text": + case "textarea": + var e = "1"; + e = "left" == this.data.valueList[a].textAlign ? "1" : "center" == this.data.valueList[a].textAlign ? "2" : "3", + this.setData({ + isShowInput: !0, + curTextValue: this.data.valueList[a].value, + curTextAlign: e + }); + break; - case "video": - this.setData({ - curVideoDisplay: this.data.valueList[a].displayType, - videoList: this.data.valueList[a].valueList, - isShowVideo: !0 - }); - break; + case "video": + this.setData({ + curVideoDisplay: this.data.valueList[a].displayType, + videoList: this.data.valueList[a].valueList, + isShowVideo: !0 + }); + break; - case "audio": - this.checkRecordPermission(); - break; + case "audio": + this.checkRecordPermission(); + break; - case "photo": - this.setData({ - curSelPhotoDisplay: this.data.valueList[a].displayType, - photoList: this.data.valueList[a].valueList, - isShowPhoto: !0 - }); - break; + case "photo": + this.setData({ + curSelPhotoDisplay: this.data.valueList[a].displayType, + photoList: this.data.valueList[a].valueList, + isShowPhoto: !0 + }); + break; - case "map": - s.latitude = this.data.valueList[a].value.latitude, s.longitude = this.data.valueList[a].value.longitude, - this.doChooseLocation(); - break; + case "map": + s.latitude = this.data.valueList[a].value.latitude, s.longitude = this.data.valueList[a].value.longitude, + this.doChooseLocation(); + break; - case "select": - break; + case "select": + break; - case "link": - this.setData({ - curLinkText: this.data.valueList[a].value, - isShowLink: !0 - }); + case "link": + this.setData({ + curLinkText: this.data.valueList[a].value, + isShowLink: !0 + }); } }, - insertItem: function(t) { + insertItem: function (t) { this.setData({ isInsert: !this.data.isInsert }); }, - delItem: function(t) { + delItem: function (t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该条数据吗?", - success: function(t) { + success: function (t) { t.confirm && (a.data.valueList.splice(a.data.currentIndex, 1), a.setData({ valueList: a.data.valueList, currentIndex: -1 @@ -532,21 +542,21 @@ Page({ } }); }, - chooseTags: function(t) { + chooseTags: function (t) { var a = t.currentTarget.dataset.idx, e = t.currentTarget.dataset.item; this.data.optionsList[a].isSel = !e.isSel, this.setData({ optionsList: this.data.optionsList }); }, - doConfirmSel: function() { + doConfirmSel: function () { var t = []; - this.data.optionsList.forEach(function(a) { + this.data.optionsList.forEach(function (a) { a.isSel && t.push(a); }); var a = { type: "select" }; - a.valueList = t, this.data.valueList.push(a), this.data.optionsList.forEach(function(t) { + a.valueList = t, this.data.valueList.push(a), this.data.optionsList.forEach(function (t) { t.isSel = !1; }), this.setData({ valueList: this.data.valueList, @@ -554,28 +564,28 @@ Page({ optionsList: this.data.optionsList }); }, - doConfirmAudio: function() { + doConfirmAudio: function () { this.data.audioFile.isPlay && e.stop(); var t = { type: "audio" }; - t.value = this.data.audioFile, this.data.audioFile.curDurationStr = "00:00", this.data.audioFile.curDuration = 0, - this.data.audioFile.isPlay = !1, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), - this.setData({ - valueList: this.data.valueList, - audioFile: null, - isShowAudio: !1 - }); + t.value = this.data.audioFile, this.data.audioFile.curDurationStr = "00:00", this.data.audioFile.curDuration = 0, + this.data.audioFile.isPlay = !1, "add" == this.data.sourceType ? this.data.valueList.push(t) : this.data.valueList.splice(this.data.currentIndex, "edit" == this.data.sourceType ? 1 : 0, t), + this.setData({ + valueList: this.data.valueList, + audioFile: null, + isShowAudio: !1 + }); }, - checkRecordPermission: function() { + checkRecordPermission: function () { var t = this; wx.getSetting({ - success: function(a) { + success: function (a) { a.authSetting["scope.record"] ? t.setData({ isShowAudio: !0 }) : wx.authorize({ scope: "scope.record", - success: function() { + success: function () { t.setData({ isShowAudio: !0 }); @@ -584,9 +594,9 @@ Page({ } }); }, - startRecord: function() { + startRecord: function () { var t = this; - t.data.setInter = setInterval(function() { + t.data.setInter = setInterval(function () { var a = parseInt(t.data.audioDuration + 1); t.setData({ audioDuration: parseInt(a), @@ -594,147 +604,152 @@ Page({ }); }, 1e3), t.start(); }, - start: function() { + start: function () { console.log("开始录音"); - a.start({ + recorderManager.start({ duration: 6e4, format: "mp3" - }), a.onStart(function() { + }), recorderManager.onStart(function () { console.log("recorder start"); - }), a.onError(function(t) { + }), recorderManager.onError(function (t) { console.log(t), _self.stop(!1); }); }, - doEndRecord: function() { + doEndRecord: function () { var t = this; - clearInterval(t.data.setInter), a.stop(), a.onStop(function(a) { + clearInterval(t.data.setInter); + recorderManager.stop(); + recorderManager.onStop(function (a) { t.data.audioDuration < 10 ? wx.showToast({ title: "录音时长需大于10秒", icon: "none" - }) : (a.isPlay = !1, a.durationStr = t.data.audioDuration + "", a.duration = t.data.audioDuration, - a.totalDurationStr = "00:" + (t.data.audioDuration > 9 ? t.data.audioDuration : "0" + t.data.audioDuration), - a.curDurationStr = "00:00", a.curDuration = 0, a.isPlay = !1, t.setData({ - audioFile: a - })), t.setData({ - audioDuration: 0, - isRecording: !1 - }); + }) : (a.isPlay = !1, a.durationStr = t.data.audioDuration + "", a.duration = t.data.audioDuration, + a.totalDurationStr = "00:" + (t.data.audioDuration > 9 ? t.data.audioDuration : "0" + t.data.audioDuration), + a.curDurationStr = "00:00", a.curDuration = 0, a.isPlay = !1, t.setData({ + audioFile: a + })), t.setData({ + audioDuration: 0, + isRecording: !1 + }); }); }, - delAudio: function() { + delAudio: function () { var t = this; wx.showModal({ title: "警告", content: "确定要删除该条录音吗?", - success: function(a) { + success: function (a) { a.confirm && t.setData({ audioFile: null }); } }); }, - closePop: function(t) { + closePop: function (t) { var a = t.currentTarget.dataset.type, i = this; - a && "audio" == a && (null != i.data.audioFile ? (i.data.audioFile.isPlay && e.stop(), - wx.showModal({ - title: "警告", - content: "关闭录音弹窗将清除当前录制的音频文件,确定要关闭吗?", - success: function(t) { - t.confirm && i.setData({ - audioFile: null, - isShowAudio: !1 - }); - } - })) : i.setData({ - isShowAudio: !1 - })), this.setData({ - isShowPhoto: !1, - isShowEdit: !1, - isShowVideo: !1, - isShowSelect: !1, - sourceType: "add" - }); + a && "audio" == a && (null != i.data.audioFile ? (i.data.audioFile.isPlay && e.stop(), + wx.showModal({ + title: "警告", + content: "关闭录音弹窗将清除当前录制的音频文件,确定要关闭吗?", + success: function (t) { + t.confirm && i.setData({ + audioFile: null, + isShowAudio: !1 + }); + } + })) : i.setData({ + isShowAudio: !1 + })), this.setData({ + isShowPhoto: !1, + isShowEdit: !1, + isShowVideo: !1, + isShowSelect: !1, + sourceType: "add" + }); }, - slider4change: function(t) { - var a = t.currentTarget.dataset.item, i = t.currentTarget.dataset.type, s = t.currentTarget.dataset.idx, o = Number.parseInt(t.detail.value); - a.isPlay && (e.pause(), e.seek(o), setTimeout(function() { + slider4change: function (t) { + var a = t.currentTarget.dataset.item; + i = t.currentTarget.dataset.type; + s = t.currentTarget.dataset.idx; + o = Number.parseInt(t.detail.value); + a.isPlay && (e.pause(), e.seek(o), setTimeout(function () { e.play(); - }, 500), "record" == i ? (this.data.audioFile.curDuration = o, this.data.audioFile.curDurationStr = "00:" + (o > 9 ? o : "0" + o), - console.log(this.data.audioFile), this.setData({ - audioFile: this.data.audioFile - })) : (this.data.valueList[s].value.curDuration = o, this.data.valueList[s].value.curDurationStr = "00:" + (o > 9 ? o : "0" + o), - this.setData({ - valueList: this.data.valueList - }))); + }, 500), "record" == i ? (this.data.audioFile.curDuration = o, this.data.audioFile.curDurationStr = "00:" + (o > 9 ? o : "0" + o), + console.log(this.data.audioFile), this.setData({ + audioFile: this.data.audioFile + })) : (this.data.valueList[s].value.curDuration = o, this.data.valueList[s].value.curDurationStr = "00:" + (o > 9 ? o : "0" + o), + this.setData({ + valueList: this.data.valueList + }))); }, - play: function(t) { + play: function (t) { var a = t.currentTarget.dataset.item, i = this, s = t.currentTarget.dataset.type, o = t.currentTarget.dataset.idx; - a.isPlay ? e.stop() : ((e = wx.createInnerAudioContext()).src = a.tempFilePath, - e.autoplay = !0), e.onPlay(function() { - "record" == s ? (i.data.audioFile.isPlay = !0, i.setData({ - audioFile: i.data.audioFile - })) : (i.data.valueList[o].value.isPlay = !0, i.setData({ - valueList: i.data.valueList - })); - }), e.onStop(function(t) { - "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); - }), e.onEnded(function(t) { - "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); - }), e.onError(function(t) { - wx.showToast({ - title: "播放失败", - icon: "error" - }), "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); - }), e.onTimeUpdate(function() { - var t = e.currentTime; - if ("record" == s) { - i.data.audioFile.curDuration = t; - var a = Number.parseInt(i.data.audioFile.curDuration); - i.data.audioFile.curDurationStr = "00:" + (a > 9 ? a : "0" + a), i.setData({ + a.isPlay ? e.stop() : ((e = wx.createInnerAudioContext()).src = a.tempFilePath, + e.autoplay = !0), e.onPlay(function () { + "record" == s ? (i.data.audioFile.isPlay = !0, i.setData({ audioFile: i.data.audioFile - }); - } else { - i.data.valueList[o].value.curDuration = t; - var u = Number.parseInt(i.data.valueList[o].value.curDuration); - i.data.valueList[o].value.curDurationStr = "00:" + (u > 9 ? a : "0" + u), i.setData({ + })) : (i.data.valueList[o].value.isPlay = !0, i.setData({ valueList: i.data.valueList - }); - } - }); + })); + }), e.onStop(function (t) { + "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); + }), e.onEnded(function (t) { + "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); + }), e.onError(function (t) { + wx.showToast({ + title: "播放失败", + icon: "error" + }), "record" == s ? i.setAudioDefault() : i.setShowAudioDefault(o); + }), e.onTimeUpdate(function () { + var t = e.currentTime; + if ("record" == s) { + i.data.audioFile.curDuration = t; + var a = Number.parseInt(i.data.audioFile.curDuration); + i.data.audioFile.curDurationStr = "00:" + (a > 9 ? a : "0" + a), i.setData({ + audioFile: i.data.audioFile + }); + } else { + i.data.valueList[o].value.curDuration = t; + var u = Number.parseInt(i.data.valueList[o].value.curDuration); + i.data.valueList[o].value.curDurationStr = "00:" + (u > 9 ? a : "0" + u), i.setData({ + valueList: i.data.valueList + }); + } + }); }, - setAudioDefault: function() { - null != this.data.audioFile && (this.data.audioFile.curDurationStr = "00:00", this.data.audioFile.curDuration = 0, - this.data.audioFile.isPlay = !1, this.setData({ - audioFile: this.data.audioFile - })); + setAudioDefault: function () { + null != this.data.audioFile && (this.data.audioFile.curDurationStr = "00:00", this.data.audioFile.curDuration = 0, + this.data.audioFile.isPlay = !1, this.setData({ + audioFile: this.data.audioFile + })); }, - setShowAudioDefault: function(t) { - this.data.valueList[t].value.curDurationStr = "00:00", this.data.valueList[t].value.curDuration = 0, - this.data.valueList[t].value.isPlay = !1, this.setData({ - valueList: this.data.valueList - }); + setShowAudioDefault: function (t) { + this.data.valueList[t].value.curDurationStr = "00:00", this.data.valueList[t].value.curDuration = 0, + this.data.valueList[t].value.isPlay = !1, this.setData({ + valueList: this.data.valueList + }); }, - rewind: function(t) { + rewind: function (t) { var a = t.currentTarget.dataset.item, i = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.type; - a.isPlay && ("record" == s ? (this.data.audioFile.curDuration = this.data.audioFile.curDuration - this.data.speedStep, - e.seek(this.data.audioFile.curDuration), this.setData({ - audioFile: this.data.audioFile - })) : (this.data.valueList[i].value.curDuration = this.data.valueList[i].value.curDuration - this.data.speedStep, - e.seek(this.data.valueList[i].value.curDuration), this.setData({ - valueList: this.data.valueList - }))); + a.isPlay && ("record" == s ? (this.data.audioFile.curDuration = this.data.audioFile.curDuration - this.data.speedStep, + e.seek(this.data.audioFile.curDuration), this.setData({ + audioFile: this.data.audioFile + })) : (this.data.valueList[i].value.curDuration = this.data.valueList[i].value.curDuration - this.data.speedStep, + e.seek(this.data.valueList[i].value.curDuration), this.setData({ + valueList: this.data.valueList + }))); }, - speed: function(t) { + speed: function (t) { var a = t.currentTarget.dataset.item, i = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.type; - a.isPlay && ("record" == s ? (this.data.audioFile.curDuration = this.data.audioFile.curDuration + this.data.speedStep, - e.seek(this.data.audioFile.curDuration), this.setData({ - audioFile: this.data.audioFile - })) : (this.data.valueList[i].value.curDuration = this.data.valueList[i].value.curDuration + this.data.speedStep, - e.seek(this.data.valueList[i].value.curDuration), this.setData({ - valueList: this.data.valueList - }))); + a.isPlay && ("record" == s ? (this.data.audioFile.curDuration = this.data.audioFile.curDuration + this.data.speedStep, + e.seek(this.data.audioFile.curDuration), this.setData({ + audioFile: this.data.audioFile + })) : (this.data.valueList[i].value.curDuration = this.data.valueList[i].value.curDuration + this.data.speedStep, + e.seek(this.data.valueList[i].value.curDuration), this.setData({ + valueList: this.data.valueList + }))); }, - onUnload: function() { + onUnload: function () { i.setLocation(null), this.setData({ map: null }); diff --git a/packagecard/moments/publish/momentpublishline.js b/packagecard/moments/publish/momentpublishline.js index 4f40e56..4fe9db9 100755 --- a/packagecard/moments/publish/momentpublishline.js +++ b/packagecard/moments/publish/momentpublishline.js @@ -1,759 +1,759 @@ -var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = wx.getRecorderManager(), i = wx.createInnerAudioContext(), s = requirePlugin("chooseLocation"), n = { - latitude: 39.90877, - longitude: 116.39695 +var a = getApp(); var e = wx.getRecorderManager(); var i = wx.createInnerAudioContext(); var s = requirePlugin("chooseLocation"); var n = { + latitude: 39.90877, + longitude: 116.39695 }; Page({ - data: { - uploadCount: 0, - uploadVideoCount: 0, - currentIndex: 0, - columnId: "", - fieldList: [], - textList: [], - textareaList: [], - audioList: [], - videoList: [], - photoList: [], - linkList: [], - locationList: [], - isShowText: !1, - isShowDesc: !1, - isShowPhoto: !1, - isShowLink: !1, - isShowAudio: !1, - isShowVideo: !1, - isShowTags: !1, - isShowType: !1, - tempText: "", - tempDesc: "", - linkStr: "", - map: null, - waitFlag: !1, - isStartRecord: !1, - speck_time: 0, - speedStep: 5, - setInter: "", - currentItem: void 0, - isAuthAudio: !1, - title: "栏目内容发布", - curMutliIndex: 0, - displayType: [ { - name: "九宫格", - id: 1 - }, { - name: "轮播", - id: 2 - }, { - name: "轮播(自动)", - id: 3 - }, { - name: "平铺", - id: 4 - } ], - selDisplayType: 1, - displayTypeStr: "九宫格", - maxDuration: 60 - }, - onLoad: function(t) { - this.setData({ - columnId: t.id, - title: t.title + "发布" - }), wx.setNavigationBarTitle({ - title: t.title + "发布" - }); - this.checkPermission(), this.getFieldList(); - }, - getFieldList: function() { - wx.showLoading({ - title: "加载中..." - }); - var t = this; - a.http.get(a.urls.getMomentsField.format({ - configColumnId: t.data.columnId - }), { - header: { - token: a.globalData.token - } - }).then(function(a) { - wx.hideLoading({}), a.data.forEach(function(t, a) { - switch (t.order = a, t.dataType) { - case "2": - case "3": - case "4": - case "5": - case "6": - t.valueList = []; - break; + data: { + uploadCount: 0, + uploadVideoCount: 0, + currentIndex: 0, + columnId: "", + fieldList: [], + textList: [], + textareaList: [], + audioList: [], + videoList: [], + photoList: [], + linkList: [], + locationList: [], + isShowText: !1, + isShowDesc: !1, + isShowPhoto: !1, + isShowLink: !1, + isShowAudio: !1, + isShowVideo: !1, + isShowTags: !1, + isShowType: !1, + tempText: "", + tempDesc: "", + linkStr: "", + map: null, + waitFlag: !1, + isStartRecord: !1, + speck_time: 0, + speedStep: 5, + setInter: "", + currentItem: void 0, + isAuthAudio: !1, + title: "栏目内容发布", + curMutliIndex: 0, + displayType: [{ + name: "九宫格", + id: 1 + }, { + name: "轮播", + id: 2 + }, { + name: "轮播(自动)", + id: 3 + }, { + name: "平铺", + id: 4 + }], + selDisplayType: 1, + displayTypeStr: "九宫格", + maxDuration: 60 + }, + onLoad: function (t) { + this.setData({ + columnId: t.id, + title: t.title + "发布" + }), wx.setNavigationBarTitle({ + title: t.title + "发布" + }); + this.checkPermission(), this.getFieldList(); + }, + getFieldList: function () { + wx.showLoading({ + title: "加载中..." + }); + var t = this; + a.http.get(a.urls.getMomentsField.format({ + configColumnId: t.data.columnId + }), { + header: { + token: a.globalData.token + } + }).then(function (a) { + wx.hideLoading({}), a.data.forEach(function (t, a) { + switch (t.order = a, t.dataType) { + case "2": + case "3": + case "4": + case "5": + case "6": + t.valueList = []; + break; - case "8": - t.index = 0, t.value = t.dictionariesList[0].dataId; - break; + case "8": + t.index = 0, t.value = t.dictionariesList[0].dataId; + break; - case "9": - t.selValue = "请选择", t.selIndexs = [], t.dictionariesList.forEach(function(t) { - t.isSel = !1; - }); - } - }), t.setData({ - fieldList: a.data - }); - }).catch(function(t) { - wx.hideLoading({}), console.log(t); - }); - }, - inputText: function(t) { - var a, e = t.currentTarget.dataset.index; - 1 != t.currentTarget.dataset.type ? ((a = this).data.fieldList[e].value = t.detail.value, - a.setData({ - fieldList: a.data.fieldList - })) : ((a = this).data.fieldList[e].order = t.detail.value, a.setData({ - fieldList: a.data.fieldList - })); - }, - checkPermission: function() { - var t = this; - wx.getSetting({ - success: function(a) { - var e = a.authSetting["scope.record"]; - void 0 === e ? wx.authorize({ - scope: "scope.record", - success: function() { - t.setData({ - isAuthAudio: !0 - }); - }, - fail: function() { - t.setData({ - isAuthAudio: !1 - }); - } - }) : e || t.openSetting(); - } - }); - }, - openSetting: function() { - wx.showModal({ - title: "提示", - content: "发布内容需要您授权录音权限.", - success: function(t) { - t.confirm && wx.openSetting({ - withSubscriptions: !0 - }); - } - }); - }, - onShow: function() { - if (null != s.getLocation()) { - var t = this.data.fieldList[this.data.curMapIndex]; - t.valueList.length < t.maxCount && (this.data.fieldList[this.data.curMapIndex].valueList.push(s.getLocation()), - this.setData({ - fieldList: this.data.fieldList - })); - } - var a = this; - wx.getSetting({ - withSubscriptions: !0, - success: function(t) { - var e = t.authSetting["scope.record"]; - a.setData({ - isAuthAudio: e - }); - } - }); - }, - pickerChange: function(t) { - var a = t.currentTarget.dataset.index, e = t.detail.value; - this.data.fieldList[a].index = e, this.data.fieldList[a].value = this.data.fieldList[a].dictionariesList[e].dataId, - this.setData({ - fieldList: this.data.fieldList - }); - }, - confirmSel: function(t) { - var a = t.detail, e = (a.piacker, a.value); - this.setData({ - selDisplayType: e.id, - displayTypeStr: e.name, - isShowType: !1 - }); - }, - cancelSel: function(t) { - this.setData({ - isShowType: !1 - }); - }, - onUnload: function() { - s.setLocation(null), this.setData({ - map: null - }); - }, - chooseVideo: function(t) { - var a = this, e = t.currentTarget.dataset.item, i = e.maxCount - e.valueList.length, s = t.currentTarget.dataset.index; - wx.chooseMedia({ - count: Number.parseInt(i), - mediaType: [ "video" ], - sourceType: [ "camera", "album" ], - maxDuration: 60, - success: function(t) { - console.log(t), t.tempFiles.length > 0 && (t.tempFiles[0].duration <= a.data.maxDuration ? a.doUploadVideo(s, t.tempFiles, a.data.uploadVideoCount) : wx.showToast({ - title: "视频最长60秒", - icon: "none" - })); - }, - fail: function(t) {} - }); - }, - doUploadVideo: function(t, e, i) { - wx.showLoading({ - title: "上传中..." - }); - var s = this, n = e.length; - s.data.uploadVideoCount < n ? a.http.upload(a.urls.doUploadVideo, { - path: e[s.data.uploadVideoCount].tempFilePath, - name: "video", - header: { - token: a.globalData.token - } - }).then(function(a) { - wx.hideLoading({}); - var i = JSON.parse(a).data; - s.doUploadVideoImg(t, i, e, s.data.uploadVideoCount); - }).catch(function(a) { - wx.hideLoading({}), s.setData({ - uploadVideoCount: ++s.data.uploadVideoCount - }), s.doUploadVideo(t, e, s.data.uploadVideoCount); - }) : (wx.hideLoading({}), s.setData({ - uploadVideoCount: 0 - })); - }, - doUploadVideoImg: function(t, e, i, s) { - wx.showLoading({ - title: "上传中..." - }); - var n = this; - a.http.upload(a.urls.doUploadImg, { - path: i[n.data.uploadVideoCount].thumbTempFilePath, - name: "image", - header: { - token: a.globalData.token - } - }).then(function(s) { - console.log(s), wx.hideLoading({}); - var o = a.baseUrls.baseCardUrl + e, d = a.baseUrls.baseCardUrl + JSON.parse(s).data, r = JSON.parse(s).data, l = { - id: e, - thumbId: r, - path: o, - imgPath: d - }; - n.data.fieldList[t].valueList.push(l), n.setData({ - fieldList: n.data.fieldList - }), n.setData({ - uploadVideoCount: ++n.data.uploadVideoCount - }), n.doUploadVideo(t, i, n.data.uploadVideoCount); - }).catch(function(a) { - console.log(a), wx.hideLoading({}), n.setData({ - uploadVideoCount: ++n.data.uploadVideoCount - }), n.doUploadVideo(t, i, n.data.uploadVideoCount); - }); - }, - viewVideo: function(t) { - var a = [ { - url: t.currentTarget.dataset.url, - type: "video" - } ]; - wx.previewMedia({ - sources: a, - current: 0, - showmenu: !1 - }); - }, - delVideo: function(t) { - var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx; - wx.showModal({ - title: "提示", - content: "确定要删除该视频吗?", - cancelText: "取消", - confirmText: "确定", - success: function(t) { - t.confirm && (a.data.fieldList[e].valueList.splice(i, 1), a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - addLink: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("LINK" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.linkList.length < t.count) { - if ("" == this.data.linkStr) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.linkList.push(this.data.linkStr), this.setData({ - linkList: this.data.linkList, - linkStr: "" - }), this.data.linkList.length == t.count && this.setData({ - isShowLink: !1 + case "9": + t.selValue = "请选择", t.selIndexs = [], t.dictionariesList.forEach(function (t) { + t.isSel = !1; }); } - }, - addDesc: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXTAREA" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.textareaList.length < t.count) { - if ("" == this.data.tempDesc) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.textareaList.push(this.data.tempDesc), this.setData({ - textareaList: this.data.textareaList, - tempDesc: "" - }), this.data.textareaList.length == t.count && this.setData({ - isShowDesc: !1 - }); - } - }, - addStr: function() { - for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXT" == this.data.items[a].type) { - t = this.data.items[a]; - break; - } - if (this.data.textList.length < t.count) { - if ("" == this.data.tempText) return void wx.showToast({ - title: "请输入文字内容", - icon: "error" - }); - this.data.textList.push(this.data.tempText), this.setData({ - textList: this.data.textList, - tempText: "" - }), this.data.textList.length == t.count && this.setData({ - isShowText: !1 - }); - } - }, - delText: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.textList.splice(t.currentTarget.dataset.index, 1), a.setData({ - textList: a.data.textList - })); - } - }); - }, - delLink: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.linkList.splice(t.currentTarget.dataset.index, 1), a.setData({ - linkList: a.data.linkList - })); - } - }); - }, - delDesc: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.textareaList.splice(t.currentTarget.dataset.index, 1), a.setData({ - textareaList: a.data.textareaList - })); - } - }); - }, - textInput: function(a) { - this.setData(t({}, a.currentTarget.id, a.detail.value)); - }, - onHide: function(t) { - this.setData({ - isShowText: !1, - isShowDesc: !1, - isShowPhoto: !1, - isShowLink: !1, - isShowAudio: !1, - isShowVideo: !1, - isShowTags: !1, - isShowType: !1 - }); - }, - chooseTags: function(t) { - var a = t.currentTarget.dataset.idx; - this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel = !this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel, - this.setData({ - fieldList: this.data.fieldList - }); - var e = "", i = ""; - this.data.fieldList[this.data.currentIndex].dictionariesList.forEach(function(t) { - t.isSel && (e += t.dataName + ",", i += t.dataId + ","); - }), e = e.substr(0, e.length - 1), i = i.substr(0, i.length - 1), this.data.fieldList[this.data.currentIndex].selValue = e, - this.data.fieldList[this.data.currentIndex].value = i, this.setData({ - fieldList: this.data.fieldList - }); - }, - selTags: function() { - this.setData({ - isShowTags: !1 - }); - }, - choosePhoto: function(t) { - var a = this, e = t.currentTarget.dataset.item, i = t.currentTarget.dataset.index, s = e.maxCount - e.valueList.length; - wx.chooseImage({ - count: Number.parseInt(s), - sourceType: [ "album", "camera" ], - success: function(t) { - console.log(t), a.doUploadImg(i, t.tempFilePaths, a.data.uploadCount); - }, - fail: function(t) {} - }); - }, - delImg: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该图片吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.fieldList[t.currentTarget.dataset.itemindex].valueList.splice(t.currentTarget.dataset.index, 1), - a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - viewImg: function(t) { - var a = [ t.currentTarget.dataset.url ]; - wx.previewImage({ - urls: a, - current: t.currentTarget.dataset.url - }); - }, - doUploadImg: function(t, e, i) { - wx.showLoading({ - title: "上传中..." - }); - var s = this, n = e.length; - s.data.uploadCount < n ? a.http.upload(a.urls.doUploadImg, { - path: e[s.data.uploadCount], - name: "image", - header: { - token: a.globalData.token - } - }).then(function(i) { - wx.hideLoading({}); - var n = JSON.parse(i).data, o = { - id: n, - path: a.baseUrls.baseCardUrl + n - }; - s.data.fieldList[t].valueList.push(o), s.setData({ - fieldList: s.data.fieldList - }), s.setData({ - uploadCount: ++s.data.uploadCount - }), s.doUploadImg(t, e, s.data.uploadCount); - }).catch(function(a) { - wx.hideLoading({}), s.setData({ - uploadCount: ++s.data.uploadCount - }), s.doUploadImg(t, e, s.data.uploadCount); - }) : (wx.hideLoading({}), s.setData({ - uploadCount: 0 - })); - }, - chooseLocation: function(t) { - var a = t.currentTarget.dataset.index; - this.setData({ - curMapIndex: a - }); - var e = JSON.stringify(n); - wx.navigateTo({ - url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(e, "&category=").concat("生活服务,娱乐休闲") - }); - }, - delMap: function(t) { - wx.showModal({ - title: "提示", - content: "确定要删除该条数据吗?", - cancelText: "取消", - confirmText: "确定", - success: function(a) { - a.confirm && (_self.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), - _self.setData({ - fieldList: _self.data.fieldList - })); - } - }); - }, - delAudio: function(t) { - var a = this; - wx.showModal({ - title: "提示", - content: "确定要删除该音频吗?", - cancelText: "取消", - confirmText: "确定", - success: function(e) { - e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), - a.setData({ - fieldList: a.data.fieldList - })); - } - }); - }, - doStartRecord: function() { - var t = this; - wx.getSetting({ - success: function(a) { - a.authSetting["scope.record"] ? t.startRecord() : wx.authorize({ - scope: "scope.record", - success: function() { - t.startRecord(); - } - }); - } - }); - }, - startRecord: function() { - var t = this; - t.data.setInter = setInterval(function() { - var a = parseInt(t.data.speck_time + 1); + }), t.setData({ + fieldList: a.data + }); + }).catch(function (t) { + wx.hideLoading({}), console.log(t); + }); + }, + inputText: function (t) { + var a, e = t.currentTarget.dataset.index; + 1 != t.currentTarget.dataset.type ? ((a = this).data.fieldList[e].value = t.detail.value, + a.setData({ + fieldList: a.data.fieldList + })) : ((a = this).data.fieldList[e].order = t.detail.value, a.setData({ + fieldList: a.data.fieldList + })); + }, + checkPermission: function () { + var t = this; + wx.getSetting({ + success: function (a) { + var e = a.authSetting["scope.record"]; + void 0 === e ? wx.authorize({ + scope: "scope.record", + success: function () { t.setData({ - speck_time: parseInt(a), - isStartRecord: !0 - }), t.data.speck_time > 0 && t.data.speck_time <= 59 ? t.start() : (clearInterval(t.data.setInter), - t.stop(), wx.showToast({ - title: "录音最长60S哦!", - duration: 2e3, - icon: "none" - })); - }, 1e3); - }, - doEndRecord: function() { - clearInterval(this.data.setInter), this.data.speck_time > 10 ? (clearInterval(this.data.setInter), - this.stop(!0), this.setData({ - speck_time: "0", - isStartRecord: !1 - })) : (clearInterval(this.data.setInter), this.stop(!1), wx.showToast({ - title: "时间需大于10秒", - duration: 2e3, - icon: "none" - }), this.setData({ - speck_time: "0", - isStartRecord: !1 - })); - }, - start: function() { - e.start({ - duration: 6e4, - format: "mp3" - }), e.onStart(function() { - console.log("recorder start"); - }), e.onError(function(t) { - console.log(t), _self.stop(!1); - }); - }, - stop: function(t) { - var a = this; - e.stop(), e.onStop(function(e) { - t && a.doUploadAudio(e); - }); - }, - doUploadAudio: function(t) { - wx.showLoading({ - title: "上传中..." - }); - var e = this; - a.http.upload(a.urls.doUploadAudio, { - path: t.tempFilePath, - name: "audio", - header: { - token: a.globalData.token - } - }).then(function(i) { - if (wx.hideLoading({}), e.data.fieldList[e.data.currentIndex].valueList.length < e.data.currentItem.maxCount) { - wx.hideLoading({}); - var s = JSON.parse(i).data, n = a.baseUrls.baseCardUrl + s, o = parseInt(t.duration / 1e3), d = parseInt(o / 60), r = parseInt(o % 60), l = { - id: s, - path: n, - isPlay: !1, - duration: o, - curDuation: 0, - curDurationStr: "00:00", - totalDurationStr: (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r) - }; - e.data.fieldList[e.data.currentIndex].valueList.push(l), e.setData({ - fieldList: e.data.fieldList - }), e.data.fieldList[e.data.currentIndex].valueList.length == e.data.currentItem.maxCount && e.setData({ - isShowAudio: !1 - }); - } - }).catch(function(t) {}); - }, - play: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.item, n = this; - n.data.fieldList[a].valueList.forEach(function(t) { - t.isPlay && i.stop(), t.isPlay = !1, t.curDuation = 0, t.curDuationStr = "00:00"; - }), s.isPlay || ((i = wx.createInnerAudioContext()).src = n.data.fieldList[a].valueList[e].path, - i.autoplay = !0), i.onPlay(function() { - n.data.fieldList[a].valueList[e].isPlay = !0, n.setData({ - fieldList: n.data.fieldList + isAuthAudio: !0 }); - }), i.onCanplay(function(t) { - n.data.waitFlag && (i.play(), n.setData({ - waitFlag: !1 - })); - }), i.onStop(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList + }, + fail: function () { + t.setData({ + isAuthAudio: !1 }); - }), i.onEnded(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList - }); - }), i.onError(function(t) { - n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, - n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ - fieldList: n.data.fieldList - }); - }), i.onSeeking(function() { - console.log(i.currentTime); - }), i.onWaiting(function() { - i.pause(), n.setData({ - waitFlag: !0 - }); - }), i.onTimeUpdate(function() { - if (i.duration != 1 / 0) { - n.data.fieldList[a].valueList[e].curDuration = parseInt(i.currentTime), n.data.fieldList[a].valueList[e].duration = parseInt(i.duration), - console.log(i.duration); - var t = parseInt(i.currentTime / 60), s = parseInt(i.currentTime % 60), o = parseInt(i.duration / 60), d = parseInt(i.duration % 60), r = t > 9 ? t : "0" + t, l = s > 9 ? s : "0" + s, u = o > 9 ? o : "0" + o, c = +d > 9 ? d : "0" + d; - n.data.fieldList[a].valueList[e].curDurationStr = r + ":" + l, n.data.fieldList[a].valueList[e].totalDurationStr = u + ":" + c, - n.setData({ - fieldList: n.data.fieldList - }); - } + } + }) : e || t.openSetting(); + } + }); + }, + openSetting: function () { + wx.showModal({ + title: "提示", + content: "发布内容需要您授权录音权限.", + success: function (t) { + t.confirm && wx.openSetting({ + withSubscriptions: !0 }); - }, - rewind: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; - t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration - this.data.speedStep, - i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ - fieldList: this.data.fieldList - })); - }, - speed: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; - t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration + this.data.speedStep, - i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ - fieldList: this.data.fieldList - })); - }, - slider4change: function(t) { - t.currentTarget.dataset.item.isPlay && i.seek(t.detail.value); - }, - showDialog: function(t) { - console.log(t), this.setData({ - isShowAudio: !0, - currentItem: t.currentTarget.dataset.item, - currentIndex: t.currentTarget.dataset.index - }); - }, - showDisplayType: function(t) { + } + }); + }, + onShow: function () { + if (null != s.getLocation()) { + var t = this.data.fieldList[this.data.curMapIndex]; + t.valueList.length < t.maxCount && (this.data.fieldList[this.data.curMapIndex].valueList.push(s.getLocation()), this.setData({ - isShowType: !0 - }); - }, - chooseDisplayType: function(t) { - var a = t.currentTarget.dataset.id; - this.setData({ - selDisplayType: a - }); - }, - showMutliSel: function(t) { - this.setData({ - isShowTags: !0, - currentIndex: t.currentTarget.dataset.index - }); - }, - doPublish: function() { - if (this.checkParams()) { - wx.showToast({ - title: "保存中..." - }); - var t = this.buildParams(); - console.log(t), a.http.post(a.urls.doSaveMoments.format({ - configColumnId: this.data.columnId - }), { - data: t, - header: { - token: a.globalData.token - } - }).then(function(t) { - wx.hideLoading({}); - var a = getCurrentPages(); - a[a.length - 2].setData({ - isRefresh: !0 - }), wx.navigateBack({ - delta: 1 - }); - }).catch(function(t) { - console.log(t); - }); - } - }, - checkParams: function() { - for (var t = !0, a = 0; a < this.data.fieldList.length; a++) { - var e = this.data.fieldList[a]; - if (e.must) if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) { - if (e.value.length <= 0) { - wx.showToast({ - title: "请输入或选择" + e.comment, - icon: "none" - }), t = !1; - break; - } - } else if (e.valueList.length <= 0) { - wx.showToast({ - title: "请上传" + e.comment, - icon: "none" - }), t = !1; - break; - } - } - return t; - }, - buildParams: function() { - for (var t = {}, a = 0; a < this.data.fieldList.length; a++) { - var e = this.data.fieldList[a]; - if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) e.value.length > 0 && (t[e.name] = e.value); else if (e.valueList.length > 0) { - var i = ""; - "6" == e.dataType ? e.valueList.forEach(function(t) { - i += t.latitude + "," + t.longitude + "-"; - }) : "4" == e.dataType ? e.valueList.forEach(function(t) { - i += t.id + "&" + t.thumbId + ","; - }) : "3" == e.dataType ? e.valueList.forEach(function(t) { - i += t.id + "&" + t.duration + ","; - }) : "2" == e.dataType ? (e.valueList.forEach(function(t) { - i += t.id + ","; - }), i = i.substr(0, i.length - 1), i += "@" + this.data.selDisplayType) : e.valueList.forEach(function(t) { - i += t.id + ","; - }), "2" != e.dataType && (i = i.substr(0, i.length - 1)), t[e.name] = i; - } - } - return t; + fieldList: this.data.fieldList + })); } + var a = this; + wx.getSetting({ + withSubscriptions: !0, + success: function (t) { + var e = t.authSetting["scope.record"]; + a.setData({ + isAuthAudio: e + }); + } + }); + }, + pickerChange: function (t) { + var a = t.currentTarget.dataset.index, e = t.detail.value; + this.data.fieldList[a].index = e, this.data.fieldList[a].value = this.data.fieldList[a].dictionariesList[e].dataId, + this.setData({ + fieldList: this.data.fieldList + }); + }, + confirmSel: function (t) { + var a = t.detail, e = (a.piacker, a.value); + this.setData({ + selDisplayType: e.id, + displayTypeStr: e.name, + isShowType: !1 + }); + }, + cancelSel: function (t) { + this.setData({ + isShowType: !1 + }); + }, + onUnload: function () { + s.setLocation(null), this.setData({ + map: null + }); + }, + chooseVideo: function (t) { + var a = this, e = t.currentTarget.dataset.item, i = e.maxCount - e.valueList.length, s = t.currentTarget.dataset.index; + wx.chooseMedia({ + count: Number.parseInt(i), + mediaType: ["video"], + sourceType: ["camera", "album"], + maxDuration: 60, + success: function (t) { + console.log(t), t.tempFiles.length > 0 && (t.tempFiles[0].duration <= a.data.maxDuration ? a.doUploadVideo(s, t.tempFiles, a.data.uploadVideoCount) : wx.showToast({ + title: "视频最长60秒", + icon: "none" + })); + }, + fail: function (t) { } + }); + }, + doUploadVideo: function (t, e, i) { + wx.showLoading({ + title: "上传中..." + }); + var s = this, n = e.length; + s.data.uploadVideoCount < n ? a.http.upload(a.urls.doUploadVideo, { + path: e[s.data.uploadVideoCount].tempFilePath, + name: "video", + header: { + token: a.globalData.token + } + }).then(function (a) { + wx.hideLoading({}); + var i = JSON.parse(a).data; + s.doUploadVideoImg(t, i, e, s.data.uploadVideoCount); + }).catch(function (a) { + wx.hideLoading({}), s.setData({ + uploadVideoCount: ++s.data.uploadVideoCount + }), s.doUploadVideo(t, e, s.data.uploadVideoCount); + }) : (wx.hideLoading({}), s.setData({ + uploadVideoCount: 0 + })); + }, + doUploadVideoImg: function (t, e, i, s) { + wx.showLoading({ + title: "上传中..." + }); + var n = this; + a.http.upload(a.urls.doUploadImg, { + path: i[n.data.uploadVideoCount].thumbTempFilePath, + name: "image", + header: { + token: a.globalData.token + } + }).then(function (s) { + console.log(s), wx.hideLoading({}); + var o = a.baseUrls.baseCardUrl + e, d = a.baseUrls.baseCardUrl + JSON.parse(s).data, r = JSON.parse(s).data, l = { + id: e, + thumbId: r, + path: o, + imgPath: d + }; + n.data.fieldList[t].valueList.push(l), n.setData({ + fieldList: n.data.fieldList + }), n.setData({ + uploadVideoCount: ++n.data.uploadVideoCount + }), n.doUploadVideo(t, i, n.data.uploadVideoCount); + }).catch(function (a) { + console.log(a), wx.hideLoading({}), n.setData({ + uploadVideoCount: ++n.data.uploadVideoCount + }), n.doUploadVideo(t, i, n.data.uploadVideoCount); + }); + }, + viewVideo: function (t) { + var a = [{ + url: t.currentTarget.dataset.url, + type: "video" + }]; + wx.previewMedia({ + sources: a, + current: 0, + showmenu: !1 + }); + }, + delVideo: function (t) { + var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx; + wx.showModal({ + title: "提示", + content: "确定要删除该视频吗?", + cancelText: "取消", + confirmText: "确定", + success: function (t) { + t.confirm && (a.data.fieldList[e].valueList.splice(i, 1), a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + addLink: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("LINK" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.linkList.length < t.count) { + if ("" == this.data.linkStr) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.linkList.push(this.data.linkStr), this.setData({ + linkList: this.data.linkList, + linkStr: "" + }), this.data.linkList.length == t.count && this.setData({ + isShowLink: !1 + }); + } + }, + addDesc: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXTAREA" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.textareaList.length < t.count) { + if ("" == this.data.tempDesc) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.textareaList.push(this.data.tempDesc), this.setData({ + textareaList: this.data.textareaList, + tempDesc: "" + }), this.data.textareaList.length == t.count && this.setData({ + isShowDesc: !1 + }); + } + }, + addStr: function () { + for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXT" == this.data.items[a].type) { + t = this.data.items[a]; + break; + } + if (this.data.textList.length < t.count) { + if ("" == this.data.tempText) return void wx.showToast({ + title: "请输入文字内容", + icon: "error" + }); + this.data.textList.push(this.data.tempText), this.setData({ + textList: this.data.textList, + tempText: "" + }), this.data.textList.length == t.count && this.setData({ + isShowText: !1 + }); + } + }, + delText: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.textList.splice(t.currentTarget.dataset.index, 1), a.setData({ + textList: a.data.textList + })); + } + }); + }, + delLink: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.linkList.splice(t.currentTarget.dataset.index, 1), a.setData({ + linkList: a.data.linkList + })); + } + }); + }, + delDesc: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.textareaList.splice(t.currentTarget.dataset.index, 1), a.setData({ + textareaList: a.data.textareaList + })); + } + }); + }, + textInput: function (a) { + this.setData(t({}, a.currentTarget.id, a.detail.value)); + }, + onHide: function (t) { + this.setData({ + isShowText: !1, + isShowDesc: !1, + isShowPhoto: !1, + isShowLink: !1, + isShowAudio: !1, + isShowVideo: !1, + isShowTags: !1, + isShowType: !1 + }); + }, + chooseTags: function (t) { + var a = t.currentTarget.dataset.idx; + this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel = !this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel, + this.setData({ + fieldList: this.data.fieldList + }); + var e = "", i = ""; + this.data.fieldList[this.data.currentIndex].dictionariesList.forEach(function (t) { + t.isSel && (e += t.dataName + ",", i += t.dataId + ","); + }), e = e.substr(0, e.length - 1), i = i.substr(0, i.length - 1), this.data.fieldList[this.data.currentIndex].selValue = e, + this.data.fieldList[this.data.currentIndex].value = i, this.setData({ + fieldList: this.data.fieldList + }); + }, + selTags: function () { + this.setData({ + isShowTags: !1 + }); + }, + choosePhoto: function (t) { + var a = this, e = t.currentTarget.dataset.item, i = t.currentTarget.dataset.index, s = e.maxCount - e.valueList.length; + wx.chooseImage({ + count: Number.parseInt(s), + sourceType: ["album", "camera"], + success: function (t) { + console.log(t), a.doUploadImg(i, t.tempFilePaths, a.data.uploadCount); + }, + fail: function (t) { } + }); + }, + delImg: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该图片吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.fieldList[t.currentTarget.dataset.itemindex].valueList.splice(t.currentTarget.dataset.index, 1), + a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + viewImg: function (t) { + var a = [t.currentTarget.dataset.url]; + wx.previewImage({ + urls: a, + current: t.currentTarget.dataset.url + }); + }, + doUploadImg: function (t, e, i) { + wx.showLoading({ + title: "上传中..." + }); + var s = this, n = e.length; + s.data.uploadCount < n ? a.http.upload(a.urls.doUploadImg, { + path: e[s.data.uploadCount], + name: "image", + header: { + token: a.globalData.token + } + }).then(function (i) { + wx.hideLoading({}); + var n = JSON.parse(i).data, o = { + id: n, + path: a.baseUrls.baseCardUrl + n + }; + s.data.fieldList[t].valueList.push(o), s.setData({ + fieldList: s.data.fieldList + }), s.setData({ + uploadCount: ++s.data.uploadCount + }), s.doUploadImg(t, e, s.data.uploadCount); + }).catch(function (a) { + wx.hideLoading({}), s.setData({ + uploadCount: ++s.data.uploadCount + }), s.doUploadImg(t, e, s.data.uploadCount); + }) : (wx.hideLoading({}), s.setData({ + uploadCount: 0 + })); + }, + chooseLocation: function (t) { + var a = t.currentTarget.dataset.index; + this.setData({ + curMapIndex: a + }); + var e = JSON.stringify(n); + wx.navigateTo({ + url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(e, "&category=").concat("生活服务,娱乐休闲") + }); + }, + delMap: function (t) { + wx.showModal({ + title: "提示", + content: "确定要删除该条数据吗?", + cancelText: "取消", + confirmText: "确定", + success: function (a) { + a.confirm && (_self.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), + _self.setData({ + fieldList: _self.data.fieldList + })); + } + }); + }, + delAudio: function (t) { + var a = this; + wx.showModal({ + title: "提示", + content: "确定要删除该音频吗?", + cancelText: "取消", + confirmText: "确定", + success: function (e) { + e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), + a.setData({ + fieldList: a.data.fieldList + })); + } + }); + }, + doStartRecord: function () { + var t = this; + wx.getSetting({ + success: function (a) { + a.authSetting["scope.record"] ? t.startRecord() : wx.authorize({ + scope: "scope.record", + success: function () { + t.startRecord(); + } + }); + } + }); + }, + startRecord: function () { + var t = this; + t.data.setInter = setInterval(function () { + var a = parseInt(t.data.speck_time + 1); + t.setData({ + speck_time: parseInt(a), + isStartRecord: !0 + }), t.data.speck_time > 0 && t.data.speck_time <= 59 ? t.start() : (clearInterval(t.data.setInter), + t.stop(), wx.showToast({ + title: "录音最长60S哦!", + duration: 2e3, + icon: "none" + })); + }, 1e3); + }, + doEndRecord: function () { + clearInterval(this.data.setInter), this.data.speck_time > 10 ? (clearInterval(this.data.setInter), + this.stop(!0), this.setData({ + speck_time: "0", + isStartRecord: !1 + })) : (clearInterval(this.data.setInter), this.stop(!1), wx.showToast({ + title: "时间需大于10秒", + duration: 2e3, + icon: "none" + }), this.setData({ + speck_time: "0", + isStartRecord: !1 + })); + }, + start: function () { + e.start({ + duration: 6e4, + format: "mp3" + }), e.onStart(function () { + console.log("recorder start"); + }), e.onError(function (t) { + console.log(t), _self.stop(!1); + }); + }, + stop: function (t) { + var a = this; + e.stop(), e.onStop(function (e) { + t && a.doUploadAudio(e); + }); + }, + doUploadAudio: function (t) { + wx.showLoading({ + title: "上传中..." + }); + var e = this; + a.http.upload(a.urls.doUploadAudio, { + path: t.tempFilePath, + name: "audio", + header: { + token: a.globalData.token + } + }).then(function (i) { + if (wx.hideLoading({}), e.data.fieldList[e.data.currentIndex].valueList.length < e.data.currentItem.maxCount) { + wx.hideLoading({}); + var s = JSON.parse(i).data, n = a.baseUrls.baseCardUrl + s, o = parseInt(t.duration / 1e3), d = parseInt(o / 60), r = parseInt(o % 60), l = { + id: s, + path: n, + isPlay: !1, + duration: o, + curDuation: 0, + curDurationStr: "00:00", + totalDurationStr: (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r) + }; + e.data.fieldList[e.data.currentIndex].valueList.push(l), e.setData({ + fieldList: e.data.fieldList + }), e.data.fieldList[e.data.currentIndex].valueList.length == e.data.currentItem.maxCount && e.setData({ + isShowAudio: !1 + }); + } + }).catch(function (t) { }); + }, + play: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.item, n = this; + n.data.fieldList[a].valueList.forEach(function (t) { + t.isPlay && i.stop(), t.isPlay = !1, t.curDuation = 0, t.curDuationStr = "00:00"; + }), s.isPlay || ((i = wx.createInnerAudioContext()).src = n.data.fieldList[a].valueList[e].path, + i.autoplay = !0), i.onPlay(function () { + n.data.fieldList[a].valueList[e].isPlay = !0, n.setData({ + fieldList: n.data.fieldList + }); + }), i.onCanplay(function (t) { + n.data.waitFlag && (i.play(), n.setData({ + waitFlag: !1 + })); + }), i.onStop(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onEnded(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onError(function (t) { + n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, + n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ + fieldList: n.data.fieldList + }); + }), i.onSeeking(function () { + console.log(i.currentTime); + }), i.onWaiting(function () { + i.pause(), n.setData({ + waitFlag: !0 + }); + }), i.onTimeUpdate(function () { + if (i.duration != 1 / 0) { + n.data.fieldList[a].valueList[e].curDuration = parseInt(i.currentTime), n.data.fieldList[a].valueList[e].duration = parseInt(i.duration), + console.log(i.duration); + var t = parseInt(i.currentTime / 60), s = parseInt(i.currentTime % 60), o = parseInt(i.duration / 60), d = parseInt(i.duration % 60), r = t > 9 ? t : "0" + t, l = s > 9 ? s : "0" + s, u = o > 9 ? o : "0" + o, c = +d > 9 ? d : "0" + d; + n.data.fieldList[a].valueList[e].curDurationStr = r + ":" + l, n.data.fieldList[a].valueList[e].totalDurationStr = u + ":" + c, + n.setData({ + fieldList: n.data.fieldList + }); + } + }); + }, + rewind: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; + t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration - this.data.speedStep, + i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ + fieldList: this.data.fieldList + })); + }, + speed: function (t) { + var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; + t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration + this.data.speedStep, + i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ + fieldList: this.data.fieldList + })); + }, + slider4change: function (t) { + t.currentTarget.dataset.item.isPlay && i.seek(t.detail.value); + }, + showDialog: function (t) { + console.log(t), this.setData({ + isShowAudio: !0, + currentItem: t.currentTarget.dataset.item, + currentIndex: t.currentTarget.dataset.index + }); + }, + showDisplayType: function (t) { + this.setData({ + isShowType: !0 + }); + }, + chooseDisplayType: function (t) { + var a = t.currentTarget.dataset.id; + this.setData({ + selDisplayType: a + }); + }, + showMutliSel: function (t) { + this.setData({ + isShowTags: !0, + currentIndex: t.currentTarget.dataset.index + }); + }, + doPublish: function () { + if (this.checkParams()) { + wx.showToast({ + title: "保存中..." + }); + var t = this.buildParams(); + console.log(t), a.http.post(a.urls.doSaveMoments.format({ + configColumnId: this.data.columnId + }), { + data: t, + header: { + token: a.globalData.token + } + }).then(function (t) { + wx.hideLoading({}); + var a = getCurrentPages(); + a[a.length - 2].setData({ + isRefresh: !0 + }), wx.navigateBack({ + delta: 1 + }); + }).catch(function (t) { + console.log(t); + }); + } + }, + checkParams: function () { + for (var t = !0, a = 0; a < this.data.fieldList.length; a++) { + var e = this.data.fieldList[a]; + if (e.must) if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) { + if (e.value.length <= 0) { + wx.showToast({ + title: "请输入或选择" + e.comment, + icon: "none" + }), t = !1; + break; + } + } else if (e.valueList.length <= 0) { + wx.showToast({ + title: "请上传" + e.comment, + icon: "none" + }), t = !1; + break; + } + } + return t; + }, + buildParams: function () { + for (var t = {}, a = 0; a < this.data.fieldList.length; a++) { + var e = this.data.fieldList[a]; + if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) e.value.length > 0 && (t[e.name] = e.value); else if (e.valueList.length > 0) { + var i = ""; + "6" == e.dataType ? e.valueList.forEach(function (t) { + i += t.latitude + "," + t.longitude + "-"; + }) : "4" == e.dataType ? e.valueList.forEach(function (t) { + i += t.id + "&" + t.thumbId + ","; + }) : "3" == e.dataType ? e.valueList.forEach(function (t) { + i += t.id + "&" + t.duration + ","; + }) : "2" == e.dataType ? (e.valueList.forEach(function (t) { + i += t.id + ","; + }), i = i.substr(0, i.length - 1), i += "@" + this.data.selDisplayType) : e.valueList.forEach(function (t) { + i += t.id + ","; + }), "2" != e.dataType && (i = i.substr(0, i.length - 1)), t[e.name] = i; + } + } + return t; + } }); \ No newline at end of file diff --git a/packagecard/sharePage/sharePage.js b/packagecard/sharePage/sharePage.js index 675688a..35e3de5 100755 --- a/packagecard/sharePage/sharePage.js +++ b/packagecard/sharePage/sharePage.js @@ -1,442 +1,684 @@ -var t, a = require("../../@babel/runtime/helpers/defineProperty"), e = getApp(), r = wx.createInnerAudioContext(); - +// pages/sharePage/sharePage.js +const app = getApp() +var innerAudioContext = wx.createInnerAudioContext() Page({ - data: (t = { - active: 0, - curIndex: 0, - token: "", - cardTemplateUseId: "", - cardTemplateDispatchId: "", - cardInfo: {}, - areaList: [], - haveCard: !1, - bgImg: "" - }, a(t, "areaList", []), a(t, "cardHeight", ""), a(t, "cardInfo", {}), a(t, "cardUrl", e.baseUrls.baseCardUrl), - a(t, "personIntro", {}), a(t, "companyIntro", {}), a(t, "shareImg", ""), a(t, "phoneTxt", ""), - a(t, "emailTxt", ""), a(t, "wechateTxt", ""), a(t, "addressTxt", ""), a(t, "viewInfo", {}), - a(t, "forwardCount", ""), a(t, "imgUrl", e.baseUrls.baseCardUrl), a(t, "personId", ""), - a(t, "shareRecordId", ""), a(t, "nameTxt", "名片"), a(t, "dataList", []), a(t, "isShowBarCode", !1), - a(t, "browUserList", []), a(t, "tempUserId", ""), a(t, "shareImgUrl", ""), t), - doLogin: function() { - var t = this; + + /** + * 页面的初始数据 + */ + data: { + active: 0, + curIndex: 0, + token: '', + cardTemplateUseId: '', + cardTemplateDispatchId: '', + cardInfo: {}, + areaList: [], + haveCard: false, + bgImg: '', + areaList: [], + cardHeight: '', + cardInfo: {}, + cardUrl: app.urls.baseImgUrl, + personIntro: {}, + companyIntro: {}, + shareImg: '', + phoneTxt: '', + emailTxt: '', + wechateTxt: '', + addressTxt: '', + viewInfo: {}, + forwardCount: '', + imgUrl: app.urls.baseImgUrl, + personId: '', + shareRecordId: '', + nameTxt: '名片', + dataList: [], + isShowBarCode: false, + browUserList: [], + tempUserId: '', + shareImgUrl: '' + }, + // 登录 + doLogin() { + var self = this; + wx.showLoading({ + title: '加载中...', + }) + wx.login({ + success(res) { + app.http.post(app.urls.wxLogin, { + data: { + jsCode: res.code + } + }) + .then(res => { + wx.hideLoading({}) + var token = res.data.data.split('_')[0] + wx.setStorageSync('token', token) + wx.setStorageSync('bindPhone', res.data.data.split('_')[1]) + self.setData({ + token: token + }) + app.globalData.token = token + self.getCardId() + }) + .catch(err => { + wx.hideLoading({}) + console.log(err) + }) + } + }) + }, + // 保存查看记录 + saveCheckRecord: function () { + var self = this + console.log('1123') + app.http.post(app.urls.checkRecord, { + header: { + token: app.globalData.token + }, + data: { + cardTemplateUseId: self.data.cardTemplateUseId, + cardTemplateDispatchId: self.data.cardTemplateDispatchId + } + }).then(res => { + console.log(res) + }).catch(res => { + console.log(res) + }) + }, + // 获取名片 + getCard: function () { + var self = this + app.http.get(app.urls.shareCard.format({ + cardTemplateUseId: self.data.cardTemplateUseId + }), { + header: { + token: self.data.token + }, + data: {} + }).then(res => { + console.log(res.data) + var area = res.data.areaList + for (let i = 0; i < area.length; i++) { + if (area[i].templateAreaFontCenter == '1') { + area[i].templateAreaFontCenter = 'left' + } else if (area[i].templateAreaFontCenter == '2') { + area[i].templateAreaFontCenter = 'center' + } else { + area[i].templateAreaFontCenter = 'right' + } + if (area[i].templateAreaFontBold == '0') { + area[i].templateAreaFontBold = 'normal' + } else if (area[i].templateAreaFontBold == '1') { + area[i].templateAreaFontBold = 'bold' + } else { + area[i]['templateAreaFontStyle'] = 'italic' + } + if (area[i].templateAreaSource == 'phone') { + self.setData({ + phoneTxt: area[i].templateAreaFontValue + }) + } else if (area[i].templateAreaSource == 'wechat') { + self.setData({ + wechatTxt: area[i].templateAreaFontValue + }) + } else if (area[i].templateAreaSource == 'email') { + self.setData({ + emailTxt: area[i].templateAreaFontValue + }) + } else if (area[i].templateAreaSource == 'address') { + self.setData({ + addressTxt: area[i].templateAreaFontValue + }) + } else if (area[i].templateAreaSource == 'name') { + self.setData({ + nameTxt: area[i].templateAreaFontValue + }) + } + } + self.setData({ + cardInfo: res.data, + areaList: area, + dataList: [] + }) + if (res.data) { + self.toSaveLocalImg(res.data.cardTemplateUseDispatchPhoto) + self.getBrowCardUserList(res.data.cardTemplateUseId) + self.setData({ + tempUserId: res.data.creator + }) + self.getMainColumn(res.data.creator) + } + }) + }, + //获取首页展示的栏目 + getMainColumn(id) { + var _self = this + app.http.get(app.urls.getMainColumn, { + header: { + token: app.globalData.token + }, + data: { + cardTemplateUseId: id + } + }) + .then(res => { wx.showLoading({ - title: "加载中..." - }), wx.login({ - success: function(a) { - e.http.post(e.urls.wxLogin, { - data: { - jsCode: a.code - } - }).then(function(a) { - wx.hideLoading({}); - var r = a.data.data.split("_")[0]; - wx.setStorageSync("token", r), wx.setStorageSync("bindPhone", a.data.data.split("_")[1]), - t.setData({ - token: r - }), e.globalData.token = r, t.getCardId(); - }).catch(function(t) { - wx.hideLoading({}), console.log(t); - }); - } - }); - }, - saveCheckRecord: function() { - console.log("1123"), e.http.post(e.urls.checkRecord, { - header: { - token: e.globalData.token - }, - data: { - cardTemplateUseId: this.data.cardTemplateUseId, - cardTemplateDispatchId: this.data.cardTemplateDispatchId - } - }).then(function(t) { - console.log(t); - }).catch(function(t) { - console.log(t); - }); - }, - getCard: function() { - var t = this; - e.http.get(e.urls.shareCard.format({ - cardTemplateUseId: t.data.cardTemplateUseId + title: '加载中...', + }) + console.log(res.data) + _self.getMainMoment(res.data, id, 0) + }) + .catch(err => {}) + }, + getMainMoment(datas, id, index) { + var _self = this + var count = datas.length + if (index < count) { + app.http.get(app.urls.getMainMoment.format({ + configColumnId: datas[_self.data.curIndex].configColumnId }), { - header: { - token: e.globalData.token - }, - data: {} - }).then(function(a) { - console.log(a.data); - for (var e = a.data.areaList, r = 0; r < e.length; r++) "1" == e[r].templateAreaFontCenter ? e[r].templateAreaFontCenter = "left" : "2" == e[r].templateAreaFontCenter ? e[r].templateAreaFontCenter = "center" : e[r].templateAreaFontCenter = "right", - "0" == e[r].templateAreaFontBold ? e[r].templateAreaFontBold = "normal" : "1" == e[r].templateAreaFontBold ? e[r].templateAreaFontBold = "bold" : e[r].templateAreaFontStyle = "italic", - "phone" == e[r].templateAreaSource ? t.setData({ - phoneTxt: e[r].templateAreaFontValue - }) : "wechat" == e[r].templateAreaSource ? t.setData({ - wechatTxt: e[r].templateAreaFontValue - }) : "email" == e[r].templateAreaSource ? t.setData({ - emailTxt: e[r].templateAreaFontValue - }) : "address" == e[r].templateAreaSource ? t.setData({ - addressTxt: e[r].templateAreaFontValue - }) : "name" == e[r].templateAreaSource && t.setData({ - nameTxt: e[r].templateAreaFontValue - }); - t.setData({ - cardInfo: a.data, - areaList: e, - dataList: [] - }), a.data && (t.toSaveLocalImg(a.data.cardTemplateUseDispatchPhoto), t.getBrowCardUserList(a.data.cardTemplateUseId), - t.setData({ - tempUserId: a.data.creator - }), t.getMainColumn(a.data.creator)); - }); - }, - getMainColumn: function(t) { - var a = this; - e.http.get(e.urls.getMainColumn, { - header: { - token: e.globalData.token - }, - data: { - cardTemplateUseId: t + header: { + token: app.globalData.token + }, + data: { + userId: id + } + }) + .then(res => { + if (res.data.length > 0) { + var tempItem = { + cId: datas[_self.data.curIndex].configColumnId, + type: datas[_self.data.curIndex].configColumnType, + name: datas[_self.data.curIndex].configColumnName, + mode: datas[_self.data.curIndex].configTableMode, + list: res.data.slice(0, datas[_self.data.curIndex].configColumnRowCount) } - }).then(function(e) { - wx.showLoading({ - title: "加载中..." - }), console.log(e.data), a.getMainMoment(e.data, t, 0); - }).catch(function(t) {}); - }, - getMainMoment: function(t, a, r) { - var s = this; - r < t.length ? e.http.get(e.urls.getMainMoment.format({ - configColumnId: t[s.data.curIndex].configColumnId - }), { - header: { - token: e.globalData.token - }, - data: { - userId: a - } - }).then(function(e) { - if (e.data.length > 0) { - var r = { - cId: t[s.data.curIndex].configColumnId, - type: t[s.data.curIndex].configColumnType, - name: t[s.data.curIndex].configColumnName, - mode: t[s.data.curIndex].configTableMode, - list: e.data.slice(0, t[s.data.curIndex].configColumnRowCount) - }; - s.data.dataList.push(r); - } - s.setData({ - curIndex: ++s.data.curIndex - }), s.getMainMoment(t, a, s.data.curIndex); - }).catch(function(e) { - s.setData({ - curIndex: ++s.data.curIndex - }), s.getMainMoment(t, a, s.data.curIndex); - }) : (wx.hideLoading({}), wx.stopPullDownRefresh({}), s.buildMainData()); - }, - buildMainData: function() { - this.data.dataList.forEach(function(t) { - t.list.forEach(function(t) { - t.list.forEach(function(t) { - switch (t.dataType) { - case "2": - var a = t.value.split(","), r = []; - a.forEach(function(t) { - var a = { - id: t, - path: e.baseUrls.baseCardUrl + t - }; - r.push(a); - }), t.valueList = r; - break; - - case "3": - a = t.value.split(","), r = []; - a.forEach(function(t) { - var a = { - id: t, - path: e.baseUrls.baseCardUrl + t, - isPlay: !1, - duration: 1e5, - curDuration: 0, - curDurationStr: "00:00", - totalDurationStr: "00:00" - }; - r.push(a); - }), t.valueList = r; - break; - - case "4": - a = t.value.split(","), r = []; - for (var s = 0; s < a.length; s++) { - var i = a[s].split("&"), n = { - path: e.baseUrls.baseCardUrl + i[0], - imgPath: e.baseUrls.baseCardUrl + i[1] - }; - r.push(n); - } - t.valueList = r; - break; - - case "6": - a = t.value.split("-"), r = []; - a.forEach(function(t) { - var a = t.split(","), e = { - name: "", - address: "", - latitude: a[0], - longitude: a[1] - }; - r.push(e); - }), t.valueList = r; - break; - - case "8": - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) && (t.selValue = a.dataName); - }); - break; - - case "9": - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) ? a.isSel = !0 : a.isSel = !1; - }); - } - }); - }); - }), this.setData({ - curIndex: 0, - dataList: this.data.dataList - }); - }, - includedCard: function() { - e.http.post(e.urls.includedCard, { - header: { - token: e.globalData.token - }, - data: { - cardTemplateUseBagId: "", - cardTemplateUseId: this.data.cardInfo.cardTemplateUseId, - cardTemplateUseStar: "", - cardTemplateUseTag: "", - cardTemplateUseTop: "" - } - }).then(function(t) { - "200" == t.statusCode && wx.showToast({ - title: "加入卡包成功!" - }); - }); - }, - getCardId: function() { - var t = this; - e.http.get(e.urls.getCardUseId.format({ - cardTemplateDispatchId: t.data.cardTemplateDispatchId - }), { - header: { - token: e.globalData.token - } - }).then(function(a) { - t.setData({ - cardTemplateUseId: a.data.cardTemplateUseDTO.cardTemplateUseId - }), t.getCard(), t.saveCheckRecord(); - }); - }, - onLoad: function(t) { - this.setData({ - cardTemplateDispatchId: t.cardTemplateDispatchId - }), this.doLogin(); - }, - makeCall: function() { - var t = this.data.phoneTxt; - t && wx.makePhoneCall({ - phoneNumber: t - }); - }, - copyText: function(t) { - var a = t.currentTarget.dataset.text; - a && wx.setClipboardData({ - data: a, - success: function() {} - }); - }, - showBarCode: function() { - this.setData({ - isShowBarCode: !0 - }); - }, - hideBarCode: function() { - this.setData({ - isShowBarCode: !1 - }); - }, - onShareAppMessage: function(t) { - if (wx.showShareMenu({ - withShareTicket: !0, - success: function(t) { - console.log(t); - } - }), "button" == t.from) { - var a = this.buildId(); - return this.shareRecord(a), { - title: "名片分享", - path: "/pages/sharePage/sharePage?cardTemplateDispatchId=" + a, - imageUrl: this.data.shareImgUrl - }; - } - }, - getBrowCardUserList: function(t) { - var a = this; - e.http.get(e.urls.getCardBrowUserList, { - header: { - token: e.globalData.token - }, - data: { - page: "1", - rows: "7", - cardTemplateUseId: t - } - }).then(function(t) { - t.data && a.setData({ - browUserList: t.data.rows - }); - }).catch(function(t) { - console.log(t); - }); - }, - shareRecord: function(t) { - var a = this; - e.http.post(e.urls.shareRecord, { - header: { - token: e.globalData.token - }, - data: { - cardTemplateUseId: a.data.cardInfo.cardTemplateUseId, - cardTemplateDispatchParentId: a.data.cardTemplateDispatchId, - cardTemplateDispatchId: t - } - }).then(function(t) { - console.log(t.data), a.setData({ - shareRecordId: t.data.data - }); - }); - }, - buildId: function() { - for (var t = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ], a = "", e = 0; e < 36; e++) { - a += t[parseInt(61 * Math.random())]; - } - return a; - }, - viewImg: function(t) { - wx.previewImage({ - urls: [ t.currentTarget.dataset.url ] - }); - }, - viewVideo: function(t) { - var a = t.currentTarget.dataset.url; - wx.previewMedia({ - sources: [ { - url: a, - type: "video" - } ] - }); - }, - play: function(t) { - var a = this, e = t.currentTarget.dataset.index, s = t.currentTarget.dataset.idx, i = t.currentTarget.dataset.i, n = t.currentTarget.dataset.a, d = t.currentTarget.dataset.item; - a.data.dataList.forEach(function(t) { - t.list.forEach(function(t) { - t.list.forEach(function(t) { - "3" == t.dataType && t.valueList && t.valueList.forEach(function(t) { - t.isPlay && r.stop(), t.isPlay = !1, t.curDuration = 0, t.curDuationStr = "00:00"; - }); - }); - }); - }), d.isPlay ? r.stop() : ((r = wx.createInnerAudioContext()).src = a.data.dataList[e].list[s].list[i].valueList[n].path + ".mp3", - r.autoplay = !0, console.log(a.data.dataList[e].list[s].list[i].valueList[n].path)), - r.onPlay(function() { - console.log("onPlay"), a.data.dataList[e].list[s].list[i].valueList[n].isPlay = !0, - a.setData({ - dataList: a.data.dataList - }); - }), r.onCanplay(function(t) {}), r.onStop(function(t) { - console.log("停止播放"), a.data.dataList[e].list[s].list[i].valueList[n].isPlay = !1, - a.data.dataList[e].list[s].list[i].valueList[n].curDuration = 0, a.data.dataList[e].list[s].list[i].valueList[n].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList - }), r.destroy(); - }), r.onEnded(function(t) { - console.log(t), console.log("播放完毕"), a.data.dataList[e].list[s].list[i].valueList[n].isPlay = !1, - a.data.dataList[e].list[s].list[i].valueList[n].curDuration = 0, a.data.dataList[e].list[s].list[i].valueList[n].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList - }), r.destroy(); - }), r.onError(function(t) { - console.log("播放错误"), console.log(t), a.data.dataList[e].list[s].list[i].valueList[n].isPlay = !1, - a.data.dataList[e].list[s].list[i].valueList[n].curDuration = 0, a.data.dataList[e].list[s].list[i].valueList[n].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList - }), r.destroy(); - }), r.onSeeking(function() {}), r.onWaiting(function() {}), r.onTimeUpdate(function() { - if (r.duration != 1 / 0) { - a.data.dataList[e].list[s].list[i].valueList[n].curDuration = parseInt(r.currentTime), - a.data.dataList[e].list[s].list[i].valueList[n].duration = parseInt(r.duration); - var t = parseInt(r.currentTime / 60), d = parseInt(r.currentTime % 60), o = parseInt(r.duration / 60), l = parseInt(r.duration % 60), c = t > 9 ? t : "0" + t, u = d > 9 ? d : "0" + d, h = o > 9 ? o : "0" + o, p = +l > 9 ? l : "0" + l; - a.data.dataList[e].list[s].list[i].valueList[n].curDurationStr = c + ":" + u, a.data.dataList[e].list[s].list[i].valueList[n].totalDurationStr = h + ":" + p, - a.setData({ - dataList: a.data.dataList - }); - } - }); - }, - rewind: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.item, s = t.currentTarget.dataset.idx, i = t.currentTarget.dataset.a, n = t.currentTarget.dataset.i; - e.isPlay && (this.data.dataList[a].list[s].list[n].valueList[i].curDuration = this.data.dataList[a].list[s].list[n].valueList[i].curDuration - this.data.speedStep, - r.seek(this.data.dataList[a].list[s].list[n].valueList[i].curDuration), this.setData({ - dataList: this.data.dataList - })); - }, - speed: function(t) { - var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.item, s = t.currentTarget.dataset.idx, i = t.currentTarget.dataset.a, n = t.currentTarget.dataset.i; - e.isPlay && (this.data.dataList[a].list[s].list[n].valueList[i].curDuration = this.data.dataList[a].list[s].list[n].valueList[i].curDuration + this.data.speedStep, - r.seek(this.data.dataList[a].list[s].list[n].valueList[i].curDuration), this.setData({ - dataList: this.data.dataList - })); - }, - slider4change: function(t) { - t.currentTarget.dataset.index; - t.currentTarget.dataset.item.isPlay && r.seek(t.detail.value); - }, - toSaveLocalImg: function(t) { - var a = t, e = wx.env.USER_DATA_PATH + "/indexshare.png", r = a.replace(/^data:image\/\w+;base64,/, ""); - wx.getFileSystemManager().writeFileSync(e, r, "base64"), this.setData({ - shareImgUrl: e - }); - }, - goHome: function() { - wx.switchTab({ - url: "/pages/index/index" - }); - }, - showDetail: function(t) { - if (-1 != t.currentTarget.dataset.ctype.indexOf("dda5007c-5fb7-48f2-8537-3cb8ea298242")) { - var a = t.currentTarget.dataset.cid, e = t.currentTarget.dataset.id; - wx.navigateTo({ - url: "../moments/momentsdetail/momentsdetail?uId=" + e + "&cId=" + a - }); - } - }, - showMore: function(t) { - var a = t.currentTarget.dataset.item; - if ("2" == a.mode) { - var e = t.currentTarget.dataset.userid, r = t.currentTarget.dataset.idx; - wx.navigateTo({ - url: "../../pages/moments/showlist/showlist?id=" + a.cId + "&userId=" + e + "&index=" + r - }); - } - }, - onChange: function(t) { - this.setData({ - active: t.detail - }); + _self.data.dataList.push(tempItem) + } + _self.setData({ + curIndex: ++_self.data.curIndex + }) + _self.getMainMoment(datas, id, _self.data.curIndex) + }) + .catch(err => { + _self.setData({ + curIndex: ++_self.data.curIndex + }) + _self.getMainMoment(datas, id, _self.data.curIndex) + }) + } else { + wx.hideLoading({}) + wx.stopPullDownRefresh({}) + _self.buildMainData() } -}); \ No newline at end of file + }, + //构建主页显示数据 + buildMainData() { + var _self = this + _self.data.dataList.forEach(it => { + it.list.forEach(item => { + item.list.forEach(iem => { + switch (iem.dataType) { + case '2': //图片 + var items = iem.value.split(',') + var tempList = [] + items.forEach(item => { + var tempItem = { + id: item, + path: app.urls.baseImgUrl + item, + } + tempList.push(tempItem) + }) + iem.valueList = tempList + break + case '3': //音频 + var items = iem.value.split(',') + var tempList = [] + items.forEach(item => { + var tempItem = { + id: item, //id + path: app.urls.baseImgUrl + item, //地址 + isPlay: false, //是否播放中 + duration: 100000, //时长 + curDuration: 0, + curDurationStr: '00:00', + totalDurationStr: '00:00' + } + tempList.push(tempItem) + }) + iem.valueList = tempList + break + case '4': //视频 + var items = iem.value.split(',') + var tempList = [] + for (var i = 0; i < items.length; i++) { + var ss = items[i].split('&') + var videoUrl = app.urls.baseImgUrl + ss[0] + var imgUrl = app.urls.baseImgUrl + ss[1] + var tempItem = { + path: videoUrl, + imgPath: imgUrl + } + tempList.push(tempItem) + } + iem.valueList = tempList + break + case '6': + var items = iem.value.split('-') + var tempList = [] + items.forEach(item => { + var latlng = item.split(',') + var tempItem = { + name: '', + address: '', + latitude: latlng[0], + longitude: latlng[1], + } + tempList.push(tempItem) + }) + iem.valueList = tempList + break + case '8': //单选 + iem.dictionariesList.forEach(ss => { + if (iem.value.indexOf(ss.dataId) != -1) { + iem.selValue = ss.dataName + } + }) + break + case '9': //多选 + iem.dictionariesList.forEach(ss => { + if (iem.value.indexOf(ss.dataId) != -1) { + ss.isSel = true + } else { + ss.isSel = false + } + }) + break + } + }) + }) + }) + _self.setData({ + curIndex: 0, + dataList: _self.data.dataList + }) + }, + // 加入卡包 + includedCard: function () { + var self = this + app.http.post(app.urls.includedCard, { + header: { + token: app.globalData.token + }, + data: { + cardTemplateUseBagId: "", + cardTemplateUseId: self.data.cardInfo.cardTemplateUseId, + cardTemplateUseStar: "", + cardTemplateUseTag: "", + cardTemplateUseTop: "" + } + }).then(res => { + if (res.statusCode == '200') { + wx.showToast({ + title: '加入卡包成功!', + }) + } + }) + }, + // 获取名片id + getCardId: function () { + var self = this + app.http.get(app.urls.getCardUseId.format({ + cardTemplateDispatchId: self.data.cardTemplateDispatchId + }), { + header: { + token: self.data.token + } + }).then(res => { + self.setData({ + cardTemplateUseId: res.data.cardTemplateUseDTO.cardTemplateUseId + }) + self.getCard() + self.saveCheckRecord() + }) + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.setData({ + cardTemplateDispatchId: options.cardTemplateDispatchId + }) + this.doLogin() + }, + // 拨打电话 + makeCall: function () { + var self = this + var phone = self.data.phoneTxt + if (phone) { + wx.makePhoneCall({ + phoneNumber: phone, + }) + } + }, + // 复制文本 + copyText: function (e) { + var self = this + var text = e.currentTarget.dataset.text + if (text) { + wx.setClipboardData({ + data: text, + success: function () {} + }) + } + }, + // 展示名片码 + showBarCode: function () { + this.setData({ + isShowBarCode: true + }) + }, + // 隐藏名片码 + hideBarCode: function () { + this.setData({ + isShowBarCode: false + }) + }, + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function (res) { + var self = this + wx.showShareMenu({ + withShareTicket: true, + success: function (res) { + console.log(res) + } + }) + + if (res.from == 'button') { + var postId = self.buildId() + self.shareRecord(postId) + + var param = '/pages/sharePage/sharePage?cardTemplateDispatchId=' + postId; + return { + title: '名片分享', + path: param, + imageUrl: self.data.shareImgUrl + } + // return返回 title 转发标题 path 路径 imageUrl 自定义图片,可以本地路径 代码包文件路径 支持png jpg 显示长宽比5:4 + } + }, + //获取浏览当前名片的用户头像列表 + getBrowCardUserList(id) { + var _self = this + app.http.get(app.urls.getCardBrowUserList, { + header: { + token: app.globalData.token + }, + data: { + page: '1', + rows: '7', + cardTemplateUseId: id + } + }) + .then(res => { + if (res.data) { + _self.setData({ + browUserList: res.data.rows + }) + } + }) + .catch(err => { + console.log(err) + }) + }, + // 转发记录 + shareRecord: function (cardTemplateDispatchId) { + var self = this + app.http.post(app.urls.shareRecord, { + header: { + token: app.globalData.token + }, + data: { + cardTemplateUseId: self.data.cardInfo.cardTemplateUseId, + cardTemplateDispatchParentId: self.data.cardTemplateDispatchId, + cardTemplateDispatchId: cardTemplateDispatchId + } + }).then(res => { + console.log(res.data) + self.setData({ + shareRecordId: res.data.data + }) + }) + }, + // 生成随机id + buildId: function () { + var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; + var nums = ""; + for (var i = 0; i < 36; i++) { + var id = parseInt(Math.random() * 61); + nums += chars[id]; + } + return nums + }, + //预览图片 + viewImg(e) { + wx.previewImage({ + urls: [e.currentTarget.dataset.url], + }) + }, + //预览视频 + viewVideo(e) { + var url = e.currentTarget.dataset.url + wx.previewMedia({ + sources: [{ + url: url, + type: 'video' + }], + }) + }, + play(e) { + //进行播放 + const _self = this + const index = e.currentTarget.dataset.index + const idx = e.currentTarget.dataset.idx + const ix = e.currentTarget.dataset.i + const a = e.currentTarget.dataset.a + var audio = e.currentTarget.dataset.item + //先需要停止其他录音文件的播放 + _self.data.dataList.forEach(it => { + it.list.forEach(item => { + item.list.forEach(ix => { + if (ix.dataType == '3') { + if (ix.valueList) { + ix.valueList.forEach(ii => { + if (ii.isPlay) { + innerAudioContext.stop() + } + ii.isPlay = false + ii.curDuration = 0 + ii.curDuationStr = '00:00' + }) + } + } + }) + }) + }) + if (!audio.isPlay) { + innerAudioContext = wx.createInnerAudioContext() + innerAudioContext.src = _self.data.dataList[index].list[idx].list[ix].valueList[a].path + '.mp3' + innerAudioContext.autoplay = true + console.log(_self.data.dataList[index].list[idx].list[ix].valueList[a].path) + } else { + innerAudioContext.stop() + } + + + innerAudioContext.onPlay(() => { + console.log('onPlay') + _self.data.dataList[index].list[idx].list[ix].valueList[a]['isPlay'] = true + _self.setData({ + dataList: _self.data.dataList + }) + }); + + innerAudioContext.onCanplay((res) => { + // if (_self.data.waitFlag) { + // innerAudioContext.play() + // _self.setData({ + // waitFlag: false + // }) + // } + }) + innerAudioContext.onStop((res) => { + console.log('停止播放') + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + }) + innerAudioContext.destroy() + }) + innerAudioContext.onEnded((res) => { + console.log(res) + console.log('播放完毕') + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + }) + innerAudioContext.destroy() + }) + innerAudioContext.onError((res) => { + console.log('播放错误') + console.log(res) + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + }) + innerAudioContext.destroy() + }) + innerAudioContext.onSeeking(() => { + // console.log(innerAudioContext.currentTime) + }) + innerAudioContext.onWaiting(() => { + // console.log('onWaiting') + // innerAudioContext.pause() + // _self.setData({ + // waitFlag: true + // }) + }) + innerAudioContext.onTimeUpdate(() => { + if (innerAudioContext.duration != Infinity) { + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = parseInt(innerAudioContext.currentTime) + _self.data.dataList[index].list[idx].list[ix].valueList[a].duration = parseInt(innerAudioContext.duration) + var curM = parseInt(innerAudioContext.currentTime / 60) //分钟 + var curS = parseInt(innerAudioContext.currentTime % 60) //秒 + var tM = parseInt(innerAudioContext.duration / 60) //分钟 + var tS = parseInt(innerAudioContext.duration % 60) //秒 + var curMStr = curM > 9 ? curM : '0' + curM + var curSStr = curS > 9 ? curS : '0' + curS + var totalMStr = tM > 9 ? tM : '0' + tM + var totalSStr = +tS > 9 ? tS : '0' + tS + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = curMStr + ':' + curSStr + _self.data.dataList[index].list[idx].list[ix].valueList[a].totalDurationStr = totalMStr + ':' + totalSStr + _self.setData({ + dataList: _self.data.dataList + }) + } + }) + }, + //倒退5秒 + rewind(e) { + var _self = this + var index = e.currentTarget.dataset.index + var item = e.currentTarget.dataset.item + var idx = e.currentTarget.dataset.idx + var a = e.currentTarget.dataset.a + var ix = e.currentTarget.dataset.i + if (item.isPlay) { + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration - _self.data.speedStep + innerAudioContext.seek(_self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration) + _self.setData({ + dataList: _self.data.dataList + }) + } + + }, + //快进5秒 + speed(e) { + var _self = this + var index = e.currentTarget.dataset.index + var item = e.currentTarget.dataset.item + var idx = e.currentTarget.dataset.idx + var a = e.currentTarget.dataset.a + var ix = e.currentTarget.dataset.i + if (item.isPlay) { + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration + _self.data.speedStep + innerAudioContext.seek(_self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration) + _self.setData({ + dataList: _self.data.dataList + }) + } + }, + slider4change(e) { + var index = e.currentTarget.dataset.index + var item = e.currentTarget.dataset.item + if (item.isPlay) { + innerAudioContext.seek(e.detail.value) + } + }, + //将分享的Base64图片保存至本地 + toSaveLocalImg(data) { + var base64 = data + var imgPath = wx.env.USER_DATA_PATH + '/index' + 'share.png' + var imageData = base64.replace(/^data:image\/\w+;base64,/, ""); + var fs = wx.getFileSystemManager(); + fs.writeFileSync(imgPath, imageData, "base64"); + this.setData({ + shareImgUrl: imgPath + }) + }, + goHome() { + wx.switchTab({ + url: '/pages/index/index', + }) + }, + //显示详情 + showDetail(e) { + var type = e.currentTarget.dataset.ctype //需要跳详情 + if (type.indexOf('dda5007c-5fb7-48f2-8537-3cb8ea298242') != -1) { + //需要跳详情 + var cId = e.currentTarget.dataset.cid + var uId = e.currentTarget.dataset.id + wx.navigateTo({ + url: '../moments/momentsdetail/momentsdetail?uId=' + uId + '&cId=' + cId, + }) + } + }, + //显示更多栏目数据 + showMore(e) { + var item = e.currentTarget.dataset.item + if (item.mode == '2') { + var userid = e.currentTarget.dataset.userid + var idx = e.currentTarget.dataset.idx + wx.navigateTo({ + url: '../../pages/moments/showlist/showlist?id=' + item.cId + '&userId=' + userid + '&index=' + idx + }) + } + }, + //tabbar切换 + onChange(e) { + this.setData({ + active: e.detail + }) + } +}) \ No newline at end of file diff --git a/pages/center/case/caseList.js b/pages/center/case/caseList.js index 5f6bc80..c134f30 100644 --- a/pages/center/case/caseList.js +++ b/pages/center/case/caseList.js @@ -1,4 +1,4 @@ -var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp(); +var e = getApp(); Page({ data: { diff --git a/pages/community/changeCommunity.js b/pages/community/changeCommunity.js index 9f13fcc..3e0c1db 100644 --- a/pages/community/changeCommunity.js +++ b/pages/community/changeCommunity.js @@ -1,159 +1,164 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), a = getApp(); +var a = getApp(); Page({ - data: { - token: a.globalData.token, - sourceUrl: a.baseUrls.sourceUrl, - areaList: [], - areaIndex: 0, - areaAll: [], - areaSelected: "", - areaName: "", - communityList: [], - myCommunityList: [], - page: { - rows: 10, - page: 1, - areaCode: "" - } - }, - getAreaList: function() { - var t = this; - a.restAjax.get(a.restAjax.path(a.apis.getArea, [ a.baseUrls.serviceUrl, "110889" ]), {}, { - headers: { - token: a.globalData.token - } - }, function(a, r) { - for (var n = t.data.areaList, o = 0; o < r.length; o++) n.push(r[o].areaName); - t.setData(e({ - areaList: n, - areaAll: r, - areaSelected: r[0].areaCode, - areaName: r[0].areaName - }, "page.areaCode", r[0].areaCode)), t.getCommunity(); - }, function(e, a) { - console.log(a); + data: { + token: a.globalData.token, + sourceUrl: a.baseUrls.sourceUrl, + areaList: [], + areaIndex: 0, + areaAll: [], + areaSelected: "", + areaName: "", + communityList: [], + myCommunityList: [], + page: { + rows: 10, + page: 1, + areaCode: "" + } + }, + getAreaList: function () { + var t = this; + a.restAjax.get(a.restAjax.path(a.apis.getArea, [a.baseUrls.serviceUrl, "110889"]), {}, { + headers: { + token: a.globalData.token + } + }, function (a, r) { + for (var n = t.data.areaList, o = 0; o < r.length; o++) { + n.push(r[o].areaName) + } + t.setData({ + areaList: n, + areaAll: r, + areaSelected: r[0].areaCode, + areaName: r[0].areaName, + "page.areaCode": r[0].areaCode + }); + t.getCommunity(); + }, function (e, a) { + console.log(a); + }); + }, + getCommunity: function () { + var t = this, r = t.data.page; + t.data.keywords && (r.keywords = t.data.keywords), a.restAjax.get(a.restAjax.path(a.apis.getCommunityListPage, [a.baseUrls.communityUrl]), r, { + headers: { + token: a.globalData.token + } + }, function (a, r) { + if (1 == t.data.page.page) t.setData({ + communityList: r.rows + }); else if (r.rows.length > 0) { + for (var n = t.data.communityList, o = 0; o < r.rows.length; o++) n.push(r.rows[o]); + t.setData({ + communityList: n }); - }, - getCommunity: function() { - var t = this, r = t.data.page; - t.data.keywords && (r.keywords = t.data.keywords), a.restAjax.get(a.restAjax.path(a.apis.getCommunityListPage, [ a.baseUrls.communityUrl ]), r, { - headers: { - token: a.globalData.token - } - }, function(a, r) { - if (1 == t.data.page.page) t.setData({ - communityList: r.rows - }); else if (r.rows.length > 0) { - for (var n = t.data.communityList, o = 0; o < r.rows.length; o++) n.push(r.rows[o]); - t.setData({ - communityList: n - }); - } else t.setData(e({}, "page.page", t.data.page.page - 1)); - r.rows.length < 10 && t.setData({ - haveMore: !1 - }); - }, function(e, a) { - console.log(a); - }); - }, - bindAreaPickerChange: function(a) { - var t; - this.setData((t = { - areaIndex: a.detail.value, - areaSelected: this.data.areaAll[a.detail.value].areaCode - }, e(t, "page.areaCode", this.data.areaAll[a.detail.value].areaCode), e(t, "page.page", 1), - e(t, "haveMore", !0), t)), this.getCommunity(); - }, - getMyCommunity: function() { - var e = this; - a.restAjax.get(a.restAjax.path(a.apis.mycommunity, [ a.baseUrls.requestUrl ]), {}, { - headers: { - token: a.globalData.token - } - }, function(a, t) { - e.setData({ - myCommunityList: t - }); - }, function(e, a) { - console.log(a); - }); - }, - otherCommunity: function() { - wx.navigateTo({ - url: "./selectCommunity" - }); - }, - selectCommunity: function(e) { - var t = { - communityId: e.currentTarget.dataset.item.communityId, - communityName: e.currentTarget.dataset.item.communityName - }; - a.globalData.currentCommunity = t, wx.setStorage({ - data: e.currentTarget.dataset.item.communityName, - key: "curCommunityName" - }), wx.setStorage({ - data: e.currentTarget.dataset.item.communityId, - key: "curCommunityId" - }), wx.setStorage({ - data: e.currentTarget.dataset.item.locationCode, - key: "areaCode" - }), wx.setStorage({ - data: parseInt(e.currentTarget.dataset.item.areaLevel), - key: "areaLevel" - }), wx.reLaunch({ - url: "../index/index" - }); - }, - selectMyCommunity: function(e) { - var t = { - communityId: e.currentTarget.dataset.item.communityId, - communityName: e.currentTarget.dataset.item.communityName - }; - a.globalData.currentCommunity = t, wx.setStorage({ - data: e.currentTarget.dataset.item.communityName, - key: "curCommunityName" - }), wx.setStorage({ - data: e.currentTarget.dataset.item.communityId, - key: "curCommunityId" - }), wx.setStorage({ - data: e.currentTarget.dataset.item.areaCode, - key: "areaCode" - }), wx.setStorage({ - data: "4", - key: "areaLevel" - }), wx.reLaunch({ - url: "../index/index" - }); - }, - loadMore: function() { - this.setData(e({}, "page.page", this.data.page.page + 1)), this.getCommunity(); - }, - enterCurrentArea: function() { - wx.setStorage({ - data: this.data.areaAll[this.data.areaIndex].areaName, - key: "curCommunityName" - }), wx.setStorage({ - data: this.data.areaAll[this.data.areaIndex].areaId, - key: "curCommunityId" - }), wx.setStorage({ - data: this.data.page.areaCode, - key: "areaCode" - }), wx.setStorage({ - data: parseInt(this.data.areaAll[this.data.areaIndex].areaLevel), - key: "areaLevel" - }), wx.reLaunch({ - url: "../index/index" - }); - }, - onLoad: function(e) { - this.getAreaList(), this.getMyCommunity(); - }, - onReady: function() {}, - onShow: function() {}, - onHide: function() {}, - onUnload: function() {}, - onPullDownRefresh: function() {}, - onReachBottom: function() {}, - onShareAppMessage: function() {} + } else t.setData(e({}, "page.page", t.data.page.page - 1)); + r.rows.length < 10 && t.setData({ + haveMore: !1 + }); + }, function (e, a) { + console.log(a); + }); + }, + bindAreaPickerChange: function (a) { + var _self = this; + _self.setData({ + areaIndex: a.detail.value, + areaSelected: _self.data.areaAll[a.detail.value].areaCode, + "page.areaCode": _self.data.areaAll[a.detail.value].areaCode, + "page.page": 1, + "haveMore": !0 + }) + _self.getCommunity(); + }, + getMyCommunity: function () { + var e = this; + a.restAjax.get(a.restAjax.path(a.apis.mycommunity, [a.baseUrls.requestUrl]), {}, { + headers: { + token: a.globalData.token + } + }, function (a, t) { + e.setData({ + myCommunityList: t + }); + }, function (e, a) { + console.log(a); + }); + }, + otherCommunity: function () { + wx.navigateTo({ + url: "./selectCommunity" + }); + }, + selectCommunity: function (e) { + var t = { + communityId: e.currentTarget.dataset.item.communityId, + communityName: e.currentTarget.dataset.item.communityName + }; + a.globalData.currentCommunity = t, wx.setStorage({ + data: e.currentTarget.dataset.item.communityName, + key: "curCommunityName" + }), wx.setStorage({ + data: e.currentTarget.dataset.item.communityId, + key: "curCommunityId" + }), wx.setStorage({ + data: e.currentTarget.dataset.item.locationCode, + key: "areaCode" + }), wx.setStorage({ + data: parseInt(e.currentTarget.dataset.item.areaLevel), + key: "areaLevel" + }), wx.reLaunch({ + url: "../index/index" + }); + }, + selectMyCommunity: function (e) { + var t = { + communityId: e.currentTarget.dataset.item.communityId, + communityName: e.currentTarget.dataset.item.communityName + }; + a.globalData.currentCommunity = t, wx.setStorage({ + data: e.currentTarget.dataset.item.communityName, + key: "curCommunityName" + }), wx.setStorage({ + data: e.currentTarget.dataset.item.communityId, + key: "curCommunityId" + }), wx.setStorage({ + data: e.currentTarget.dataset.item.areaCode, + key: "areaCode" + }), wx.setStorage({ + data: "4", + key: "areaLevel" + }), wx.reLaunch({ + url: "../index/index" + }); + }, + loadMore: function () { + this.setData({ + "page.page": this.data.page.page + 1 + }); + this.getCommunity(); + }, + enterCurrentArea: function () { + wx.setStorage({ + data: this.data.areaAll[this.data.areaIndex].areaName, + key: "curCommunityName" + }), wx.setStorage({ + data: this.data.areaAll[this.data.areaIndex].areaId, + key: "curCommunityId" + }), wx.setStorage({ + data: this.data.page.areaCode, + key: "areaCode" + }), wx.setStorage({ + data: parseInt(this.data.areaAll[this.data.areaIndex].areaLevel), + key: "areaLevel" + }), wx.reLaunch({ + url: "../index/index" + }); + }, + onLoad: function (e) { + this.getAreaList(); + this.getMyCommunity(); + }, + }); \ No newline at end of file diff --git a/pages/community/selectCommunity.js b/pages/community/selectCommunity.js index 821371f..fe86441 100644 --- a/pages/community/selectCommunity.js +++ b/pages/community/selectCommunity.js @@ -1,4 +1,4 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), a = getApp(); +var a = getApp(); Page({ data: { diff --git a/pages/index/index.js b/pages/index/index.js index 40a2de3..2fba967 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -105,7 +105,7 @@ Page({ }); }, doLogin: function () { - var _self= this; + var _self = this; wx.login({ success: function (a) { t.restAjax.post(t.restAjax.path(t.apis.doLogin, [t.baseUrls.serviceUrl]), { @@ -117,7 +117,7 @@ Page({ token: t.globalData.token, isBindPhone: 0 == r }), "" != _self.data.cardId && null != _self.data.cardId ? (console.log(_self.data.cardId), - _self.getCard()) : _self.getDefaultCard(), _self.getNotice(), "" != _self.data.cardTemplateDispatchId && null != _self.data.cardTemplateDispatchId) { + _self.getCard()) : _self.getDefaultCard(), _self.getNotice(), "" != _self.data.cardTemplateDispatchId && null != _self.data.cardTemplateDispatchId) { var s = "/pages/mine/otherCard/othercarddetail?cardTemplateUseId=" + _self.data.cardTemplateDispatchId; wx.navigateTo({ url: s @@ -243,7 +243,10 @@ Page({ onLoad: function (e) { e.cardTemplateDispatchId && this.setData({ cardTemplateDispatchId: e.cardTemplateDispatchId - }), this.doLogin(), this.checkPermission(), wx.setStorage({ + }); + this.doLogin(); + this.checkPermission(); + wx.setStorage({ data: "1", key: "gridMiniId" }); diff --git a/pages/mine/myCard/myCard.js b/pages/mine/myCard/myCard.js index 3d11e9c..f6ca8f0 100644 --- a/pages/mine/myCard/myCard.js +++ b/pages/mine/myCard/myCard.js @@ -1,4 +1,4 @@ -var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(); +var a = getApp(); Page({ data: { diff --git a/pages/mine/myCardDetail/myCardDetail.js b/pages/mine/myCardDetail/myCardDetail.js index 7a14d45..3ca6d50 100644 --- a/pages/mine/myCardDetail/myCardDetail.js +++ b/pages/mine/myCardDetail/myCardDetail.js @@ -1,4 +1,4 @@ -var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp(); +var e = getApp(); Page({ data: { diff --git a/pages/mine/otherCard/othercarddetail.js b/pages/mine/otherCard/othercarddetail.js index e59dbf7..e21bb7b 100644 --- a/pages/mine/otherCard/othercarddetail.js +++ b/pages/mine/otherCard/othercarddetail.js @@ -1,574 +1,713 @@ -var t, a = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp(), n = wx.createInnerAudioContext(); - -Page((a(t = { +const app = getApp() +var innerAudioContext = wx.createInnerAudioContext() +Page({ data: { - nameTxt: "名片", + nameTxt: '名片', dataList: [], - curIndex: 0, - speedStep: 5, - waitFlag: !1, - avatarUrl: e.globalData.userInfo.avatarUrl, + curIndex: 0, //用来记录请求次数 + speedStep: 5, //快进快退秒数 + waitFlag: false, + avatarUrl: app.globalData.userInfo.avatarUrl, areaList: [], - cardHeight: "", + cardHeight: '', cardInfo: {}, - cardUrl: e.baseUrls.baseCardUrl, + cardUrl: app.urls.baseImgUrl, personIntro: {}, companyIntro: {}, - shareImg: "", - phoneTxt: "未录入", - emailTxt: "未录入", - wechateTxt: "未录入", - addressTxt: "未录入", + shareImg: '', + phoneTxt: '未录入', + emailTxt: '未录入', + wechateTxt: '未录入', + addressTxt: '未录入', viewInfo: {}, - forwardCount: "", - imgUrl: e.baseUrls.baseCardUrl, - shareRecordId: "", - isShowBarCode: !1, + forwardCount: '', + imgUrl: app.urls.baseImgUrl, + shareRecordId: '', + isShowBarCode: false, browUserList: [], - shareImgUrl: "", - tempUserId: "", - cardTemplateDispatchId: "", - cardTemplateUseId: "", - isShowCard: !1, - otherCardList: [], - isPlayAudio: !1, - audioId: "", + shareImgUrl: '', + tempUserId: '', //当前名片用户的ID + cardTemplateDispatchId: '', //用来标记是否是分享过来的 + cardTemplateUseId: '', //分享过来的名片id + isShowCard: false, //用来显示我浏览过的名片 + otherCardList: [], //卡包名片 + isPlayAudio: false, //标识当前是否在播放音乐 + audioId: '', count: 3, animationData: {}, - isShowBtn: !1 + isShowBtn: false }, - onLoad: function(t) { - this.setData({ - cardTemplateUseId: t.cardTemplateUseId - }), this.buildId(), this.getCard(); + onLoad(options) { + var self = this + self.setData({ + cardTemplateUseId: options.cardTemplateUseId + }) + self.buildId() + self.getCard() }, - getCard: function() { - var t = this; - e.http.get(e.urls.shareCard.format({ - cardTemplateUseId: t.data.cardTemplateUseId + // 获取名片 + getCard() { + var self = this + app.http.get(app.urls.shareCard.format({ + cardTemplateUseId: self.data.cardTemplateUseId }), { header: { - token: e.globalData.token + token: app.globalData.token } - }).then(function(a) { - var e = a.data.areaList; - e.forEach(function(a) { - "name" == a.templateAreaSource && t.setData({ - nameTxt: a.templateAreaFontValue - }); - }), t.setData({ - cardInfo: a.data, - areaList: e, - dataList: [] - }), a.data && (t.toSaveLocalImg(a.data.cardTemplateUseDispatchPhoto), t.getBrowCardUserList(a.data.cardTemplateUseId), - t.setData({ - tempUserId: a.data.creator - }), t.getMainColumn(a.data.creator), t.getMainBaseUserInfo(a.data.creator)); - }); - }, - toSaveLocalImg: function(t) { - var a = t, e = wx.env.USER_DATA_PATH + "/indexshare.png", n = a.replace(/^data:image\/\w+;base64,/, ""); - wx.getFileSystemManager().writeFileSync(e, n, "base64"), this.setData({ - shareImgUrl: e - }); - }, - getBrowCardUserList: function(t) { - var a = this; - e.http.get(e.urls.getCardBrowUserList, { - header: { - token: e.globalData.token - }, - data: { - page: "1", - rows: "7", - cardTemplateUseId: t - } - }).then(function(t) { - t.data && a.setData({ - browUserList: t.data.rows - }); - }).catch(function(t) { - console.log(t); - }); - }, - getMainColumn: function(t) { - var a = this; - a.setData({ - dataList: [] - }), e.http.get(e.urls.getMainColumn, { - header: { - token: e.globalData.token - }, - data: { - creator: t - } - }).then(function(e) { - wx.showLoading({ - title: "加载中..." - }), a.getMainMoment(e.data, t, 0); - }).catch(function(t) { - wx.stopPullDownRefresh({}); - }); - }, - getMainMoment: function(t, a, n) { - var i = this; - n < t.length ? e.http.get(e.urls.getMainMoment.format({ - configColumnId: t[i.data.curIndex].configColumnId - }), { - header: { - token: e.globalData.token - }, - data: { - userId: a - } - }).then(function(e) { - if (e.data.length > 0) { - var n = t[i.data.curIndex], o = { - funcSwitch: "2" == n.configColumnCollect || "4" == n.configColumnCollect || "2" == n.configColumnLike && "4" == n.configColumnLike || "2" == n.configColumnDispatch || "4" == n.configColumnDispatch || "2" == n.configColumnComment || "4" == n.configColumnComment, - collectSwitch: t[i.data.curIndex].configColumnCollect, - commentSwitch: t[i.data.curIndex].configColumnComment, - shareSwitch: t[i.data.curIndex].configColumnDispatch, - likeSwitch: t[i.data.curIndex].configColumnLike, - cId: t[i.data.curIndex].configColumnId, - type: t[i.data.curIndex].configColumnType, - name: t[i.data.curIndex].configColumnName, - mode: t[i.data.curIndex].configTableMode, - list: e.data.slice(0, t[i.data.curIndex].configColumnRowCount) - }; - i.data.dataList.push(o); - } - i.setData({ - curIndex: ++i.data.curIndex - }), i.getMainMoment(t, a, i.data.curIndex); - }).catch(function(e) { - i.setData({ - curIndex: ++i.data.curIndex - }), t[i.data.curIndex] && i.getMainMoment(t, a, i.data.curIndex); - }) : (wx.hideLoading({}), wx.stopPullDownRefresh({}), i.buildMainData()); - }, - buildMainData: function() { - var t = ""; - this.data.dataList.forEach(function(a) { - a.list.forEach(function(a) { - t += a.uid + ",", a.collectCount = 0, a.collectStatus = !1, a.commentCount = 0, - a.dispatchCount = 0, a.likeCount = 0, a.likeStatus = !1, a.scansCount = 0, a.list.forEach(function(t) { - switch (t.dataType) { - case "2": - if (t.value.length > 0) { - var a = t.value.split("@"); - a.length > 1 ? t.dataMode = a[1] : t.dataMode = "1"; - var n = a[0].split(","), i = []; - n.forEach(function(t) { - var a = { - id: t, - path: e.baseUrls.baseCardUrl + t - }; - i.push(a); - }), t.valueList = i; - } - break; - - case "3": - n = t.value.split(","), i = []; - n.forEach(function(t) { - if (t.length > 0) { - var a = t.split("&"), n = "00:00"; - if (a.length > 1) { - var o = a[1], s = parseInt(o / 60), r = parseInt(o % 60); - n = (s > 9 ? s : "0" + s) + ":" + (+r > 9 ? r : "0" + r); - } - var d = { - id: a[0], - path: e.baseUrls.baseCardUrl + a[0], - isPlay: !1, - duration: 1e5, - curDuration: 0, - curDurationStr: "00:00", - totalDurationStr: n - }; - i.push(d); - } - }), t.valueList = i; - break; - - case "4": - n = t.value.split(","), i = []; - for (var o = 0; o < n.length; o++) if (n[o].length > 0) { - var s = n[o].split("&"), r = { - path: e.baseUrls.baseCardUrl + s[0], - imgPath: e.baseUrls.baseCardUrl + s[1] - }; - i.push(r); - } - t.valueList = i; - break; - - case "6": - n = t.value.split("-"), i = []; - n.forEach(function(t) { - if (t.length > 0) { - var a = t.split(","), e = { - name: "", - address: "", - latitude: a[0], - longitude: a[1] - }; - i.push(e); - } - }), t.valueList = i; - break; - - case "8": - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) && (t.selValue = a.dataName); - }); - break; - - case "9": - t.dictionariesList.forEach(function(a) { - -1 != t.value.indexOf(a.dataId) ? a.isSel = !0 : a.isSel = !1; - }); - } - }); - }); - }), this.setData({ - curIndex: 0, - dataList: this.data.dataList - }), this.getColumnContentHandle(t); - }, - getColumnContentHandle: function(t) { - var a = this; - wx.showLoading({ - title: "加载中..." - }), e.http.get(e.urls.getColumnContentHandle.format({ - projectId: "column", - businessIds: t - }), { - header: { - token: e.globalData.token - } - }).then(function(t) { - wx.hideLoading({}), t.data.forEach(function(t) { - a.data.dataList.forEach(function(a) { - a.list.forEach(function(a) { - a.uid == t.businessId && (a.collectCount = t.collectCount, a.collectStatus = t.collectStatus, - a.commentCount = t.commentCount, a.dispatchCount = t.dispatchCount, a.likeCount = t.likeCount, - a.likeStatus = t.likeStatus, a.scansCount = t.scansCount); - }); - }); - }), a.setData({ - curIndex: 0, - dataList: a.data.dataList - }); - }).catch(function(t) {}); - }, - getMainBaseUserInfo: function(t) { - var a = this; - e.http.get(e.urls.getMainMoment.format({ - configColumnId: "de7b5e22-64f9-4c60-a1f9-6ac004dfb9a8" - }), { - header: { - token: e.globalData.token - }, - data: { - userId: t - } - }).then(function(t) { - t.data.length > 0 ? (a.setData({ - isShowBtn: !0 - }), t.data[0].list.forEach(function(t) { - switch (t.name) { - case "phone": - a.setData({ - phoneTxt: t.value - }); - break; - - case "wechat": - a.setData({ - wechateTxt: t.value - }); - break; - - case "email": - a.setData({ - emailTxt: t.value - }); - break; - - case "address": - a.setData({ - addressTxt: t.value - }); + }).then(res => { + var area = res.data.areaList + area.forEach(it => { + if (it.templateAreaSource == 'name') { + self.setData({ + nameTxt: it.templateAreaFontValue + }) } - })) : a.setData({ - isShowBtn: !1 - }); - }).catch(function(t) { - console.log(t); - }); - }, - buildId: function() { - for (var t = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" ], a = "", e = 0; e < 36; e++) { - a += t[parseInt(61 * Math.random())]; - } - return a; - }, - showDetail: function(t) { - if (-1 != t.currentTarget.dataset.ctype.indexOf("dda5007c-5fb7-48f2-8537-3cb8ea298242")) { - var a = t.currentTarget.dataset.cid, e = t.currentTarget.dataset.id, n = t.currentTarget.dataset.like, i = "&collectSwitch=" + t.currentTarget.dataset.collect + "&likeSwitch=" + n + "&commentSwitch=" + t.currentTarget.dataset.comment + "&shareSwitch=" + t.currentTarget.dataset.share; - wx.navigateTo({ - url: "/packagecard/moments/momentsdetail/momentsdetail?uId=" + e + "&cId=" + a + i - }); - } - }, - onHide: function(t) { - this.setData({ - isShowCard: !1 - }), n && n.stop(); - }, - onShareAppMessage: function(t) { - wx.showShareMenu({ - withShareTicket: !0, - success: function(t) { - console.log(t); + }) + self.setData({ + cardInfo: res.data, + areaList: area, + dataList: [] + }) + + if (res.data) { + self.toSaveLocalImg(res.data.cardTemplateUseDispatchPhoto) //保存分享的图片 + self.getBrowCardUserList(res.data.cardTemplateUseId) //获取浏览数量 + self.setData({ + tempUserId: res.data.creator + }) + self.getMainColumn(res.data.creator) //获取当前用户的栏目 + self.getMainBaseUserInfo(res.data.creator) //获取当前人员基础信息 } - }); - var a = this.buildId(); - return this.shareRecord(a), { - title: "您好,这是我的电子名片,请查看.", - path: "/pages/index/index?cardTemplateDispatchId=" + a, - imageUrl: this.data.shareImgUrl - }; + }) }, - shareRecord: function(t) { - var a = this; - e.http.post(e.urls.shareRecord, { + //将分享的Base64图片保存至本地 + toSaveLocalImg(data) { + var _self = this + var base64 = data + var imgPath = wx.env.USER_DATA_PATH + '/index' + 'share.png' + var imageData = base64.replace(/^data:image\/\w+;base64,/, ""); + var fs = wx.getFileSystemManager(); + fs.writeFileSync(imgPath, imageData, "base64"); + this.setData({ + shareImgUrl: imgPath + }) + }, + //获取浏览当前名片的用户头像列表 + getBrowCardUserList(id) { + var _self = this + app.http.get(app.urls.getCardBrowUserList, { + header: { + token: app.globalData.token + }, + data: { + page: '1', + rows: '7', + cardTemplateUseId: id + } + }) + .then(res => { + if (res.data) { + _self.setData({ + browUserList: res.data.rows + }) + } + }) + .catch(err => { + console.log(err) + }) + }, + //获取首页展示的栏目 + getMainColumn(id) { + console.log(id) + var _self = this + _self.setData({ + dataList: [] + }) + app.http.get(app.urls.getMainColumn, { + header: { + token: app.globalData.token + }, + data: { + creator: id + } + }) + .then(res => { + wx.showLoading({ + title: '加载中...', + }) + _self.getMainMoment(res.data, id, 0) + }) + .catch(err => { + wx.stopPullDownRefresh({}) + }) + }, + //获取首页栏目数据 + getMainMoment(datas, userid, index) { + var _self = this + var count = datas.length + if (index < count) { + app.http.get(app.urls.getMainMoment.format({ + configColumnId: datas[_self.data.curIndex].configColumnId + }), { + header: { + token: app.globalData.token + }, + data: { + userId: userid + } + }) + .then(res => { + if (res.data.length > 0) { + var tempItem = { + cId: datas[_self.data.curIndex].configColumnId, + type: datas[_self.data.curIndex].configColumnType, + name: datas[_self.data.curIndex].configColumnName, + mode: datas[_self.data.curIndex].configTableMode, + list: res.data.slice(0, datas[_self.data.curIndex].configColumnRowCount) + } + _self.data.dataList.push(tempItem) + } + _self.setData({ + curIndex: ++_self.data.curIndex + }) + _self.getMainMoment(datas, userid, _self.data.curIndex) + + }) + .catch(err => { + _self.setData({ + curIndex: ++_self.data.curIndex + }) + if (datas[_self.data.curIndex]) { + _self.getMainMoment(datas, userid, _self.data.curIndex) + } + }) + } else { + wx.hideLoading({}) + wx.stopPullDownRefresh({}) + _self.buildMainData() + } + }, + //构建主页显示数据 + buildMainData() { + var _self = this + _self.data.dataList.forEach(it => { + it.list.forEach(item => { + item.list.forEach(iem => { + switch (iem.dataType) { + case '2': //图片 + var photoIds = iem.value.split('@') + if (photoIds.length > 1) { + //展示方式 + iem.dataMode = photoIds[1] + } else { + iem.dataMode = '1' + } + var items = photoIds[0].split(',') + var tempList = [] + items.forEach(item => { + var tempItem = { + id: item, + path: app.urls.baseImgUrl + item, + } + tempList.push(tempItem) + }) + iem.valueList = tempList + break + case '3': //音频 + var items = iem.value.split(',') + var tempList = [] + items.forEach(item => { + if (item.length > 0) { + var ss = item.split('&') + var totalStr = '00:00' + if (ss.length > 1) { + var dur = ss[1] + var tM = parseInt(dur / 60) //分钟 + var tS = parseInt(dur % 60) //秒 + var totalMStr = tM > 9 ? tM : '0' + tM + var totalSStr = +tS > 9 ? tS : '0' + tS + totalStr = totalMStr + ':' + totalSStr + } + var tempItem = { + id: ss[0], //id + path: app.urls.baseImgUrl + ss[0], //地址 + isPlay: false, //是否播放中 + duration: 100000, //时长 + curDuration: 0, + curDurationStr: '00:00', + totalDurationStr: totalStr + } + tempList.push(tempItem) + } + }) + iem.valueList = tempList + break + case '4': //视频 + var items = iem.value.split(',') + var tempList = [] + for (var i = 0; i < items.length; i++) { + if (items[i].length > 0) { + var ss = items[i].split('&') + var videoUrl = app.urls.baseImgUrl + ss[0] + var imgUrl = app.urls.baseImgUrl + ss[1] + var tempItem = { + path: videoUrl, + imgPath: imgUrl + } + tempList.push(tempItem) + } + } + iem.valueList = tempList + break + case '6': + var items = iem.value.split('-') + var tempList = [] + items.forEach(item => { + if (item.length > 0) { + var latlng = item.split(',') + var tempItem = { + name: '', + address: '', + latitude: latlng[0], + longitude: latlng[1], + } + tempList.push(tempItem) + } + }) + iem.valueList = tempList + break + case '8': //单选 + iem.dictionariesList.forEach(ss => { + if (iem.value.indexOf(ss.dataId) != -1) { + iem.selValue = ss.dataName + } + }) + break + case '9': //多选 + iem.dictionariesList.forEach(ss => { + if (iem.value.indexOf(ss.dataId) != -1) { + ss.isSel = true + } else { + ss.isSel = false + } + }) + break + } + }) + }) + }) + _self.setData({ + curIndex: 0, + dataList: _self.data.dataList + }) + }, + //获取首页基础数据 电话 微信号 地址 邮箱 + getMainBaseUserInfo(userid) { + var _self = this + app.http.get(app.urls.getMainMoment.format({ + configColumnId: 'de7b5e22-64f9-4c60-a1f9-6ac004dfb9a8' + }), { + header: { + token: app.globalData.token + }, + data: { + userId: userid + } + }) + .then(res => { + if (res.data.length > 0) { + _self.setData({ + isShowBtn: true + }) + res.data[0].list.forEach(it => { + switch (it.name) { + case 'phone': + _self.setData({ + phoneTxt: it.value + }) + break + case 'wechat': + _self.setData({ + wechateTxt: it.value + }) + break + case 'email': + _self.setData({ + emailTxt: it.value + }) + break + case 'address': + _self.setData({ + addressTxt: it.value + }) + break + } + }) + } else { + _self.setData({ + isShowBtn: false + }) + } + }) + .catch(err => { + console.log(err) + }) + }, + // 生成随机id + buildId: function () { + var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; + + var nums = ""; + + for (var i = 0; i < 36; i++) { + var id = parseInt(Math.random() * 61); + + nums += chars[id]; + } + return nums + }, + //显示详情 + showDetail(e) { + var type = e.currentTarget.dataset.ctype //需要跳详情 + if (type.indexOf('dda5007c-5fb7-48f2-8537-3cb8ea298242') != -1) { + //需要跳详情 + var cId = e.currentTarget.dataset.cid + var uId = e.currentTarget.dataset.id + wx.navigateTo({ + url: '/packagecard/moments/momentsdetail/momentsdetail?uId=' + uId + '&cId=' + cId, + }) + } + }, + onHide(e) { + this.setData({ + isShowCard: false + }) + if (innerAudioContext) { + innerAudioContext.stop() + } + }, + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function (res) { + var self = this + wx.showShareMenu({ + withShareTicket: true, + success: function (res) { + console.log(res) + } + }) + + // if (res.from == 'button') { + var postId = self.buildId() + self.shareRecord(postId) + + var param = '/pages/index/index?cardTemplateDispatchId=' + postId; + return { + title: '您好,这是我的电子名片,请查看.', + path: param, + imageUrl: self.data.shareImgUrl + } + // return返回 title 转发标题 path 路径 imageUrl 自定义图片,可以本地路径 代码包文件路径 支持png jpg 显示长宽比5:4 + // } + }, + // 转发记录 + shareRecord: function (cardTemplateDispatchId) { + var self = this + app.http.post(app.urls.shareRecord, { header: { - token: e.globalData.token + token: app.globalData.token }, data: { - cardTemplateUseId: a.data.cardInfo.cardTemplateUseId, - cardTemplateDispatchParentId: "", - cardTemplateDispatchId: t + cardTemplateUseId: self.data.cardInfo.cardTemplateUseId, + cardTemplateDispatchParentId: '', + cardTemplateDispatchId: cardTemplateDispatchId } - }).then(function(t) { - a.setData({ - shareRecordId: t.data.data - }); - }); + }).then(res => { + self.setData({ + shareRecordId: res.data.data + }) + }) }, - showBarCode: function() { + // 展示名片码 + showBarCode: function () { + var _self = this wx.navigateTo({ - url: "/packagecard/sharePage/cardcode?cardImg=" + this.data.cardInfo.cardTemplateUsePhotoUrl + "&id=" + this.data.cardInfo.cardTemplateUseBarcode - }); + url: '/packagecard/sharePage/cardcode?cardImg=' + _self.data.cardInfo.cardTemplateUsePhotoUrl + '&id=' + _self.data.cardInfo.cardTemplateUseBarcode, + }) + // this.setData({ + // isShowBarCode: true + // }) + // wx.hideTabBar() + // var anim = wx.createAnimation({ + // duration: 1200, + // timingFunction: 'linear', + // transformOrigin: '50% 50% 0' + // }) + // anim.rotate(180).step() + // this.setData({ + // animationData: anim.export() + // }) }, - hideBarCode: function() { + // 隐藏名片码 + hideBarCode: function () { this.setData({ - isShowBarCode: !1 - }), wx.showTabBar(); + isShowBarCode: false + }) + wx.showTabBar() }, - getForwardCount: function() { - var t = this; - e.restAjax.get(e.restAjax.path("{cardUrl}app/templateforwardingrecord/count", [ e.cardUrl ]), { - templateUseId: t.data.cardInfo.cardPersonId + // 获取转发数 + getForwardCount: function () { + var self = this + app.restAjax.get(app.restAjax.path('{cardUrl}app/templateforwardingrecord/count', [app.cardUrl]), { + templateUseId: self.data.cardInfo.cardPersonId }, { headers: { - token: e.globalData.token + token: app.globalData.token } - }, function(a, e) { - t.setData({ - forwardCount: e.data - }); - }, function(t, a) { - e.dialog.msg(a.msg); + }, function (code, data) { + self.setData({ + forwardCount: data.data + }) + }, function (code, data) { + app.dialog.msg(data.msg); }); }, - copyText: function(t) { - var a = t.currentTarget.dataset.text; - a && wx.setClipboardData({ - data: a, - success: function() {} - }); + // 复制文本 + copyText: function (e) { + var self = this + var text = e.currentTarget.dataset.text + if (text) { + wx.setClipboardData({ + data: text, + success: function () {} + }) + } }, - includedCard: function() { - e.http.post(e.urls.includedCard, { - header: { - token: e.globalData.token - }, - data: { - cardTemplateUseBagId: "", - cardTemplateUseId: this.data.cardInfo.cardTemplateUseId, - cardTemplateUseStar: "", - cardTemplateUseTag: "", - cardTemplateUseTop: "" - } - }).then(function(t) { - console.log(t.data), wx.showToast({ - title: "加入卡包成功!" - }); - }).catch(function(t) {}); + // 加入卡包 + includedCard: function () { + var self = this + app.http.post(app.urls.includedCard, { + header: { + token: app.globalData.token + }, + data: { + cardTemplateUseBagId: "", + cardTemplateUseId: self.data.cardInfo.cardTemplateUseId, + cardTemplateUseStar: "", + cardTemplateUseTag: "", + cardTemplateUseTop: "" + } + }).then(res => { + console.log(res.data) + wx.showToast({ + title: '加入卡包成功!', + }) + }) + .catch(err => { + + }) }, - makeCall: function() { - var t = this.data.phoneTxt; - t && wx.makePhoneCall({ - phoneNumber: t - }); + // 拨打电话 + makeCall: function () { + var self = this + var phone = self.data.phoneTxt + if (phone) { + wx.makePhoneCall({ + phoneNumber: phone, + }) + } }, - getViewCount: function() { - var t = this; - e.restAjax.get(e.restAjax.path("{cardUrl}app/templateviewrecord/getByTemplateUseId/" + t.data.cardInfo.cardPersonId, [ e.cardUrl ]), {}, { + // 获取浏览数 + getViewCount: function () { + var self = this + app.restAjax.get(app.restAjax.path('{cardUrl}app/templateviewrecord/getByTemplateUseId/' + self.data.cardInfo.cardPersonId, [app.cardUrl]), {}, { headers: { - token: e.globalData.token + token: app.globalData.token + } + }, function (code, data) { + self.setData({ + viewInfo: data + }) + }, function (code, data) { + if (data.msg) { + app.dialog.msg(data.msg); } - }, function(a, e) { - t.setData({ - viewInfo: e - }); - }, function(t, a) { - a.msg && e.dialog.msg(a.msg); }); - } -}, "getBrowCardUserList", function(t) { - var a = this; - e.http.get(e.urls.getCardBrowUserList, { - header: { - token: e.globalData.token - }, - data: { - page: "1", - rows: "7", - cardTemplateUseId: t + }, + //获取浏览当前名片的用户头像列表 + getBrowCardUserList(id) { + var _self = this + app.http.get(app.urls.getCardBrowUserList, { + header: { + token: app.globalData.token + }, + data: { + page: '1', + rows: '7', + cardTemplateUseId: id + } + }) + .then(res => { + if (res.data) { + _self.setData({ + browUserList: res.data.rows + }) + } + }) + .catch(err => { + console.log(err) + }) + }, + // 存入通讯录 + addContact: function () { + var self = this + wx.addPhoneContact({ + firstName: self.data.nameTxt, + mobilePhoneNumber: self.data.phoneNum + }) + }, + //预览图片 + viewImg(e) { + var imgs = e.currentTarget.dataset.values + var cur = e.currentTarget.dataset.url + var imgPaths = [] + imgs.forEach(it => { + imgPaths.push(it.path) + }) + wx.previewImage({ + urls: imgPaths, + current: cur + }) + }, + //预览视频 + viewVideo(e) { + var url = e.currentTarget.dataset.url + wx.previewMedia({ + sources: [{ + url: url, + type: 'video' + }], + }) + }, + play(e) { + //进行播放 + const _self = this + const index = e.currentTarget.dataset.index + const idx = e.currentTarget.dataset.idx + const ix = e.currentTarget.dataset.i + const a = e.currentTarget.dataset.a + var audio = e.currentTarget.dataset.item + console.log(_self.data.isPlayAudio) + if (_self.data.isPlayAudio) { + //有播放的 + //先需要停止其他录音文件的播放 + _self.data.dataList.forEach(it => { + it.list.forEach(item => { + item.list.forEach(ix => { + if (ix.dataType == '3') { + if (ix.valueList) { + ix.valueList.forEach(ii => { + ii.isPlay = false + ii.curDuration = 0 + ii.curDuationStr = '00:00' + }) + } + } + }) + }) + }) + _self.setData({ + dataList: _self.data.dataList + }) + innerAudioContext.stop() + if (_self.data.audioId != audio.id) { + wx.showLoading({ + title: '加载中...', + }) + setTimeout(function () { + wx.hideLoading({}) + innerAudioContext.src = _self.data.dataList[index].list[idx].list[ix].valueList[a].path + '.mp3' + innerAudioContext.startTime = 0 + innerAudioContext.autoplay = true + _self.data.dataList[index].list[idx].list[ix].valueList[a]['isPlay'] = true + _self.setData({ + dataList: _self.data.dataList, + isPlayAudio: true, + audioId: audio.id + }) + }, 1500) + } + } else { + //没有播放的 + innerAudioContext.src = _self.data.dataList[index].list[idx].list[ix].valueList[a].path + '.mp3' + innerAudioContext.startTime = 0 + innerAudioContext.autoplay = true + innerAudioContext.play() + _self.data.dataList[index].list[idx].list[ix].valueList[a]['isPlay'] = true + _self.setData({ + dataList: _self.data.dataList, + isPlayAudio: true, + audioId: audio.id + }) } - }).then(function(t) { - t.data && a.setData({ - browUserList: t.data.rows + innerAudioContext.onPlay(() => { + }); - }).catch(function(t) { - console.log(t); - }); -}), a(t, "addContact", function() { - wx.addPhoneContact({ - firstName: this.data.nameTxt, - mobilePhoneNumber: this.data.phoneNum - }); -}), a(t, "viewImg", function(t) { - var a = t.currentTarget.dataset.values, e = t.currentTarget.dataset.url, n = []; - a.forEach(function(t) { - n.push(t.path); - }), wx.previewImage({ - urls: n, - current: e - }); -}), a(t, "viewVideo", function(t) { - var a = t.currentTarget.dataset.url; - wx.previewMedia({ - sources: [ { - url: a, - type: "video" - } ] - }); -}), a(t, "play", function(t) { - var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx, o = t.currentTarget.dataset.i, s = t.currentTarget.dataset.a, r = t.currentTarget.dataset.item; - console.log(a.data.isPlayAudio), a.data.isPlayAudio ? (a.data.dataList.forEach(function(t) { - t.list.forEach(function(t) { - t.list.forEach(function(t) { - "3" == t.dataType && t.valueList && t.valueList.forEach(function(t) { - t.isPlay = !1, t.curDuration = 0, t.curDuationStr = "00:00"; - }); - }); - }); - }), a.setData({ - dataList: a.data.dataList - }), n.stop(), a.data.audioId != r.id && (wx.showLoading({ - title: "加载中..." - }), setTimeout(function() { - wx.hideLoading({}), n.src = a.data.dataList[e].list[i].list[o].valueList[s].path + ".mp3", - n.startTime = 0, n.autoplay = !0, a.data.dataList[e].list[i].list[o].valueList[s].isPlay = !0, - a.setData({ - dataList: a.data.dataList, - isPlayAudio: !0, - audioId: r.id - }); - }, 1500))) : (n.src = a.data.dataList[e].list[i].list[o].valueList[s].path + ".mp3", - n.startTime = 0, n.autoplay = !0, n.play(), a.data.dataList[e].list[i].list[o].valueList[s].isPlay = !0, - a.setData({ - dataList: a.data.dataList, - isPlayAudio: !0, - audioId: r.id - })), n.onPlay(function() {}), n.onCanplay(function(t) {}), n.onStop(function(t) { - console.log("onStop==="), a.data.dataList[e].list[i].list[o].valueList[s].isPlay = !1, - a.data.dataList[e].list[i].list[o].valueList[s].curDuration = 0, a.data.dataList[e].list[i].list[o].valueList[s].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList, - isPlayAudio: !1 - }); - }), n.onEnded(function(t) { - console.log(t), console.log("播放完毕"), a.data.dataList[e].list[i].list[o].valueList[s].isPlay = !1, - a.data.dataList[e].list[i].list[o].valueList[s].curDuration = 0, a.data.dataList[e].list[i].list[o].valueList[s].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList, - isPlayAudio: !1 - }); - }), n.onError(function(t) { - console.log("播放错误"), console.log(t), a.data.dataList[e].list[i].list[o].valueList[s].isPlay = !1, - a.data.dataList[e].list[i].list[o].valueList[s].curDuration = 0, a.data.dataList[e].list[i].list[o].valueList[s].curDurationStr = "00:00", - a.setData({ - dataList: a.data.dataList, - isPlayAudio: !1 - }); - }), n.onSeeking(function() {}); -}), a(t, "goList", function() { - wx.navigateTo({ - url: "/packagecard/cardList/cardList" - }); -}), a(t, "showMore", function(t) { - var a = t.currentTarget.dataset.item; - if ("2" == a.mode) { - var e = t.currentTarget.dataset.userid, n = t.currentTarget.dataset.idx; + + innerAudioContext.onCanplay((res) => {}) + innerAudioContext.onStop((res) => { + console.log('onStop===') + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + isPlayAudio: false + }) + }) + innerAudioContext.onEnded((res) => { + console.log(res) + console.log('播放完毕') + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + isPlayAudio: false + }) + }) + innerAudioContext.onError((res) => { + console.log('播放错误') + console.log(res) + _self.data.dataList[index].list[idx].list[ix].valueList[a].isPlay = false + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDuration = 0 + _self.data.dataList[index].list[idx].list[ix].valueList[a].curDurationStr = '00:00' + _self.setData({ + dataList: _self.data.dataList, + isPlayAudio: false + }) + }) + innerAudioContext.onSeeking(() => { + // console.log(innerAudioContext.currentTime) + }) + }, + + // 跳转模板列表 + goList: function () { wx.navigateTo({ - url: "/packagecard/moments/showlist/showlist?id=" + a.cId + "&userId=" + e + "&index=" + n - }); - } -}), a(t, "showComment", function(t) { - var a = t.currentTarget.dataset.cid, e = t.currentTarget.dataset.uid, n = t.currentTarget.dataset.like, i = "&collectSwitch=" + t.currentTarget.dataset.collect + "&likeSwitch=" + n + "&commentSwitch=" + t.currentTarget.dataset.comment + "&shareSwitch=" + t.currentTarget.dataset.share; - console.log(i), wx.navigateTo({ - url: "/packagecard/moments/momentsdetail/momentsdetail?uId=" + e + "&cId=" + a + i - }); -}), a(t, "doLike", function(t) { - var a = this, n = t.currentTarget.dataset.item, i = t.currentTarget.dataset.idx, o = t.currentTarget.dataset.index, s = ""; - s = n.likeStatus ? "取消中..." : "保存中...", wx.showLoading({ - title: s - }), e.http.post(e.urls.doSaveLike, { - header: { - token: e.globalData.token - }, - data: { - businessId: n.uid, - projectId: "column" + url: '/packagecard/cardList/cardList', + }) + }, + //显示更多栏目数据 + showMore(e) { + var item = e.currentTarget.dataset.item + if (item.mode == '2') { + var userid = e.currentTarget.dataset.userid + var idx = e.currentTarget.dataset.idx + wx.navigateTo({ + url: '/packagecard/moments/showlist/showlist?id=' + item.cId + '&userId=' + userid + '&index=' + idx, + }) } - }).then(function(t) { - wx.hideLoading({}), a.data.dataList[o].list[i].likeStatus = !n.likeStatus, n.likeStatus ? --a.data.dataList[o].list[i].likeCount : ++a.data.dataList[o].list[i].likeCount, - a.setData({ - dataList: a.data.dataList - }); - }).catch(function(t) {}); -}), a(t, "doCollect", function(t) { - var a = this, n = t.currentTarget.dataset.item, i = t.currentTarget.dataset.idx, o = t.currentTarget.dataset.index, s = ""; - s = n.collectStatus ? "取消收藏..." : "收藏中...", wx.showLoading({ - title: s - }), e.http.post(e.urls.doSaveCollect, { - header: { - token: e.globalData.token - }, - data: { - businessId: n.uid, - projectId: "column" - } - }).then(function(t) { - wx.hideLoading({}), a.data.dataList[o].list[i].collectStatus = !n.collectStatus, - a.setData({ - dataList: a.data.dataList - }); - }).catch(function(t) {}); -}), t)); \ No newline at end of file + }, +}) \ No newline at end of file diff --git a/pages/neighbor/help/helpList.js b/pages/neighbor/help/helpList.js index dddc186..70668e8 100644 --- a/pages/neighbor/help/helpList.js +++ b/pages/neighbor/help/helpList.js @@ -1,63 +1,63 @@ -var e = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp(); +var t = getApp(); Page({ - data: { - token: t.globalData.token, - helpList: [], - page: { - page: 1, - rows: 10, - communityId: "" - }, - haveMore: !0, - serviceUrl: t.baseUrls.serviceUrl, - baseImgUrl: t.baseUrls.baseImgUrl + data: { + token: t.globalData.token, + helpList: [], + page: { + page: 1, + rows: 10, + communityId: "" }, - getHelpList: function() { - var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getHelpList, [ t.baseUrls.requestUrl ]), a.data.page, { - headers: { - token: t.globalData.token - } - }, function(t, o) { - for (var s = 0; s < o.rows.length; s++) o.rows[s].photo && (o.rows[s].photo = o.rows[s].photo.split(",")); - if (1 == a.data.page.page) a.setData({ - helpList: o.rows - }); else if (o.rows.length > 0) { - for (var n = a.data.helpList, r = 0; r < o.rows.length; r++) n.push(o.rows[r]); - a.setData({ - helpList: n - }); - } else wx.showToast({ - title: "暂无更多", - icon: "none" - }), a.setData(e({}, "page.page", a.data.page.page - 1)); - o.rows.length < 10 && a.setData({ - haveMore: !1 - }); - }, function(e, t) { - console.log(t); + haveMore: !0, + serviceUrl: t.baseUrls.serviceUrl, + baseImgUrl: t.baseUrls.baseImgUrl + }, + getHelpList: function () { + var a = this; + t.restAjax.get(t.restAjax.path(t.apis.getHelpList, [t.baseUrls.requestUrl]), a.data.page, { + headers: { + token: t.globalData.token + } + }, function (t, o) { + for (var s = 0; s < o.rows.length; s++) o.rows[s].photo && (o.rows[s].photo = o.rows[s].photo.split(",")); + if (1 == a.data.page.page) a.setData({ + helpList: o.rows + }); else if (o.rows.length > 0) { + for (var n = a.data.helpList, r = 0; r < o.rows.length; r++) n.push(o.rows[r]); + a.setData({ + helpList: n }); - }, - checkHelpDetail: function(e) { - var t = e.currentTarget.dataset.id; - wx.navigateTo({ - url: "./helpDetail?neighborId=" + t - }); - }, - loadMore: function() { - this.setData(e({}, "page.page", this.data.page.page + 1)), this.getHelpList(); - }, - onLoad: function(a) { - var o; - this.setData((e(o = {}, "page.communityId", a.communityId), e(o, "token", t.globalData.token), - o)), this.getHelpList(); - }, - onReady: function() {}, - onShow: function() {}, - onHide: function() {}, - onUnload: function() {}, - onPullDownRefresh: function() {}, - onReachBottom: function() {}, - onShareAppMessage: function() {} + } else wx.showToast({ + title: "暂无更多", + icon: "none" + }), a.setData(e({}, "page.page", a.data.page.page - 1)); + o.rows.length < 10 && a.setData({ + haveMore: !1 + }); + }, function (e, t) { + console.log(t); + }); + }, + checkHelpDetail: function (e) { + var t = e.currentTarget.dataset.id; + wx.navigateTo({ + url: "./helpDetail?neighborId=" + t + }); + }, + loadMore: function () { + this.setData(e({}, "page.page", this.data.page.page + 1)), this.getHelpList(); + }, + onLoad: function (a) { + var o; + this.setData((e(o = {}, "page.communityId", a.communityId), e(o, "token", t.globalData.token), + o)), this.getHelpList(); + }, + onReady: function () { }, + onShow: function () { }, + onHide: function () { }, + onUnload: function () { }, + onPullDownRefresh: function () { }, + onReachBottom: function () { }, + onShareAppMessage: function () { } }); \ No newline at end of file diff --git a/pages/neighbor/neighbor.js b/pages/neighbor/neighbor.js index 5f5dfda..3cc25de 100644 --- a/pages/neighbor/neighbor.js +++ b/pages/neighbor/neighbor.js @@ -1,4 +1,4 @@ -var t = require("../../@babel/runtime/helpers/defineProperty"), e = getApp(); +var e = getApp(); Page({ data: { diff --git a/pages/news/newsList.js b/pages/news/newsList.js index 8dbcdcf..e7cc00a 100644 --- a/pages/news/newsList.js +++ b/pages/news/newsList.js @@ -1,4 +1,4 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), t = getApp(); +var t = getApp(); Page({ data: { @@ -16,71 +16,86 @@ Page({ serviceUrl: t.baseUrls.serviceUrl, baseImgUrl: t.baseUrls.baseImgUrl }, - getNewsType: function() { + getNewsType: function () { var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [ t.baseUrls.requestUrl ]), { + t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [t.baseUrls.requestUrl]), { showArea: "6dcbb862-4b48-4dca-aee1-d78fd76adc05" }, { headers: { token: a.data.token } - }, function(t, s) { + }, function (t, s) { var n; - a.setData((e(n = { - newsType: s - }, "page.newsTypeId", s[0].newsTypeId), e(n, "curType", s[0].newsTypeId), n)), a.getNewsList(); - }, function(e, t) { + a.setData({ + newsType: s, + "page.newsTypeId": s[0].newsTypeId, + "curType": s[0].newsTypeId + }); + a.getNewsList(); + }, function (e, t) { console.log(t); }); }, - changeType: function(t) { + changeType: function (t) { var a, s = t.currentTarget.dataset.id; - this.setData((e(a = { - curType: s - }, "page.newsTypeId", s), e(a, "page.page", 1), a)), this.getNewsList(); + this.setData({ + curType: s, + "page.newsTypeId": s, + "page.page": 1, + }); + this.getNewsList(); }, - getNewsList: function() { + getNewsList: function () { var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [ t.baseUrls.requestUrl ]), a.data.page, { + t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [t.baseUrls.requestUrl]), a.data.page, { headers: { token: a.data.token } - }, function(t, s) { - for (var n = 0; n < s.rows.length; n++) s.rows[n].photo && (s.rows[n].photo = s.rows[n].photo.split(",")); - if (1 == a.data.page.page) a.setData({ - newsList: s.rows - }); else if (s.rows.length > 0) { + }, function (t, s) { + for (var n = 0; n < s.rows.length; n++) { + s.rows[n].photo && (s.rows[n].photo = s.rows[n].photo.split(",")); + } + if(1==a.data.page.page){ + a.setData({ + newsList:s.rows + }) + }else if(s.rows.length>0){ for (var o = a.data.newsList, r = 0; r < s.rows.length; r++) o.push(s.rows[r]); a.setData({ newsList: o }); - } else wx.showToast({ - title: "暂无更多", - icon: "none" - }), a.setData(e({}, "page.page", a.data.page.page - 1)); - }, function(e, t) { + }else{ + wx.showToast({ + title: '暂无更多', + icon:'none' + }) + a.setData({ + "page.page":a.data.page.page-1 + }) + } + }, function (e, t) { console.log(t); }); }, - checkDetail: function(e) { + checkDetail: function (e) { var t = e.currentTarget.dataset.id; wx.navigateTo({ url: "./newsDetail?newsId=" + t }); }, - onLoad: function(a) { - this.setData(e({ - token: t.globalData.token - }, "page.areaCode", wx.getStorageSync("areaCode") ? wx.getStorageSync("areaCode") : "")), + onLoad: function (a) { + this.setData({ + token: t.globalData.token, + "page.areaCode": wx.getStorageSync("areaCode") ? wx.getStorageSync("areaCode") : "" + }) this.getNewsType(); }, - onReady: function() {}, - onShow: function() {}, - onHide: function() {}, - onUnload: function() {}, - onPullDownRefresh: function() {}, - onReachBottom: function() { - this.setData(e({}, "page.page", this.data.page.page + 1)), this.getNewsList(); + + onReachBottom: function () { + this.setData({ + "page.page": this.data.page.page + 1, + + }); + this.getNewsList(); }, - onShareAppMessage: function() {} }); \ No newline at end of file diff --git a/pages/report/report.json b/pages/report/report.json index b54f60f..0ba001b 100644 --- a/pages/report/report.json +++ b/pages/report/report.json @@ -21,5 +21,5 @@ "van-collapse": "/vant/dist/collapse/index", "van-collapse-item": "/vant/dist/collapse-item/index" }, - "navigationBarTitleText": "事件上报" + "navigationBarTitleText": "述求上报" } \ No newline at end of file diff --git a/pages/serve/newsList.js b/pages/serve/newsList.js index 1d49d44..77314c1 100644 --- a/pages/serve/newsList.js +++ b/pages/serve/newsList.js @@ -1,83 +1,89 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), t = getApp(); +var t = getApp(); Page({ - data: { - token: t.globalData.token, - newsType: [], - curType: "", - page: { - page: 1, - rows: 10, - newsTypeId: "" - }, - newsList: [], - serviceUrl: t.baseUrls.serviceUrl, - baseImgUrl: t.baseUrls.baseImgUrl + data: { + token: t.globalData.token, + newsType: [], + curType: "", + page: { + page: 1, + rows: 10, + newsTypeId: "" }, - getNewsType: function() { - var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [ t.baseUrls.requestUrl ]), { - showArea: "6dcbb862-4b48-4dca-aee1-d78fd76adc05" - }, { - headers: { - token: a.data.token - } - }, function(t, s) { - var n; - a.setData((e(n = { - newsType: s - }, "page.newsTypeId", s[0].newsTypeId), e(n, "curType", s[0].newsTypeId), n)), a.getNewsList(); - }, function(e, t) { - console.log(t); + newsList: [], + serviceUrl: t.baseUrls.serviceUrl, + baseImgUrl: t.baseUrls.baseImgUrl + }, + getNewsType: function () { + var a = this; + t.restAjax.get(t.restAjax.path(t.apis.getNewsType, [t.baseUrls.requestUrl]), { + showArea: "6dcbb862-4b48-4dca-aee1-d78fd76adc05" + }, { + headers: { + token: a.data.token + } + }, function (t, s) { + var n; + a.setData({ + newsType: s, + "page.newsTypeId": s[0].newsTypeId, + "curType": s[0].newsTypeId + }); + a.getNewsList(); + }, function (e, t) { + console.log(t); + }); + }, + changeType: function (t) { + var a, s = t.currentTarget.dataset.id; + this.setData({ + curType: s, + "page.newsTypeId": s, + "page.page": 1 + }); + this.getNewsList(); + }, + getNewsList: function () { + var a = this; + t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [t.baseUrls.requestUrl]), a.data.page, { + headers: { + token: a.data.token + } + }, function (t, s) { + for (var n = 0; n < s.rows.length; n++) s.rows[n].photo && (s.rows[n].photo = s.rows[n].photo.split(",")); + if (1 == a.data.page.page) a.setData({ + newsList: s.rows + }); else if (s.rows.length > 0) { + for (var o = a.data.newsList, r = 0; r < s.rows.length; r++) o.push(s.rows[r]); + a.setData({ + newsList: o }); - }, - changeType: function(t) { - var a, s = t.currentTarget.dataset.id; - this.setData((e(a = { - curType: s - }, "page.newsTypeId", s), e(a, "page.page", 1), a)), this.getNewsList(); - }, - getNewsList: function() { - var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getNewsList, [ t.baseUrls.requestUrl ]), a.data.page, { - headers: { - token: a.data.token - } - }, function(t, s) { - for (var n = 0; n < s.rows.length; n++) s.rows[n].photo && (s.rows[n].photo = s.rows[n].photo.split(",")); - if (1 == a.data.page.page) a.setData({ - newsList: s.rows - }); else if (s.rows.length > 0) { - for (var o = a.data.newsList, r = 0; r < s.rows.length; r++) o.push(s.rows[r]); - a.setData({ - newsList: o - }); - } else wx.showToast({ - title: "暂无更多", - icon: "none" - }), a.setData(e({}, "page.page", a.data.page.page - 1)); - }, function(e, t) { - console.log(t); - }); - }, - checkDetail: function(e) { - var t = e.currentTarget.dataset.id; - wx.navigateTo({ - url: "../news/newsDetail?newsId=" + t - }); - }, - onLoad: function(e) { - this.setData({ - token: t.globalData.token - }), this.getNewsType(); - }, - onReady: function() {}, - onShow: function() {}, - onHide: function() {}, - onUnload: function() {}, - onPullDownRefresh: function() {}, - onReachBottom: function() { - this.setData(e({}, "page.page", this.data.page.page + 1)), this.getNewsList(); - }, - onShareAppMessage: function() {} + } else wx.showToast({ + title: "暂无更多", + icon: "none" + }), a.setData(e({}, "page.page", a.data.page.page - 1)); + }, function (e, t) { + console.log(t); + }); + }, + checkDetail: function (e) { + var t = e.currentTarget.dataset.id; + wx.navigateTo({ + url: "../news/newsDetail?newsId=" + t + }); + }, + onLoad: function (e) { + this.setData({ + token: t.globalData.token + }), this.getNewsType(); + }, + onReady: function () { }, + onShow: function () { }, + onHide: function () { }, + onUnload: function () { }, + onPullDownRefresh: function () { }, + onReachBottom: function () { + this.setData(e({}, "page.page", this.data.page.page + 1)), this.getNewsList(); + }, + onShareAppMessage: function () { } }); \ No newline at end of file diff --git a/pages/talk/talk.js b/pages/talk/talk.js index db470db..a7ce715 100644 --- a/pages/talk/talk.js +++ b/pages/talk/talk.js @@ -1,94 +1,94 @@ -var e = require("../../@babel/runtime/helpers/defineProperty"), t = getApp(); +var t = getApp(); Page({ - data: { - token: t.globalData.token, - sourceUrl: t.baseUrls.sourceUrl, - page: { - page: 1, - rows: 5 - }, - talkList: [], - serviceUrl: t.baseUrls.serviceUrl, - baseImgUrl: t.baseUrls.baseImgUrl, + data: { + token: t.globalData.token, + sourceUrl: t.baseUrls.sourceUrl, + page: { + page: 1, + rows: 5 + }, + talkList: [], + serviceUrl: t.baseUrls.serviceUrl, + baseImgUrl: t.baseUrls.baseImgUrl, + isShowMenu: !1 + }, + getTalkList: function () { + var a = this; + t.restAjax.get(t.restAjax.path(t.apis.getTalkList, [t.baseUrls.requestUrl]), { + pages: a.data.page, + areaCode: wx.getStorageSync("areaCode") + }, { + headers: { + token: t.globalData.token + } + }, function (t, o) { + if (o.rows.length > 0) { + for (var s = 0; s < o.rows.length; s++) o.rows[s].photo && (o.rows[s].photo = o.rows[s].photo.split(",")); + if (1 == a.data.page.page) a.setData({ + talkList: o.rows + }); else { + for (var n = a.data.talkList, l = 0; l < o.rows.length; l++) n.push(o.rows[l]); + a.setData({ + talkList: n + }); + } + } else wx.showToast({ + title: "暂无更多", + icon: "none" + }), a.data.page.page > 1 && a.setData(e({}, "page.page", a.data.page.page - 1)); + }, function (e, t) { + console.log(t); + }); + }, + newTalk: function () { + wx.navigateTo({ + url: "./newTalk" + }); + }, + checkMyTalk: function () { + wx.navigateTo({ + url: "./myTalk" + }); + }, + checkDetail: function (e) { + var t = e.currentTarget.dataset.id; + wx.navigateTo({ + url: "./talkDetail?trifleMyselfId=" + t + }); + }, + clickVideo: function () { }, + onLoad: function (e) { }, + getMenuIsShow: function () { + var e = this; + t.restAjax.get(t.restAjax.path(t.apis.getBtnIsShow, [t.baseUrls.requestUrl, "talk"]), null, { + headers: { + token: t.globalData.token + } + }, function (t, a) { + null != a && null != a ? e.setData({ + isShowMenu: 1 == a.isShow + }) : e.setData({ isShowMenu: !1 - }, - getTalkList: function() { - var a = this; - t.restAjax.get(t.restAjax.path(t.apis.getTalkList, [ t.baseUrls.requestUrl ]), { - pages: a.data.page, - areaCode: wx.getStorageSync("areaCode") - }, { - headers: { - token: t.globalData.token - } - }, function(t, o) { - if (o.rows.length > 0) { - for (var s = 0; s < o.rows.length; s++) o.rows[s].photo && (o.rows[s].photo = o.rows[s].photo.split(",")); - if (1 == a.data.page.page) a.setData({ - talkList: o.rows - }); else { - for (var n = a.data.talkList, l = 0; l < o.rows.length; l++) n.push(o.rows[l]); - a.setData({ - talkList: n - }); - } - } else wx.showToast({ - title: "暂无更多", - icon: "none" - }), a.data.page.page > 1 && a.setData(e({}, "page.page", a.data.page.page - 1)); - }, function(e, t) { - console.log(t); - }); - }, - newTalk: function() { - wx.navigateTo({ - url: "./newTalk" - }); - }, - checkMyTalk: function() { - wx.navigateTo({ - url: "./myTalk" - }); - }, - checkDetail: function(e) { - var t = e.currentTarget.dataset.id; - wx.navigateTo({ - url: "./talkDetail?trifleMyselfId=" + t - }); - }, - clickVideo: function() {}, - onLoad: function(e) {}, - getMenuIsShow: function() { - var e = this; - t.restAjax.get(t.restAjax.path(t.apis.getBtnIsShow, [ t.baseUrls.requestUrl, "talk" ]), null, { - headers: { - token: t.globalData.token - } - }, function(t, a) { - null != a && null != a ? e.setData({ - isShowMenu: 1 == a.isShow - }) : e.setData({ - isShowMenu: !1 - }); - }, function(t, a) { - e.setData({ - isShowMenu: !1 - }); - }); - }, - onReady: function() {}, - onShow: function() { - this.setData({ - token: t.globalData.token - }), this.getTalkList(), this.getMenuIsShow(); - }, - onHide: function() {}, - onUnload: function() {}, - onPullDownRefresh: function() {}, - onReachBottom: function() { - var t = this.data.page.page + 1; - this.setData(e({}, "page.page", t)), this.getTalkList(); - }, - onShareAppMessage: function() {} + }); + }, function (t, a) { + e.setData({ + isShowMenu: !1 + }); + }); + }, + onReady: function () { }, + onShow: function () { + this.setData({ + token: t.globalData.token + }), this.getTalkList(), this.getMenuIsShow(); + }, + onHide: function () { }, + onUnload: function () { }, + onPullDownRefresh: function () { }, + onReachBottom: function () { + var t = this.data.page.page + 1; + this.setData(e({}, "page.page", t)), this.getTalkList(); + }, + onShareAppMessage: function () { } }); \ No newline at end of file diff --git a/project.config.json b/project.config.json index 9235c0a..543fd09 100644 --- a/project.config.json +++ b/project.config.json @@ -1,29 +1,30 @@ { - "appid": "wxa5e5552f8a3b1616", - "compileType": "miniprogram", - "libVersion": "2.31.1", - "packOptions": { - "ignore": [], - "include": [] - }, - "setting": { - "coverView": true, - "es6": true, - "postcss": true, - "minified": true, - "enhance": true, - "showShadowRootInWxmlPanel": true, - "packNpmRelationList": [], - "babelSetting": { - "ignore": [], - "disablePlugins": [], - "outputPath": "" + "compileType": "miniprogram", + "setting": { + "coverView": true, + "es6": true, + "postcss": true, + "minified": true, + "enhance": true, + "showShadowRootInWxmlPanel": true, + "packNpmRelationList": [], + "babelSetting": { + "ignore": [], + "disablePlugins": [], + "outputPath": "" + }, + "condition": false, + "ignoreUploadUnusedFiles": true }, - "condition": false - }, - "condition": {}, - "editorSetting": { - "tabIndent": "insertSpaces", - "tabSize": 2 - } + "condition": {}, + "editorSetting": { + "tabIndent": "insertSpaces", + "tabSize": 4 + }, + "libVersion": "2.31.1", + "packOptions": { + "ignore": [], + "include": [] + }, + "appid": "wxa5e5552f8a3b1616" } \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json index 200ac2c..41f0cc0 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -1,8 +1,8 @@ { - "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", - "projectname": "city_card", - "setting": { - "compileHotReLoad": true, - "urlCheck": false - } + "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", + "projectname": "city_card", + "setting": { + "compileHotReLoad": true, + "urlCheck": false + } } \ No newline at end of file diff --git a/utils/api.js b/utils/api.js index 807bb19..7f7b6e7 100644 --- a/utils/api.js +++ b/utils/api.js @@ -6,10 +6,12 @@ var baseUrls = { caseUrl: "https://www.wlcbsyzl.cn/case/", sourceUrl: "https://www.wlcbsyzl.cn/systemmunicipalmini/assets/weCharMiniFile/images/", baseCardUrl: "https://www.wlcbsyzl.cn/citycard/route/file/download/true/", + // baseCardUrl: "http://192.168.0.115:8089/citycard/route/file/download/true/", url: "https://www.wlcbsyzl.cn/citycard/" + // url: "http://192.168.0.115:8089/citycard/" } - + var apis = { diff --git a/utils/request.js b/utils/request.js index 194819b..1d13b3c 100644 --- a/utils/request.js +++ b/utils/request.js @@ -266,6 +266,7 @@ function upload(url, params) { } }, fail: function (response) { + console.log(response) wx.hideLoading({}) try { if (typeof (response.data.msg) != undefined) { diff --git a/vant/dist/cropper/image-cropper.js b/vant/dist/cropper/image-cropper.js new file mode 100755 index 0000000..401d2af --- /dev/null +++ b/vant/dist/cropper/image-cropper.js @@ -0,0 +1,1117 @@ +Component({ + properties: { + /** + * 图片路径 + */ + 'imgSrc': { + type: String + }, + /** + * 裁剪框高度 + */ + 'height': { + type: Number, + value: 200 + }, + /** + * 裁剪框宽度 + */ + 'width': { + type: Number, + value: 200 + }, + /** + * 裁剪框最小尺寸 + */ + 'min_width': { + type: Number, + value: 100 + }, + 'min_height': { + type: Number, + value: 100 + }, + /** + * 裁剪框最大尺寸 + */ + 'max_width': { + type: Number, + value: 300 + }, + 'max_height': { + type: Number, + value: 300 + }, + /** + * 裁剪框禁止拖动 + */ + 'disable_width': { + type: Boolean, + value: false + }, + 'disable_height': { + type: Boolean, + value: false + }, + /** + * 锁定裁剪框比例 + */ + 'disable_ratio': { + type: Boolean, + value: false + }, + /** + * 生成的图片尺寸相对剪裁框的比例 + */ + 'export_scale': { + type: Number, + value: 3 + }, + /** + * 生成的图片质量0-1 + */ + 'quality': { + type: Number, + value: 1 + }, + 'cut_top': { + type: Number, + value: null + }, + 'cut_left': { + type: Number, + value: null + }, + /** + * canvas上边距(不设置默认不显示) + */ + 'canvas_top': { + type: Number, + value: null + }, + /** + * canvas左边距(不设置默认不显示) + */ + 'canvas_left': { + type: Number, + value: null + }, + /** + * 图片宽度 + */ + 'img_width': { + type: null, + value: null + }, + /** + * 图片高度 + */ + 'img_height': { + type: null, + value: null + }, + /** + * 图片缩放比 + */ + 'scale': { + type: Number, + value: 1 + }, + /** + * 图片旋转角度 + */ + 'angle': { + type: Number, + value: 0 + }, + /** + * 最小缩放比 + */ + 'min_scale': { + type: Number, + value: 0.5 + }, + /** + * 最大缩放比 + */ + 'max_scale': { + type: Number, + value: 2 + }, + /** + * 是否禁用旋转 + */ + 'disable_rotate': { + type: Boolean, + value: false + }, + /** + * 是否限制移动范围(剪裁框只能在图片内) + */ + 'limit_move': { + type: Boolean, + value: false + } + }, + data: { + el: 'image-cropper', //暂时无用 + info: wx.getSystemInfoSync(), + MOVE_THROTTLE: null, //触摸移动节流settimeout + MOVE_THROTTLE_FLAG: true, //节流标识 + INIT_IMGWIDTH: 0, //图片设置尺寸,此值不变(记录最初设定的尺寸) + INIT_IMGHEIGHT: 0, //图片设置尺寸,此值不变(记录最初设定的尺寸) + TIME_BG: null, //背景变暗延时函数 + TIME_CUT_CENTER: null, + _touch_img_relative: [{ + x: 0, + y: 0 + }], //鼠标和图片中心的相对位置 + _flag_cut_touch: false, //是否是拖动裁剪框 + _hypotenuse_length: 0, //双指触摸时斜边长度 + _flag_img_endtouch: false, //是否结束触摸 + _flag_bright: true, //背景是否亮 + _canvas_overflow: true, //canvas缩略图是否在屏幕外面 + _canvas_width: 200, + _canvas_height: 200, + origin_x: 0.5, //图片旋转中心 + origin_y: 0.5, //图片旋转中心 + _cut_animation: false, //是否开启图片和裁剪框过渡 + _img_top: wx.getSystemInfoSync().windowHeight / 2, //图片上边距 + _img_left: wx.getSystemInfoSync().windowWidth / 2, //图片左边距 + watch: { + //监听截取框宽高变化 + width(value, that) { + if (value < that.data.min_width) { + that.setData({ + width: that.data.min_width + }); + } + that._computeCutSize(); + }, + height(value, that) { + if (value < that.data.min_height) { + that.setData({ + height: that.data.min_height + }); + } + that._computeCutSize(); + }, + angle(value, that) { + //停止居中裁剪框,继续修改图片位置 + that._moveStop(); + if (that.data.limit_move) { + if (that.data.angle % 90) { + that.setData({ + angle: Math.round(that.data.angle / 90) * 90 + }); + return; + } + } + }, + _cut_animation(value, that) { + //开启过渡300毫秒之后自动关闭 + clearTimeout(that.data._cut_animation_time); + if (value) { + that.data._cut_animation_time = setTimeout(() => { + that.setData({ + _cut_animation: false + }); + }, 300) + } + }, + limit_move(value, that) { + if (value) { + if (that.data.angle % 90) { + that.setData({ + angle: Math.round(that.data.angle / 90) * 90 + }); + } + that._imgMarginDetectionScale(); + !that.data._canvas_overflow && that._draw(); + } + }, + canvas_top(value, that) { + that._canvasDetectionPosition(); + }, + canvas_left(value, that) { + that._canvasDetectionPosition(); + }, + imgSrc(value, that) { + that.pushImg(); + }, + cut_top(value, that) { + that._cutDetectionPosition(); + if (that.data.limit_move) { + !that.data._canvas_overflow && that._draw(); + } + }, + cut_left(value, that) { + that._cutDetectionPosition(); + if (that.data.limit_move) { + !that.data._canvas_overflow && that._draw(); + } + } + } + }, + attached() { + this.data.info = wx.getSystemInfoSync(); + //启用数据监听 + this._watcher(); + this.data.INIT_IMGWIDTH = this.data.img_width; + this.data.INIT_IMGHEIGHT = this.data.img_height; + this.setData({ + _canvas_height: this.data.height, + _canvas_width: this.data.width, + }); + this._initCanvas(); + this.data.imgSrc && (this.data.imgSrc = this.data.imgSrc); + //根据开发者设置的图片目标尺寸计算实际尺寸 + this._initImageSize(); + //设置裁剪框大小>设置图片尺寸>绘制canvas + this._computeCutSize(); + //检查裁剪框是否在范围内 + this._cutDetectionPosition(); + //检查canvas是否在范围内 + this._canvasDetectionPosition(); + //初始化完成 + this.triggerEvent('load', { + cropper: this + }); + }, + methods: { + /** + * 上传图片 + */ + upload() { + let that = this; + wx.chooseImage({ + count: 1, + sizeType: ['original', 'compressed'], + sourceType: ['album', 'camera'], + success(res) { + const tempFilePaths = res.tempFilePaths[0]; + that.pushImg(tempFilePaths); + wx.showLoading({ + title: '加载中...' + }) + } + }) + }, + /** + * 返回图片信息 + */ + getImg(getCallback) { + this._draw(() => { + wx.canvasToTempFilePath({ + width: this.data.width * this.data.export_scale, + height: Math.round(this.data.height * this.data.export_scale), + destWidth: this.data.width * this.data.export_scale, + destHeight: Math.round(this.data.height) * this.data.export_scale, + fileType: 'png', + quality: this.data.quality, + canvasId: this.data.el, + success: (res) => { + getCallback({ + url: res.tempFilePath, + width: this.data.width * this.data.export_scale, + height: this.data.height * this.data.export_scale + }); + } + }, this) + }); + }, + /** + * 设置图片动画 + * { + * x:10,//图片在原有基础上向下移动10px + * y:10,//图片在原有基础上向右移动10px + * angle:10,//图片在原有基础上旋转10deg + * scale:0.5,//图片在原有基础上增加0.5倍 + * } + */ + setTransform(transform) { + if (!transform) return; + if (!this.data.disable_rotate) { + this.setData({ + angle: transform.angle ? this.data.angle + transform.angle : this.data.angle + }); + } + var scale = this.data.scale; + if (transform.scale) { + scale = this.data.scale + transform.scale; + scale = scale <= this.data.min_scale ? this.data.min_scale : scale; + scale = scale >= this.data.max_scale ? this.data.max_scale : scale; + } + this.data.scale = scale; + let cutX = this.data.cut_left; + let cutY = this.data.cut_top; + if (transform.cutX) { + this.setData({ + cut_left: cutX + transform.cutX + }); + this.data.watch.cut_left(null, this); + } + if (transform.cutY) { + this.setData({ + cut_top: cutY + transform.cutY + }); + this.data.watch.cut_top(null, this); + } + this.data._img_top = transform.y ? this.data._img_top + transform.y : this.data._img_top; + this.data._img_left = transform.x ? this.data._img_left + transform.x : this.data._img_left; + //图像边缘检测,防止截取到空白 + this._imgMarginDetectionScale(); + //停止居中裁剪框,继续修改图片位置 + this._moveDuring(); + this.setData({ + scale: this.data.scale, + _img_top: this.data._img_top, + _img_left: this.data._img_left + }); + !this.data._canvas_overflow && this._draw(); + //可以居中裁剪框了 + this._moveStop(); //结束操作 + }, + /** + * 设置剪裁框位置 + */ + setCutXY(x, y) { + this.setData({ + cut_top: y, + cut_left: x + }); + }, + /** + * 设置剪裁框尺寸 + */ + setCutSize(w, h) { + this.setData({ + width: w, + height: h + }); + this._computeCutSize(); + }, + /** + * 设置剪裁框和图片居中 + */ + setCutCenter() { + let cut_top = (this.data.info.windowHeight - this.data.height) * 0.5; + let cut_left = (this.data.info.windowWidth - this.data.width) * 0.5; + //顺序不能变 + this.setData({ + _img_top: this.data._img_top - this.data.cut_top + cut_top, + cut_top: cut_top, //截取的框上边距 + _img_left: this.data._img_left - this.data.cut_left + cut_left, + cut_left: cut_left, //截取的框左边距 + }); + }, + _setCutCenter() { + let cut_top = (this.data.info.windowHeight - this.data.height) * 0.5; + let cut_left = (this.data.info.windowWidth - this.data.width) * 0.5; + this.setData({ + cut_top: cut_top, //截取的框上边距 + cut_left: cut_left, //截取的框左边距 + }); + }, + /** + * 设置剪裁框宽度-即将废弃 + */ + setWidth(width) { + this.setData({ + width: width + }); + this._computeCutSize(); + }, + /** + * 设置剪裁框高度-即将废弃 + */ + setHeight(height) { + this.setData({ + height: height + }); + this._computeCutSize(); + }, + /** + * 是否锁定旋转 + */ + setDisableRotate(value) { + this.data.disable_rotate = value; + }, + /** + * 是否限制移动 + */ + setLimitMove(value) { + this.setData({ + _cut_animation: true, + limit_move: !!value + }); + }, + /** + * 初始化图片,包括位置、大小、旋转角度 + */ + imgReset() { + this.setData({ + scale: 1, + angle: 0, + _img_top: wx.getSystemInfoSync().windowHeight / 2, + _img_left: wx.getSystemInfoSync().windowWidth / 2, + }) + }, + /** + * 加载(更换)图片 + */ + pushImg(src) { + if (src) { + this.setData({ + imgSrc: src + }); + //发现是手动赋值直接返回,交给watch处理 + return; + } + + // getImageInfo接口传入 src: '' 会导致内存泄漏 + + if (!this.data.imgSrc) return; + wx.getImageInfo({ + src: this.data.imgSrc, + success: (res) => { + this.data.imageObject = res; + //图片非本地路径需要换成本地路径 + if (this.data.imgSrc.search(/tmp/) == -1) { + this.setData({ + imgSrc: res.path + }); + } + //计算最后图片尺寸 + this._imgComputeSize(); + if (this.data.limit_move) { + //限制移动,不留空白处理 + this._imgMarginDetectionScale(); + } + this._draw(); + }, + fail: (err) => { + this.setData({ + imgSrc: '' + }); + } + }); + }, + imageLoad(e) { + setTimeout(() => { + this.triggerEvent('imageload', this.data.imageObject); + + }) + }, + /** + * 设置图片放大缩小 + */ + setScale(scale) { + if (!scale) return; + this.setData({ + scale: scale + }); + !this.data._canvas_overflow && this._draw(); + }, + /** + * 设置图片旋转角度 + */ + setAngle(angle) { + if (!angle) return; + this.setData({ + _cut_animation: true, + angle: angle + }); + this._imgMarginDetectionScale(); + !this.data._canvas_overflow && this._draw(); + }, + _initCanvas() { + //初始化canvas + if (!this.data.ctx) { + this.data.ctx = wx.createCanvasContext("image-cropper", this); + } + }, + /** + * 根据开发者设置的图片目标尺寸计算实际尺寸 + */ + _initImageSize() { + //处理宽高特殊单位 %>px + if (this.data.INIT_IMGWIDTH && typeof this.data.INIT_IMGWIDTH == "string" && this.data.INIT_IMGWIDTH.indexOf("%") != -1) { + let width = this.data.INIT_IMGWIDTH.replace("%", ""); + this.data.INIT_IMGWIDTH = this.data.img_width = this.data.info.windowWidth / 100 * width; + } + if (this.data.INIT_IMGHEIGHT && typeof this.data.INIT_IMGHEIGHT == "string" && this.data.INIT_IMGHEIGHT.indexOf("%") != -1) { + let height = this.data.img_height.replace("%", ""); + this.data.INIT_IMGHEIGHT = this.data.img_height = this.data.info.windowHeight / 100 * height; + } + }, + /** + * 检测剪裁框位置是否在允许的范围内(屏幕内) + */ + _cutDetectionPosition() { + let _cutDetectionPositionTop = () => { + //检测上边距是否在范围内 + if (this.data.cut_top < 0) { + this.setData({ + cut_top: 0 + }); + } + if (this.data.cut_top > this.data.info.windowHeight - this.data.height) { + this.setData({ + cut_top: this.data.info.windowHeight - this.data.height + }); + } + }, + _cutDetectionPositionLeft = () => { + //检测左边距是否在范围内 + if (this.data.cut_left < 0) { + this.setData({ + cut_left: 0 + }); + } + if (this.data.cut_left > this.data.info.windowWidth - this.data.width) { + this.setData({ + cut_left: this.data.info.windowWidth - this.data.width + }); + } + }; + //裁剪框坐标处理(如果只写一个参数则另一个默认为0,都不写默认居中) + if (this.data.cut_top == null && this.data.cut_left == null) { + this._setCutCenter(); + } else if (this.data.cut_top != null && this.data.cut_left != null) { + _cutDetectionPositionTop(); + _cutDetectionPositionLeft(); + } else if (this.data.cut_top != null && this.data.cut_left == null) { + _cutDetectionPositionTop(); + this.setData({ + cut_left: (this.data.info.windowWidth - this.data.width) / 2 + }); + } else if (this.data.cut_top == null && this.data.cut_left != null) { + _cutDetectionPositionLeft(); + this.setData({ + cut_top: (this.data.info.windowHeight - this.data.height) / 2 + }); + } + }, + /** + * 检测canvas位置是否在允许的范围内(屏幕内)如果在屏幕外则不开启实时渲染 + * 如果只写一个参数则另一个默认为0,都不写默认超出屏幕外 + */ + _canvasDetectionPosition() { + if (this.data.canvas_top == null && this.data.canvas_left == null) { + this.data._canvas_overflow = false; + this.setData({ + canvas_top: -5000, + canvas_left: -5000 + }); + } else if (this.data.canvas_top != null && this.data.canvas_left != null) { + if (this.data.canvas_top < -this.data.height || this.data.canvas_top > this.data.info.windowHeight) { + this.data._canvas_overflow = true; + } else { + this.data._canvas_overflow = false; + } + } else if (this.data.canvas_top != null && this.data.canvas_left == null) { + this.setData({ + canvas_left: 0 + }); + } else if (this.data.canvas_top == null && this.data.canvas_left != null) { + this.setData({ + canvas_top: 0 + }); + if (this.data.canvas_left < -this.data.width || this.data.canvas_left > this.data.info.windowWidth) { + this.data._canvas_overflow = true; + } else { + this.data._canvas_overflow = false; + } + } + }, + /** + * 图片边缘检测-位置 + */ + _imgMarginDetectionPosition(scale) { + if (!this.data.limit_move) return; + let left = this.data._img_left; + let top = this.data._img_top; + var scale = scale || this.data.scale; + let img_width = this.data.img_width; + let img_height = this.data.img_height; + if (this.data.angle / 90 % 2) { + img_width = this.data.img_height; + img_height = this.data.img_width; + } + left = this.data.cut_left + img_width * scale / 2 >= left ? left : this.data.cut_left + img_width * scale / 2; + left = this.data.cut_left + this.data.width - img_width * scale / 2 <= left ? left : this.data.cut_left + this.data.width - img_width * scale / 2; + top = this.data.cut_top + img_height * scale / 2 >= top ? top : this.data.cut_top + img_height * scale / 2; + top = this.data.cut_top + this.data.height - img_height * scale / 2 <= top ? top : this.data.cut_top + this.data.height - img_height * scale / 2; + this.setData({ + _img_left: left, + _img_top: top, + scale: scale + }) + }, + /** + * 图片边缘检测-缩放 + */ + _imgMarginDetectionScale() { + if (!this.data.limit_move) return; + let scale = this.data.scale; + let img_width = this.data.img_width; + let img_height = this.data.img_height; + if (this.data.angle / 90 % 2) { + img_width = this.data.img_height; + img_height = this.data.img_width; + } + if (img_width * scale < this.data.width) { + scale = this.data.width / img_width; + } + if (img_height * scale < this.data.height) { + scale = Math.max(scale, this.data.height / img_height); + } + this._imgMarginDetectionPosition(scale); + }, + _setData(obj) { + let data = {}; + for (var key in obj) { + if (this.data[key] != obj[key]) { + data[key] = obj[key]; + } + } + this.setData(data); + return data; + }, + /** + * 计算图片尺寸 + */ + _imgComputeSize() { + let img_width = this.data.img_width, + img_height = this.data.img_height; + if (!this.data.INIT_IMGHEIGHT && !this.data.INIT_IMGWIDTH) { + //默认按图片最小边 = 对应裁剪框尺寸 + img_width = this.data.imageObject.width; + img_height = this.data.imageObject.height; + if (img_width / img_height > this.data.width / this.data.height) { + img_height = this.data.height; + img_width = this.data.imageObject.width / this.data.imageObject.height * img_height; + } else { + img_width = this.data.width; + img_height = this.data.imageObject.height / this.data.imageObject.width * img_width; + } + } else if (this.data.INIT_IMGHEIGHT && !this.data.INIT_IMGWIDTH) { + img_width = this.data.imageObject.width / this.data.imageObject.height * this.data.INIT_IMGHEIGHT; + } else if (!this.data.INIT_IMGHEIGHT && this.data.INIT_IMGWIDTH) { + img_height = this.data.imageObject.height / this.data.imageObject.width * this.data.INIT_IMGWIDTH; + } + this.setData({ + img_width: img_width, + img_height: img_height + }); + }, + //改变截取框大小 + _computeCutSize() { + if (this.data.width > this.data.info.windowWidth) { + this.setData({ + width: this.data.info.windowWidth, + }); + } else if (this.data.width + this.data.cut_left > this.data.info.windowWidth) { + this.setData({ + cut_left: this.data.info.windowWidth - this.data.cut_left, + }); + }; + if (this.data.height > this.data.info.windowHeight) { + this.setData({ + height: this.data.info.windowHeight, + }); + } else if (this.data.height + this.data.cut_top > this.data.info.windowHeight) { + this.setData({ + cut_top: this.data.info.windowHeight - this.data.cut_top, + }); + }!this.data._canvas_overflow && this._draw(); + }, + //开始触摸 + _start(event) { + this.data._flag_img_endtouch = false; + if (event.touches.length == 1) { + //单指拖动 + this.data._touch_img_relative[0] = { + x: (event.touches[0].clientX - this.data._img_left), + y: (event.touches[0].clientY - this.data._img_top) + } + } else { + //双指放大 + let width = Math.abs(event.touches[0].clientX - event.touches[1].clientX); + let height = Math.abs(event.touches[0].clientY - event.touches[1].clientY); + this.data._touch_img_relative = [{ + x: (event.touches[0].clientX - this.data._img_left), + y: (event.touches[0].clientY - this.data._img_top) + }, { + x: (event.touches[1].clientX - this.data._img_left), + y: (event.touches[1].clientY - this.data._img_top) + }]; + this.data._hypotenuse_length = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); + }!this.data._canvas_overflow && this._draw(); + }, + _move_throttle() { + //安卓需要节流 + if (this.data.info.platform == 'android') { + clearTimeout(this.data.MOVE_THROTTLE); + this.data.MOVE_THROTTLE = setTimeout(() => { + this.data.MOVE_THROTTLE_FLAG = true; + }, 1000 / 40) + return this.data.MOVE_THROTTLE_FLAG; + } else { + this.data.MOVE_THROTTLE_FLAG = true; + } + }, + _move(event) { + if (this.data._flag_img_endtouch || !this.data.MOVE_THROTTLE_FLAG) return; + this.data.MOVE_THROTTLE_FLAG = false; + this._move_throttle(); + this._moveDuring(); + if (event.touches.length == 1) { + //单指拖动 + let left = (event.touches[0].clientX - this.data._touch_img_relative[0].x), + top = (event.touches[0].clientY - this.data._touch_img_relative[0].y); + //图像边缘检测,防止截取到空白 + this.data._img_left = left; + this.data._img_top = top; + this._imgMarginDetectionPosition(); + this.setData({ + _img_left: this.data._img_left, + _img_top: this.data._img_top + }); + } else { + //双指放大 + let width = (Math.abs(event.touches[0].clientX - event.touches[1].clientX)), + height = (Math.abs(event.touches[0].clientY - event.touches[1].clientY)), + hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)), + scale = this.data.scale * (hypotenuse / this.data._hypotenuse_length), + current_deg = 0; + scale = scale <= this.data.min_scale ? this.data.min_scale : scale; + scale = scale >= this.data.max_scale ? this.data.max_scale : scale; + //图像边缘检测,防止截取到空白 + this.data.scale = scale; + this._imgMarginDetectionScale(); + //双指旋转(如果没禁用旋转) + let _touch_img_relative = [{ + x: (event.touches[0].clientX - this.data._img_left), + y: (event.touches[0].clientY - this.data._img_top) + }, { + x: (event.touches[1].clientX - this.data._img_left), + y: (event.touches[1].clientY - this.data._img_top) + }]; + if (!this.data.disable_rotate) { + let first_atan = 180 / Math.PI * Math.atan2(_touch_img_relative[0].y, _touch_img_relative[0].x); + let first_atan_old = 180 / Math.PI * Math.atan2(this.data._touch_img_relative[0].y, this.data._touch_img_relative[0].x); + let second_atan = 180 / Math.PI * Math.atan2(_touch_img_relative[1].y, _touch_img_relative[1].x); + let second_atan_old = 180 / Math.PI * Math.atan2(this.data._touch_img_relative[1].y, this.data._touch_img_relative[1].x); + //当前旋转的角度 + let first_deg = first_atan - first_atan_old, + second_deg = second_atan - second_atan_old; + if (first_deg != 0) { + current_deg = first_deg; + } else if (second_deg != 0) { + current_deg = second_deg; + } + } + this.data._touch_img_relative = _touch_img_relative; + this.data._hypotenuse_length = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); + //更新视图 + this.setData({ + angle: this.data.angle + current_deg, + scale: this.data.scale + }); + }!this.data._canvas_overflow && this._draw(); + }, + //结束操作 + _end(event) { + this.data._flag_img_endtouch = true; + this._moveStop(); + }, + //点击中间剪裁框处理 + _click(event) { + if (!this.data.imgSrc) { + //调起上传 + this.upload(); + return; + } + this._draw(() => { + let x = event.detail ? event.detail.x : event.touches[0].clientX; + let y = event.detail ? event.detail.y : event.touches[0].clientY; + if ((x >= this.data.cut_left && x <= (this.data.cut_left + this.data.width)) && (y >= this.data.cut_top && y <= (this.data.cut_top + this.data.height))) { + //生成图片并回调 + wx.canvasToTempFilePath({ + width: this.data.width * this.data.export_scale, + height: Math.round(this.data.height * this.data.export_scale), + destWidth: this.data.width * this.data.export_scale, + destHeight: Math.round(this.data.height) * this.data.export_scale, + fileType: 'png', + quality: this.data.quality, + canvasId: this.data.el, + success: (res) => { + this.triggerEvent('tapcut', { + url: res.tempFilePath, + width: this.data.width * this.data.export_scale, + height: this.data.height * this.data.export_scale + }); + } + }, this) + } + }); + }, + //渲染 + _draw(callback) { + if (!this.data.imgSrc) return; + let draw = () => { + //图片实际大小 + let img_width = this.data.img_width * this.data.scale * this.data.export_scale; + let img_height = this.data.img_height * this.data.scale * this.data.export_scale; + //canvas和图片的相对距离 + var xpos = this.data._img_left - this.data.cut_left; + var ypos = this.data._img_top - this.data.cut_top; + //旋转画布 + this.data.ctx.translate(xpos * this.data.export_scale, ypos * this.data.export_scale); + this.data.ctx.rotate(this.data.angle * Math.PI / 180); + this.data.ctx.drawImage(this.data.imgSrc, -img_width / 2, -img_height / 2, img_width, img_height); + this.data.ctx.draw(false, () => { + callback && callback(); + }); + } + if (this.data.ctx.width != this.data.width || this.data.ctx.height != this.data.height) { + //优化拖动裁剪框,所以必须把宽高设置放在离用户触发渲染最近的地方 + this.setData({ + _canvas_height: this.data.height, + _canvas_width: this.data.width, + }, () => { + //延迟40毫秒防止点击过快出现拉伸或裁剪过多 + setTimeout(() => { + draw(); + }, 40); + }); + } else { + draw(); + } + }, + //裁剪框处理 + _cutTouchMove(e) { + if (this.data._flag_cut_touch && this.data.MOVE_THROTTLE_FLAG) { + if (this.data.disable_ratio && (this.data.disable_width || this.data.disable_height)) return; + //节流 + this.data.MOVE_THROTTLE_FLAG = false; + this._move_throttle(); + let width = this.data.width, + height = this.data.height, + cut_top = this.data.cut_top, + cut_left = this.data.cut_left, + size_correct = () => { + width = width <= this.data.max_width ? width >= this.data.min_width ? width : this.data.min_width : this.data.max_width; + height = height <= this.data.max_height ? height >= this.data.min_height ? height : this.data.min_height : this.data.max_height; + }, + size_inspect = () => { + if ((width > this.data.max_width || width < this.data.min_width || height > this.data.max_height || height < this.data.min_height) && this.data.disable_ratio) { + size_correct(); + return false; + } else { + size_correct(); + return true; + } + }; + height = this.data.CUT_START.height + ((this.data.CUT_START.corner > 1 && this.data.CUT_START.corner < 4 ? 1 : -1) * (this.data.CUT_START.y - e.touches[0].clientY)); + switch (this.data.CUT_START.corner) { + case 1: + width = this.data.CUT_START.width + this.data.CUT_START.x - e.touches[0].clientX; + if (this.data.disable_ratio) { + height = width / (this.data.width / this.data.height) + } + if (!size_inspect()) return; + cut_left = this.data.CUT_START.cut_left - (width - this.data.CUT_START.width); + break + case 2: + width = this.data.CUT_START.width + this.data.CUT_START.x - e.touches[0].clientX; + if (this.data.disable_ratio) { + height = width / (this.data.width / this.data.height) + } + if (!size_inspect()) return; + cut_top = this.data.CUT_START.cut_top - (height - this.data.CUT_START.height) + cut_left = this.data.CUT_START.cut_left - (width - this.data.CUT_START.width) + break + case 3: + width = this.data.CUT_START.width - this.data.CUT_START.x + e.touches[0].clientX; + if (this.data.disable_ratio) { + height = width / (this.data.width / this.data.height) + } + if (!size_inspect()) return; + cut_top = this.data.CUT_START.cut_top - (height - this.data.CUT_START.height); + break + case 4: + width = this.data.CUT_START.width - this.data.CUT_START.x + e.touches[0].clientX; + if (this.data.disable_ratio) { + height = width / (this.data.width / this.data.height) + } + if (!size_inspect()) return; + break + } + if (!this.data.disable_width && !this.data.disable_height) { + this.setData({ + width: width, + cut_left: cut_left, + height: height, + cut_top: cut_top, + }) + } else if (!this.data.disable_width) { + this.setData({ + width: width, + cut_left: cut_left + }) + } else if (!this.data.disable_height) { + this.setData({ + height: height, + cut_top: cut_top + }) + } + this._imgMarginDetectionScale(); + } + }, + _cutTouchStart(e) { + let currentX = e.touches[0].clientX; + let currentY = e.touches[0].clientY; + let cutbox_top4 = this.data.cut_top + this.data.height - 30; + let cutbox_bottom4 = this.data.cut_top + this.data.height + 20; + let cutbox_left4 = this.data.cut_left + this.data.width - 30; + let cutbox_right4 = this.data.cut_left + this.data.width + 30; + + let cutbox_top3 = this.data.cut_top - 30; + let cutbox_bottom3 = this.data.cut_top + 30; + let cutbox_left3 = this.data.cut_left + this.data.width - 30; + let cutbox_right3 = this.data.cut_left + this.data.width + 30; + + let cutbox_top2 = this.data.cut_top - 30; + let cutbox_bottom2 = this.data.cut_top + 30; + let cutbox_left2 = this.data.cut_left - 30; + let cutbox_right2 = this.data.cut_left + 30; + + let cutbox_top1 = this.data.cut_top + this.data.height - 30; + let cutbox_bottom1 = this.data.cut_top + this.data.height + 30; + let cutbox_left1 = this.data.cut_left - 30; + let cutbox_right1 = this.data.cut_left + 30; + if (currentX > cutbox_left4 && currentX < cutbox_right4 && currentY > cutbox_top4 && currentY < cutbox_bottom4) { + this._moveDuring(); + this.data._flag_cut_touch = true; + this.data._flag_img_endtouch = true; + this.data.CUT_START = { + width: this.data.width, + height: this.data.height, + x: currentX, + y: currentY, + corner: 4 + } + } else if (currentX > cutbox_left3 && currentX < cutbox_right3 && currentY > cutbox_top3 && currentY < cutbox_bottom3) { + this._moveDuring(); + this.data._flag_cut_touch = true; + this.data._flag_img_endtouch = true; + this.data.CUT_START = { + width: this.data.width, + height: this.data.height, + x: currentX, + y: currentY, + cut_top: this.data.cut_top, + cut_left: this.data.cut_left, + corner: 3 + } + } else if (currentX > cutbox_left2 && currentX < cutbox_right2 && currentY > cutbox_top2 && currentY < cutbox_bottom2) { + this._moveDuring(); + this.data._flag_cut_touch = true; + this.data._flag_img_endtouch = true; + this.data.CUT_START = { + width: this.data.width, + height: this.data.height, + cut_top: this.data.cut_top, + cut_left: this.data.cut_left, + x: currentX, + y: currentY, + corner: 2 + } + } else if (currentX > cutbox_left1 && currentX < cutbox_right1 && currentY > cutbox_top1 && currentY < cutbox_bottom1) { + this._moveDuring(); + this.data._flag_cut_touch = true; + this.data._flag_img_endtouch = true; + this.data.CUT_START = { + width: this.data.width, + height: this.data.height, + cut_top: this.data.cut_top, + cut_left: this.data.cut_left, + x: currentX, + y: currentY, + corner: 1 + } + } + }, + _cutTouchEnd(e) { + this._moveStop(); + this.data._flag_cut_touch = false; + }, + //停止移动时需要做的操作 + _moveStop() { + //清空之前的自动居中延迟函数并添加最新的 + clearTimeout(this.data.TIME_CUT_CENTER); + this.data.TIME_CUT_CENTER = setTimeout(() => { + //动画启动 + if (!this.data._cut_animation) { + this.setData({ + _cut_animation: true + }); + } + this.setCutCenter(); + }, 1000) + //清空之前的背景变化延迟函数并添加最新的 + clearTimeout(this.data.TIME_BG); + this.data.TIME_BG = setTimeout(() => { + if (this.data._flag_bright) { + this.setData({ + _flag_bright: false + }); + } + }, 2000) + }, + //移动中 + _moveDuring() { + //清空之前的自动居中延迟函数 + clearTimeout(this.data.TIME_CUT_CENTER); + //清空之前的背景变化延迟函数 + clearTimeout(this.data.TIME_BG); + //高亮背景 + if (!this.data._flag_bright) { + this.setData({ + _flag_bright: true + }); + } + }, + //监听器 + _watcher() { + Object.keys(this.data).forEach(v => { + this._observe(this.data, v, this.data.watch[v]); + }) + }, + _observe(obj, key, watchFun) { + var val = obj[key]; + Object.defineProperty(obj, key, { + configurable: true, + enumerable: true, + set: (value) => { + val = value; + watchFun && watchFun(val, this); + }, + get() { + if (val && '_img_top|img_left||width|height|min_width|max_width|min_height|max_height|export_scale|cut_top|cut_left|canvas_top|canvas_left|img_width|img_height|scale|angle|min_scale|max_scale'.indexOf(key) != -1) { + let ret = parseFloat(parseFloat(val).toFixed(3)); + if (typeof val == "string" && val.indexOf("%") != -1) { + ret += '%'; + } + return ret; + } + return val; + } + }) + }, + _preventTouchMove() {} + } +}) \ No newline at end of file diff --git a/vant/dist/cropper/image-cropper.json b/vant/dist/cropper/image-cropper.json new file mode 100755 index 0000000..d577ade --- /dev/null +++ b/vant/dist/cropper/image-cropper.json @@ -0,0 +1,3 @@ +{ + "component": true +} \ No newline at end of file diff --git a/vant/dist/cropper/image-cropper.wxml b/vant/dist/cropper/image-cropper.wxml new file mode 100755 index 0000000..a4a7526 --- /dev/null +++ b/vant/dist/cropper/image-cropper.wxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vant/dist/cropper/image-cropper.wxss b/vant/dist/cropper/image-cropper.wxss new file mode 100755 index 0000000..b52c12a --- /dev/null +++ b/vant/dist/cropper/image-cropper.wxss @@ -0,0 +1,143 @@ +.image-cropper { + background: rgba(14, 13, 13, .8); + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + z-index: 1; +} + +.image-cropper .main { + position: absolute; + width: 100vw; + height: 100vh; + overflow: hidden; +} + +.image-cropper .content { + z-index: 9; + position: absolute; + width: 100vw; + height: 100vh; + display: flex; + flex-direction: column; + pointer-events: none; +} + +.image-cropper .bg_black { + background: rgba(0, 0, 0, 0.8) !important; +} + +.image-cropper .bg_gray { + background: rgba(0, 0, 0, 0.45); + transition-duration: .35s; +} + +.image-cropper .content>.content_top { + pointer-events: none; +} + +.image-cropper .content>.content_middle { + display: flex; + height: 200px; + width: 100%; +} + +.image-cropper .content_middle_middle { + width: 200px; + box-sizing: border-box; + position: relative; + transition-duration: .3s; +} + +.image-cropper .content_middle_right { + flex: auto; +} + +.image-cropper .content>.content_bottom { + flex: auto; +} + +.image-cropper .img { + z-index: 2; + top: 0; + left: 0; + position: absolute; + border: none; + width: 100%; + backface-visibility: hidden; + transform-origin: center; +} + +.image-cropper .image-cropper-canvas { + position: fixed; + background: white; + width: 150px; + height: 150px; + z-index: 10; + top: -200%; + pointer-events: none; +} + +.image-cropper .border { + background: white; + pointer-events: auto; + position: absolute; +} + +.image-cropper .border-top-left { + left: -2.5px; + top: -2.5px; + height: 2.5px; + width: 33rpx; +} + +.image-cropper .border-top-right { + right: -2.5px; + top: -2.5px; + height: 2.5px; + width: 33rpx; +} + +.image-cropper .border-right-top { + top: -1px; + width: 2.5px; + height: 30rpx; + right: -2.5px; +} + +.image-cropper .border-right-bottom { + width: 2.5px; + height: 30rpx; + right: -2.5px; + bottom: -1px; +} + +.image-cropper .border-bottom-left { + height: 2.5px; + width: 33rpx; + bottom: -2.5px; + left: -2.5px; +} + +.image-cropper .border-bottom-right { + height: 2.5px; + width: 33rpx; + bottom: -2.5px; + right: -2.5px; +} + +.image-cropper .border-left-top { + top: -1px; + width: 2.5px; + height: 30rpx; + left: -2.5px; +} + +.image-cropper .border-left-bottom { + width: 2.5px; + height: 30rpx; + left: -2.5px; + bottom: -1px; +} diff --git a/vant/dist/cropper/index.js b/vant/dist/cropper/index.js deleted file mode 100755 index 9a80a7a..0000000 --- a/vant/dist/cropper/index.js +++ /dev/null @@ -1,381 +0,0 @@ -const defaultData = { - isShowCropper:false, - // 初始化的宽高 - cropperInitW: 750, - cropperInitH: 750, - // 动态的宽高 - cropperW: 750, - cropperH: 750, - // 动态的left top值 - cropperL: 0, - cropperT: 0, - - transL: 0, - transT: 0, - - // 图片缩放值 - scaleP: 0, - imageW: 0, - imageH: 0, - - // 裁剪框 宽高 - cutL: 0, - cutT: 0, - cutB: 0, - cutR: 0, - - qualityWidth: '', - innerAspectRadio: 750 / wx.getSystemInfoSync().windowWidth, - - C_CONSTANTS:{ - SCREEN_WIDTH : 750, - PAGE_X:0, // 手按下的x位置 - PAGE_Y:0, // 手按下y的位置 - PR : wx.getSystemInfoSync().pixelRatio, // dpi - T_PAGE_X:{}, // 手移动的时候x的位置 - T_PAGE_Y:{}, // 手移动的时候Y的位置 - CUT_L:0, // 初始化拖拽元素的left值 - CUT_T:0, // 初始化拖拽元素的top值 - CUT_R:0, // 初始化拖拽元素的 - CUT_B:0, // 初始化拖拽元素的 - CUT_W:0, // 初始化拖拽元素的宽度 - CUT_H:0, // 初始化拖拽元素的高度 - IMG_RATIO:0, // 图片比例 - IMG_REAL_W:0, // 图片实际的宽度 - IMG_REAL_H:0, // 图片实际的高度 - IMG_TYPE:'',//图片的格式 - DRAFG_MOVE_RATIO : 750 / wx.getSystemInfoSync().windowWidth //移动时候的比例 - } -}; -let data = {}; - -try{ - data = JSON.parse(JSON.stringify(defaultData)); -}catch(e){console.log(e)}; - -Component({ - properties: { - imageSrc:{ - type:String, - value:'', - observer(newVal, oldVal) { - if(newVal !== oldVal){ - this.setData({ - isShowCropper:true - },() => { - this.loadImage(); - }) - } - - } - }, - isCircleCrop:{ - type:Boolean, - value:false - }, - enableScale:{ - type:Boolean, - value:false - }, - ratio:{ - type:Number, - value:1 - } - }, - data, - ready(){ - if(this.data.isCircleCrop){ - //圆形裁剪 强制比例为1 - this.setData({ - ratio:1 - }) - } - }, - methods: { - loadImage() { - let {ratio,imageSrc} = this.data; - let {IMG_REAL_W,IMG_REAL_H,IMG_RATIO,SCREEN_WIDTH,IMG_TYPE} = this.data.C_CONSTANTS; - wx.getImageInfo({ - src: imageSrc, - success: res => { - IMG_REAL_W = res.width; - IMG_REAL_H = res.height; - IMG_RATIO = IMG_REAL_W / IMG_REAL_H; - IMG_TYPE = res.type === 'png' ? 'png' : 'jpg'; - // 根据图片的宽高显示不同的效果 保证图片可以正常显示 - let temp = {}; - let cropperData = {}; - if (IMG_RATIO >= 1) { - cropperData = { - cropperW: SCREEN_WIDTH, - cropperH: SCREEN_WIDTH / IMG_RATIO, - // 初始化left right - cropperL: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH) / 2), - cropperT: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO) / 2) - } - if(ratio > 1){ - temp = { - cutL: (SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO) / 2, - cutT: (SCREEN_WIDTH / IMG_RATIO - SCREEN_WIDTH / IMG_RATIO / ratio ) / 2, - cutR: SCREEN_WIDTH - (SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO) / 2 - SCREEN_WIDTH / IMG_RATIO, - cutB: SCREEN_WIDTH / IMG_RATIO - (SCREEN_WIDTH / IMG_RATIO - SCREEN_WIDTH / IMG_RATIO / ratio ) / 2 - SCREEN_WIDTH / IMG_RATIO / ratio - } - }else{ - temp = { - cutT:0, - cutB:0, - cutL:(SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO * ratio) / 2, - cutR: SCREEN_WIDTH - (SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO * ratio) / 2 - SCREEN_WIDTH / IMG_RATIO * ratio - } - } - } else { - cropperData = { - cropperW: SCREEN_WIDTH * IMG_RATIO, - cropperH: SCREEN_WIDTH, - // 初始化left right - cropperL: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO) / 2), - cropperT: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH) / 2) - } - if(ratio > 1){ - temp = { - cutL:0, - cutR:0, - cutT: (SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO / ratio) / 2, - cutB: SCREEN_WIDTH - (SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO / ratio) / 2 - SCREEN_WIDTH * IMG_RATIO / ratio - } - }else{ - temp = { - cutL: (SCREEN_WIDTH * IMG_RATIO - SCREEN_WIDTH * IMG_RATIO * ratio) / 2, - cutR: SCREEN_WIDTH * IMG_RATIO - (SCREEN_WIDTH * IMG_RATIO - SCREEN_WIDTH * IMG_RATIO * ratio) / 2 - SCREEN_WIDTH * IMG_RATIO * ratio, - cutT: (SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO) / 2, - cutB: SCREEN_WIDTH - (SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO) / 2 - SCREEN_WIDTH * IMG_RATIO - } - - } - } - this.setData({ - C_CONSTANTS:Object.assign({},this.data.C_CONSTANTS,{ - IMG_REAL_W, - IMG_REAL_H, - IMG_RATIO, - IMG_TYPE - }), - isShowCropper: true, - // 图片缩放值 - scaleP: IMG_REAL_W / SCREEN_WIDTH, - qualityWidth: IMG_REAL_W, - innerAspectRadio: IMG_RATIO, - ...temp, - ...cropperData - }) - } - }); - - }, - contentStartMove(e) { - this.setData({ - 'C_CONSTANTS.PAGE_X':e.touches[0].pageX, - 'C_CONSTANTS.PAGE_Y':e.touches[0].pageY - }) - }, - // 拖动时候触发的touchMove事件 - contentMoveing(e) { - let {PAGE_X,PAGE_Y,DRAFG_MOVE_RATIO} = this.data.C_CONSTANTS; - let {cutL,cutR,cutT,cutB} = this.data; - let dragLengthX = (PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO - let dragLengthY = (PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO - // 左移 - if (dragLengthX > 0) { - if (cutL - dragLengthX < 0) dragLengthX = cutL - } else { - if (cutR + dragLengthX < 0) dragLengthX = -cutR - } - - if (dragLengthY > 0) { - if (cutT - dragLengthY < 0) dragLengthY = cutT - } else { - if (cutB + dragLengthY < 0) dragLengthY = -cutB - } - this.setData({ - cutL: cutL - dragLengthX, - cutT: cutT - dragLengthY, - cutR: cutR + dragLengthX, - cutB: cutB + dragLengthY, - 'C_CONSTANTS.PAGE_X':e.touches[0].pageX, - 'C_CONSTANTS.PAGE_Y':e.touches[0].pageY - }); - }, - // 设置大小的时候触发的touchStart事件 - dragStart(e) { - let {cutL,cutR,cutT,cutB} = this.data; - this.setData({ - C_CONSTANTS:Object.assign({},this.data.C_CONSTANTS,{ - T_PAGE_X : e.touches[0].pageX, - T_PAGE_Y : e.touches[0].pageY, - CUT_L : cutL, - CUT_R : cutR, - CUT_B : cutB, - CUT_T : cutT - }) - }) - - }, - // 设置大小的时候触发的touchMove事件 - dragMove(e) { - let dragType = e.target.dataset.drag - let {ratio,cropperW,cropperH,cutL,cutT,cutR,cutB,enableScale} = this.data; - let {CUT_R,CUT_L,CUT_T,CUT_B,T_PAGE_X,T_PAGE_Y,DRAFG_MOVE_RATIO} = this.data.C_CONSTANTS; - let dragLength; - switch (dragType) { - case 'right': - dragLength = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO - if (CUT_R + dragLength < 0) dragLength = -CUT_R - cutR = CUT_R + dragLength; - if(enableScale){ - cutT = CUT_T + dragLength / ratio; - } - if(cutR < 0 || cutT < 0 || cutT > cropperH || cutR > cropperW) return; - break; - case 'left': - dragLength = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO - if (CUT_L - dragLength < 0) dragLength = CUT_L - if ((CUT_L - dragLength) > (this.data.cropperW - this.data.cutR)) dragLength = CUT_L - (this.data.cropperW - this.data.cutR) - cutL = CUT_L - dragLength; - if(enableScale){ - cutT = CUT_T - dragLength / ratio; - } - if(cutL < 0 || cutT < 0 || cutT > cropperH || cutL > cropperW) return; - break; - case 'top': - dragLength = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO - if (CUT_T - dragLength < 0) dragLength = CUT_T - if ((CUT_T - dragLength) > (this.data.cropperH - this.data.cutB)) dragLength = CUT_T - (this.data.cropperH - this.data.cutB) - cutT = CUT_T - dragLength; - if(enableScale){ - cutR = CUT_R - dragLength * ratio; - } - break; - case 'bottom': - dragLength = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO - if (CUT_B + dragLength < 0) dragLength = -CUT_B - cutB = CUT_B + dragLength; - if(enableScale){ - cutR = CUT_R + dragLength * ratio; - } - if(cutR < 0 || cutT < 0 || cutT > cropperH || cutR > cropperW) return; - break; - default:''; - } - this.setData({ - cutL, - cutT, - cutR, - cutB - }); - }, - contentTouchEnd(){}, - // 获取图片 - confirmCropper() { - const {isCircleCrop} = this.data;; - if(isCircleCrop){ - this.circleCrop() - }else{ - this.normalCropper(); - } - }, - - normalCropper(){ - let {imageSrc,cropperW,cropperH,cutL,cutT,cutR,cutB} = this.data; - let {IMG_REAL_W,IMG_REAL_H,IMG_TYPE} = this.data.C_CONSTANTS; - // 将图片写入画布 - const ctx = wx.createCanvasContext('cropper',this) - ctx.drawImage(imageSrc, 0, 0, IMG_REAL_W, IMG_REAL_H); - ctx.draw(true, () => { - // 获取画布要裁剪的位置和宽度 均为百分比 * 画布中图片的宽度 保证了在微信小程序中裁剪的图片模糊 位置不对的问题 canvasT = (_this.data.cutT / _this.data.cropperH) * (_this.data.imageH / pixelRatio) - let canvasW = ((cropperW - cutL - cutR) / cropperW) * IMG_REAL_W - let canvasH = ((cropperH - cutT - cutB) / cropperH) * IMG_REAL_H - let canvasL = (cutL / cropperW) * IMG_REAL_W - let canvasT = (cutT / cropperH) * IMG_REAL_H - wx.canvasToTempFilePath({ - x: canvasL, - y: canvasT, - width: canvasW, - height: canvasH, - destWidth: canvasW, - destHeight: canvasH, - fileType:IMG_TYPE || 'jpg', - canvasId: 'cropper', - success: (res) => { - //图片裁剪成功 - this.cancelCropper(); - this.triggerEvent('cropperDone', { - src:res.tempFilePath, - cropperData:{ - x: canvasL, - y: canvasT, - width: canvasW, - height: canvasH - } - }) - }, - fail:err =>{ - this.triggerEvent('cropperFail',err) - } - },this); - }) - }, - - circleCrop(){ - let {imageSrc,cropperW,cropperH,cutL,cutT,cutR,cutB} = this.data; - let {IMG_REAL_W,IMG_REAL_H,IMG_TYPE} = this.data.C_CONSTANTS; - // 将图片写入画布 - const ctx = wx.createCanvasContext('cropper',this) - let canvasW = ((cropperW - cutL - cutR) / cropperW) * IMG_REAL_W - let canvasL = (cutL / cropperW) * IMG_REAL_W - let canvasT = (cutT / cropperH) * IMG_REAL_H - - this.setData({ - canvasW:canvasW, - canvasH:canvasW - },() => { - ctx.arc(canvasW / 2,canvasW / 2,canvasW / 2,0,2 * Math.PI); - ctx.clip(); - ctx.drawImage(imageSrc, canvasL, canvasT, canvasW, canvasW,0,0,canvasW,canvasW); - ctx.draw(true, () => { - wx.canvasToTempFilePath({ - fileType:IMG_TYPE || 'jpg', - canvasId: 'cropper', - success: (res) => { - //图片裁剪成功 - this.cancelCropper(); - this.triggerEvent('cropperDone', { - src:res.tempFilePath, - cropperData:{ - x: canvasL, - y: canvasT, - width: canvasW, - height: canvasW - } - }) - }, - fail:err =>{ - this.triggerEvent('cropperFail',err) - } - },this); - }) - }) - }, - - cancelCropper(){ - let originData = {} - try{ - originData = JSON.parse(JSON.stringify(defaultData)) - }catch(e){}; - - this.setData({ - ...originData - }); - this.triggerEvent('cropperCancel') - } - } -}) \ No newline at end of file diff --git a/vant/dist/cropper/index.json b/vant/dist/cropper/index.json deleted file mode 100755 index fba482a..0000000 --- a/vant/dist/cropper/index.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "component": true -} \ No newline at end of file diff --git a/vant/dist/cropper/index.wxml b/vant/dist/cropper/index.wxml deleted file mode 100755 index 373095b..0000000 --- a/vant/dist/cropper/index.wxml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vant/dist/cropper/index.wxss b/vant/dist/cropper/index.wxss deleted file mode 100755 index 08aa641..0000000 --- a/vant/dist/cropper/index.wxss +++ /dev/null @@ -1,296 +0,0 @@ -/* pages/wx-cropper/index.wxss */ -.wx-cropper-info { - position: fixed; - top: 140rpx; - left: 0; - right: 0; - bottom: 0; - display: block; - z-index: 10000; - align-items: center; - flex-direction: column; - height: 100%; - background: #000; -} - -.cropper-config { - display: flex; - position: fixed; - width: 100%; - bottom: 20rpx; -} - -.cropper-config .btn { - min-width: 300rpx; -} - -.cropper-config .cropper-confirm { - background: #fac208; -} - -.cropper-content { - min-height: 750rpx; - width: 100%; - height: 100%; -} - -.wx-corpper { - position: relative; - overflow: hidden; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; - -webkit-tap-highlight-color: transparent; - -webkit-touch-callout: none; - box-sizing: border-box; -} - -.wx-corpper-content { - position: relative; -} - -.wx-corpper-content .img { - display: block; - width: 100%; - min-width: 0 !important; - max-width: none !important; - height: 100%; - min-height: 0 !important; - max-height: none !important; - image-orientation: 0deg !important; - margin: 0 auto; -} - -/* 移动图片效果 */ -.wx-cropper-drag-box { - position: absolute; - top: 0; - right: 0; - bottom: 0; - left: 0; - cursor: move; - background: rgba(0, 0, 0, 0.6); - z-index: 1; -} - -/* 内部的信息 */ -.wx-corpper-crop-box { - position: absolute; - background: rgba(255, 255, 255, 0.3); - z-index: 2; -} - -.wx-corpper-crop-box .wx-cropper-view-box { - position: relative; - display: block; - width: 100%; - height: 100%; - overflow: visible; - outline: 1px solid #69f; - outline-color: rgba(102, 153, 255, .75) -} - -/* 横向虚线 */ -.wx-cropper-dashed-h { - position: absolute; - top: 33.33333333%; - left: 0; - width: 100%; - height: 33.33333333%; - border-top: 1px dashed rgba(255, 255, 255, 0.5); - border-bottom: 1px dashed rgba(255, 255, 255, 0.5); -} - -/* 纵向虚线 */ -.wx-cropper-dashed-v { - position: absolute; - left: 33.33333333%; - top: 0; - width: 33.33333333%; - height: 100%; - border-left: 1px dashed rgba(255, 255, 255, 0.5); - border-right: 1px dashed rgba(255, 255, 255, 0.5); -} - -/* 四个方向的线 为了之后的拖动事件*/ -.wx-cropper-line-t { - position: absolute; - display: block; - width: 100%; - background-color: #69f; - top: 0; - left: 0; - height: 1px; - opacity: 0.1; - cursor: n-resize; -} - -.wx-cropper-line-t::before { - content: ''; - position: absolute; - top: 50%; - right: 0rpx; - width: 100%; - -webkit-transform: translate3d(0, -50%, 0); - transform: translate3d(0, -50%, 0); - bottom: 0; - height: 41rpx; - background: transparent; - z-index: 11; -} - -.wx-cropper-line-r { - position: absolute; - display: block; - background-color: #69f; - top: 0; - right: 0px; - width: 1px; - opacity: 0.1; - height: 100%; - cursor: e-resize; -} - -.wx-cropper-line-r::before { - content: ''; - position: absolute; - top: 0; - left: 50%; - width: 41rpx; - -webkit-transform: translate3d(-50%, 0, 0); - transform: translate3d(-50%, 0, 0); - bottom: 0; - height: 100%; - background: transparent; - z-index: 11; -} - -.wx-cropper-line-b { - position: absolute; - display: block; - width: 100%; - background-color: #69f; - bottom: 0; - left: 0; - height: 1px; - opacity: 0.1; - cursor: s-resize; -} - -.wx-cropper-line-b::before { - content: ''; - position: absolute; - top: 50%; - right: 0rpx; - width: 100%; - -webkit-transform: translate3d(0, -50%, 0); - transform: translate3d(0, -50%, 0); - bottom: 0; - height: 41rpx; - background: transparent; - z-index: 11; -} - -.wx-cropper-line-l { - position: absolute; - display: block; - background-color: #69f; - top: 0; - left: 0; - width: 1px; - opacity: 0.1; - height: 100%; - cursor: w-resize; -} - -.wx-cropper-line-l::before { - content: ''; - position: absolute; - top: 0; - left: 50%; - width: 41rpx; - -webkit-transform: translate3d(-50%, 0, 0); - transform: translate3d(-50%, 0, 0); - bottom: 0; - height: 100%; - background: transparent; - z-index: 11; -} - -.wx-cropper-point { - width: 5px; - height: 5px; - background-color: #69f; - opacity: .75; - position: absolute; - z-index: 3; -} - -.point-t { - top: -3px; - left: 50%; - margin-left: -3px; - cursor: n-resize; -} - -.point-tr { - top: -3px; - left: 100%; - margin-left: -3px; - cursor: n-resize; -} - -.point-r { - top: 50%; - left: 100%; - margin-left: -3px; - margin-top: -3px; - cursor: n-resize; -} - -.point-rb { - left: 100%; - top: 100%; - -webkit-transform: translate3d(-50%, -50%, 0); - transform: translate3d(-50%, -50%, 0); - cursor: n-resize; - /* width: 24rpx; */ - /* height: 24rpx; */ - background-color: #69f; - position: absolute; - z-index: 1112; - opacity: 1; -} - -.point-b { - left: 50%; - top: 100%; - margin-left: -3px; - margin-top: -3px; - cursor: n-resize; -} - -.point-bl { - left: 0%; - top: 100%; - margin-left: -3px; - margin-top: -3px; - cursor: n-resize; -} - -.point-l { - left: 0%; - top: 50%; - margin-left: -3px; - margin-top: -3px; - cursor: n-resize; -} - -.point-lt { - left: 0%; - top: 0%; - margin-left: -3px; - margin-top: -3px; - cursor: n-resize; -} \ No newline at end of file diff --git a/vant/dist/tabs/index.js b/vant/dist/tabs/index.js index ec54096..3be2db9 100755 --- a/vant/dist/tabs/index.js +++ b/vant/dist/tabs/index.js @@ -1,271 +1,302 @@ import { VantComponent } from '../common/component'; import { touch } from '../mixins/touch'; -import { - getAllRect, - getRect, - groupSetData, - nextTick, - requestAnimationFrame, -} from '../common/utils'; +import { getAllRect, getRect, groupSetData, nextTick, requestAnimationFrame, } from '../common/utils'; import { isDef } from '../common/validator'; import { useChildren } from '../common/relation'; VantComponent({ - mixins: [touch], - classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'], - relation: useChildren('tab', function () { - this.updateTabs(); - }), - props: { - sticky: Boolean, - border: Boolean, - swipeable: Boolean, - titleActiveColor: String, - titleInactiveColor: String, - color: String, - animated: { - type: Boolean, - observer() { - this.children.forEach((child, index) => - child.updateRender(index === this.data.currentIndex, this) - ); - }, + mixins: [touch], + classes: [ + 'nav-class', + 'tab-class', + 'tab-active-class', + 'line-class', + 'wrap-class', + ], + relation: useChildren('tab', function () { + this.updateTabs(); + }), + props: { + sticky: Boolean, + border: Boolean, + swipeable: Boolean, + titleActiveColor: String, + titleInactiveColor: String, + color: String, + animated: { + type: Boolean, + observer() { + this.children.forEach((child, index) => child.updateRender(index === this.data.currentIndex, this)); + }, + }, + lineWidth: { + type: null, + value: 40, + observer: 'resize', + }, + lineHeight: { + type: null, + value: -1, + }, + active: { + type: null, + value: 0, + observer(name) { + if (name !== this.getCurrentName()) { + this.setCurrentIndexByName(name); + } + }, + }, + type: { + type: String, + value: 'line', + }, + ellipsis: { + type: Boolean, + value: true, + }, + duration: { + type: Number, + value: 0.3, + }, + zIndex: { + type: Number, + value: 1, + }, + swipeThreshold: { + type: Number, + value: 5, + observer(value) { + this.setData({ + scrollable: this.children.length > value || !this.data.ellipsis, + }); + }, + }, + offsetTop: { + type: Number, + value: 0, + }, + lazyRender: { + type: Boolean, + value: true, + }, + useBeforeChange: { + type: Boolean, + value: false, + }, }, - lineWidth: { - type: null, - value: 40, - observer: 'resize', + data: { + tabs: [], + scrollLeft: 0, + scrollable: false, + currentIndex: 0, + container: null, + skipTransition: true, + scrollWithAnimation: false, + lineOffsetLeft: 0, + inited: false, }, - lineHeight: { - type: null, - value: -1, - }, - active: { - type: null, - value: 0, - observer(name) { - if (name !== this.getCurrentName()) { - this.setCurrentIndexByName(name); - } - }, - }, - type: { - type: String, - value: 'line', - }, - ellipsis: { - type: Boolean, - value: true, - }, - duration: { - type: Number, - value: 0.3, - }, - zIndex: { - type: Number, - value: 1, - }, - swipeThreshold: { - type: Number, - value: 5, - observer(value) { - this.setData({ - scrollable: this.children.length > value || !this.data.ellipsis, + mounted() { + requestAnimationFrame(() => { + this.swiping = true; + this.setData({ + container: () => this.createSelectorQuery().select('.van-tabs'), + }); + this.resize(); + this.scrollIntoView(); }); - }, }, - offsetTop: { - type: Number, - value: 0, + methods: { + updateTabs() { + const { children = [], data } = this; + this.setData({ + tabs: children.map((child) => child.data), + scrollable: this.children.length > data.swipeThreshold || !data.ellipsis, + }); + this.setCurrentIndexByName(data.active || this.getCurrentName()); + }, + trigger(eventName, child) { + const { currentIndex } = this.data; + const data = this.getChildData(currentIndex, child); + if (!isDef(data)) { + return; + } + this.$emit(eventName, data); + }, + onTap(event) { + const { index } = event.currentTarget.dataset; + const child = this.children[index]; + if (child.data.disabled) { + this.trigger('disabled', child); + return; + } + this.onBeforeChange(index).then(() => { + this.setCurrentIndex(index); + nextTick(() => { + this.trigger('click'); + }); + }); + }, + // correct the index of active tab + setCurrentIndexByName(name) { + const { children = [] } = this; + const matched = children.filter((child) => child.getComputedName() === name); + if (matched.length) { + this.setCurrentIndex(matched[0].index); + } + }, + setCurrentIndex(currentIndex) { + const { data, children = [] } = this; + if (!isDef(currentIndex) || + currentIndex >= children.length || + currentIndex < 0) { + return; + } + groupSetData(this, () => { + children.forEach((item, index) => { + const active = index === currentIndex; + if (active !== item.data.active || !item.inited) { + item.updateRender(active, this); + } + }); + }); + if (currentIndex === data.currentIndex) { + if (!data.inited) { + this.resize(); + } + return; + } + const shouldEmitChange = data.currentIndex !== null; + this.setData({ currentIndex }); + requestAnimationFrame(() => { + this.resize(); + this.scrollIntoView(); + }); + nextTick(() => { + this.trigger('input'); + if (shouldEmitChange) { + this.trigger('change'); + } + }); + }, + getCurrentName() { + const activeTab = this.children[this.data.currentIndex]; + if (activeTab) { + return activeTab.getComputedName(); + } + }, + resize() { + if (this.data.type !== 'line') { + return; + } + const { currentIndex, ellipsis, skipTransition } = this.data; + Promise.all([ + getAllRect(this, '.van-tab'), + getRect(this, '.van-tabs__line'), + ]).then(([rects = [], lineRect]) => { + const rect = rects[currentIndex]; + if (rect == null) { + return; + } + let lineOffsetLeft = rects + .slice(0, currentIndex) + .reduce((prev, curr) => prev + curr.width, 0); + lineOffsetLeft += + (rect.width - lineRect.width) / 2 + (ellipsis ? 0 : 8); + this.setData({ lineOffsetLeft, inited: true }); + this.swiping = true; + if (skipTransition) { + // waiting transition end + setTimeout(() => { + this.setData({ skipTransition: false }); + }, this.data.duration); + } + }); + }, + // scroll active tab into view + scrollIntoView() { + const { currentIndex, scrollable, scrollWithAnimation } = this.data; + if (!scrollable) { + return; + } + Promise.all([ + getAllRect(this, '.van-tab'), + getRect(this, '.van-tabs__nav'), + ]).then(([tabRects, navRect]) => { + const tabRect = tabRects[currentIndex]; + const offsetLeft = tabRects + .slice(0, currentIndex) + .reduce((prev, curr) => prev + curr.width, 0); + this.setData({ + scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2, + }); + if (!scrollWithAnimation) { + nextTick(() => { + this.setData({ scrollWithAnimation: true }); + }); + } + }); + }, + onTouchScroll(event) { + this.$emit('scroll', event.detail); + }, + onTouchStart(event) { + if (!this.data.swipeable) + return; + this.swiping = true; + this.touchStart(event); + }, + onTouchMove(event) { + if (!this.data.swipeable || !this.swiping) + return; + this.touchMove(event); + }, + // watch swipe touch end + onTouchEnd() { + if (!this.data.swipeable || !this.swiping) + return; + const { direction, deltaX, offsetX } = this; + const minSwipeDistance = 50; + if (direction === 'horizontal' && offsetX >= minSwipeDistance) { + const index = this.getAvaiableTab(deltaX); + if (index !== -1) { + this.onBeforeChange(index).then(() => this.setCurrentIndex(index)); + } + } + this.swiping = false; + }, + getAvaiableTab(direction) { + const { tabs, currentIndex } = this.data; + const step = direction > 0 ? -1 : 1; + for (let i = step; currentIndex + i < tabs.length && currentIndex + i >= 0; i += step) { + const index = currentIndex + i; + if (index >= 0 && + index < tabs.length && + tabs[index] && + !tabs[index].disabled) { + return index; + } + } + return -1; + }, + onBeforeChange(index) { + const { useBeforeChange } = this.data; + if (!useBeforeChange) { + return Promise.resolve(); + } + return new Promise((resolve, reject) => { + this.$emit('before-change', Object.assign(Object.assign({}, this.getChildData(index)), { callback: (status) => (status ? resolve() : reject()) })); + }); + }, + getChildData(index, child) { + const currentChild = child || this.children[index]; + if (!isDef(currentChild)) { + return; + } + return { + index: currentChild.index, + name: currentChild.getComputedName(), + title: currentChild.data.title, + }; + }, }, - lazyRender: { - type: Boolean, - value: true, - }, - }, - data: { - tabs: [], - scrollLeft: 0, - scrollable: false, - currentIndex: 0, - container: null, - skipTransition: true, - lineOffsetLeft: 0, - }, - mounted() { - requestAnimationFrame(() => { - this.setData({ - container: () => this.createSelectorQuery().select('.van-tabs'), - }); - this.resize(true); - this.scrollIntoView(); - }); - }, - methods: { - updateTabs() { - const { children = [], data } = this; - this.setData({ - tabs: children.map((child) => child.data), - scrollable: - this.children.length > data.swipeThreshold || !data.ellipsis, - }); - this.setCurrentIndexByName(data.active || this.getCurrentName()); - }, - trigger(eventName, child) { - const { currentIndex } = this.data; - const currentChild = child || this.children[currentIndex]; - if (!isDef(currentChild)) { - return; - } - this.$emit(eventName, { - index: currentChild.index, - name: currentChild.getComputedName(), - title: currentChild.data.title, - }); - }, - onTap(event) { - const { index } = event.currentTarget.dataset; - const child = this.children[index]; - if (child.data.disabled) { - this.trigger('disabled', child); - } else { - this.setCurrentIndex(index); - nextTick(() => { - this.trigger('click'); - }); - } - }, - // correct the index of active tab - setCurrentIndexByName(name) { - const { children = [] } = this; - const matched = children.filter( - (child) => child.getComputedName() === name - ); - if (matched.length) { - this.setCurrentIndex(matched[0].index); - } - }, - setCurrentIndex(currentIndex) { - const { data, children = [] } = this; - if ( - !isDef(currentIndex) || - currentIndex >= children.length || - currentIndex < 0 - ) { - return; - } - groupSetData(this, () => { - children.forEach((item, index) => { - const active = index === currentIndex; - if (active !== item.data.active || !item.inited) { - item.updateRender(active, this); - } - }); - }); - if (currentIndex === data.currentIndex) { - return; - } - const shouldEmitChange = data.currentIndex !== null; - this.setData({ currentIndex }); - nextTick(() => { - this.resize(); - this.scrollIntoView(); - this.trigger('input'); - if (shouldEmitChange) { - this.trigger('change'); - } - }); - }, - getCurrentName() { - const activeTab = this.children[this.data.currentIndex]; - if (activeTab) { - return activeTab.getComputedName(); - } - }, - resize(skipTransition = false) { - if (this.data.type !== 'line') { - return; - } - const { currentIndex, ellipsis } = this.data; - Promise.all([ - getAllRect(this, '.van-tab'), - getRect(this, '.van-tabs__line'), - ]).then(([rects = [], lineRect]) => { - const rect = rects[currentIndex]; - if (rect == null) { - return; - } - let lineOffsetLeft = rects - .slice(0, currentIndex) - .reduce((prev, curr) => prev + curr.width, 0); - lineOffsetLeft += - (rect.width - lineRect.width) / 2 + (ellipsis ? 0 : 8); - this.setData({ - lineOffsetLeft, - skipTransition, - }); - }); - }, - // scroll active tab into view - scrollIntoView() { - const { currentIndex, scrollable } = this.data; - if (!scrollable) { - return; - } - Promise.all([ - getAllRect(this, '.van-tab'), - getRect(this, '.van-tabs__nav'), - ]).then(([tabRects, navRect]) => { - const tabRect = tabRects[currentIndex]; - const offsetLeft = tabRects - .slice(0, currentIndex) - .reduce((prev, curr) => prev + curr.width, 0); - this.setData({ - scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2, - }); - }); - }, - onTouchScroll(event) { - this.$emit('scroll', event.detail); - }, - onTouchStart(event) { - if (!this.data.swipeable) return; - this.touchStart(event); - }, - onTouchMove(event) { - if (!this.data.swipeable) return; - this.touchMove(event); - }, - // watch swipe touch end - onTouchEnd() { - if (!this.data.swipeable) return; - const { direction, deltaX, offsetX } = this; - const minSwipeDistance = 50; - if (direction === 'horizontal' && offsetX >= minSwipeDistance) { - const index = this.getAvaiableTab(deltaX); - if (index !== -1) { - this.setCurrentIndex(index); - } - } - }, - getAvaiableTab(direction) { - const { tabs, currentIndex } = this.data; - const step = direction > 0 ? -1 : 1; - for ( - let i = step; - currentIndex + i < tabs.length && currentIndex + i >= 0; - i += step - ) { - const index = currentIndex + i; - if ( - index >= 0 && - index < tabs.length && - tabs[index] && - !tabs[index].disabled - ) { - return index; - } - } - return -1; - }, - }, }); diff --git a/vant/dist/tabs/index.wxml b/vant/dist/tabs/index.wxml index 0dc346b..05bb1e1 100755 --- a/vant/dist/tabs/index.wxml +++ b/vant/dist/tabs/index.wxml @@ -1,7 +1,7 @@ - + - + - +