From 8b808723790b301d09e1146464537540aa7cbfc1 Mon Sep 17 00:00:00 2001 From: itgaojian163 Date: Sun, 19 Jan 2025 17:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5,=E4=BA=A7=E4=B8=9A=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 1 + app.wxss | 9 ++ pages/domain/domain.js | 89 ++++++++++- pages/domain/domain.json | 3 +- pages/domain/domain.wxml | 83 +++------- pages/domain/domain.wxss | 26 +++- pages/index/index.js | 316 ++++++++++++++++++++------------------- pages/index/index.wxml | 100 +++++-------- pages/index/index.wxss | 28 ++-- utils/api/domainApi.js | 23 +++ utils/api/indexApi.js | 42 ++++++ utils/http.js | 30 ++-- utils/util.js | 56 ++++++- 13 files changed, 494 insertions(+), 312 deletions(-) create mode 100644 utils/api/domainApi.js create mode 100644 utils/api/indexApi.js diff --git a/app.js b/app.js index 2360b59..d38cb27 100644 --- a/app.js +++ b/app.js @@ -14,5 +14,6 @@ App({ }, globalData: { userInfo: null, + imgPath: 'http://106.74.34.136:8084/daqi/route/file/true/' } }) \ No newline at end of file diff --git a/app.wxss b/app.wxss index 0524169..9af45ce 100644 --- a/app.wxss +++ b/app.wxss @@ -187,6 +187,14 @@ page::after { width: 100%; } +.line-2 { + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + overflow: hidden; + width: 100%; +} + .line-noappoint { @@ -205,6 +213,7 @@ page::after { .body { overflow: scroll; + height: auto; } .font-18 { diff --git a/pages/domain/domain.js b/pages/domain/domain.js index 0d915b5..ec63ae8 100644 --- a/pages/domain/domain.js +++ b/pages/domain/domain.js @@ -1,4 +1,6 @@ // pages/domain/domain.js +const app = getApp(); +import DomainService from '../../utils/api/domainApi'; Page({ /** @@ -12,6 +14,12 @@ Page({ lastScrollLeft: 0, lastScrollTop: 0, defaultSliderWidth: 10, //默认指示器宽度 + domainCategoryList: [], //特色产业 + keyEnterpriseList: [], //重点企业 + showPageLoading: true, + imgBasePath: app.globalData.imgPath, + domainInfo: {}, //产业基础 + isAreaExpand: false, }, /** @@ -23,7 +31,18 @@ Page({ this.setData({ screenWidth: screenWidth - 34 }) - + var _self = this + //产业基础 + _self.getDomainInfo() + //特色产业 + _self.getDomainCategory() + //重点企业 + _self.getKeyEnterprise() + setTimeout(() => { + _self.setData({ + showPageLoading: false + }) + }, 2000); }, onReady() { var _self = this @@ -43,6 +62,54 @@ Page({ }) }, 5) }, + //产业基础 + getDomainInfo() { + var _self = this + DomainService.doGetDomainInfo() + .then(res => { + if (res) { + _self.setData({ + domainInfo: res.rows[0] + }) + } + }, err => { + wx.showToast({ + title: '网络错误(domainInfo)', + }) + }) + }, + //特色产业 + getDomainCategory() { + var _self = this + DomainService.doGetDomainCategory() + .then(res => { + if (res) { + _self.setData({ + domainCategoryList: res + }) + } + }, err => { + wx.showToast({ + title: '网络错误(domainCategory)', + }) + }) + }, + //重点企业 + getKeyEnterprise() { + var _self = this + DomainService.doGetKeyEnterprise() + .then(res => { + if (res) { + _self.setData({ + keyEnterpriseList: res + }) + } + }, err => { + wx.showToast({ + title: '网络错误(domainEnterprise)', + }) + }) + }, //监听scroll-view滚动 scrollPlates(e) { var _self = this @@ -57,12 +124,32 @@ Page({ lastScrollLeft: scrollLeft }) }, + areaShowAll() { + var _self = this + _self.setData({ + isAreaExpand: !_self.data.isAreaExpand + }) + }, //公司详情 showCompany() { wx.navigateTo({ url: '/pages/company/company', }) }, + onPullDownRefresh() { + var _self = this + _self.setData({ + showPageLoading: true + }) + _self.getDomainCategory() + _self.getKeyEnterprise() + setTimeout(() => { + wx.stopPullDownRefresh() + _self.setData({ + showPageLoading: false + }) + }, 2000); + }, //园区详情 showGarden() { wx.navigateTo({ diff --git a/pages/domain/domain.json b/pages/domain/domain.json index 8835af0..7ad8a36 100644 --- a/pages/domain/domain.json +++ b/pages/domain/domain.json @@ -1,3 +1,4 @@ { - "usingComponents": {} + "usingComponents": {}, + "enablePullDownRefresh": true } \ No newline at end of file diff --git a/pages/domain/domain.wxml b/pages/domain/domain.wxml index a5e0d01..ecbe77d 100644 --- a/pages/domain/domain.wxml +++ b/pages/domain/domain.wxml @@ -3,21 +3,13 @@ - 产业基础 - 达拉特旗位于内蒙古自治区南部,为鄂尔多斯市下辖的一个旗,北与包头市隔河相望,东南西分别与准格尔旗、东胜市、杭锦旗接壤,达拉特旗地处鄂尔多斯高原西部,黄河南岸。 - - - - 全旗总面积8200平方公里 - - - - 辖8个苏木镇 - - - - 总人口34万 - + {{domainInfo.newsContentTitle}} + + + + + {{isAreaExpand?'收取':'查看全部'}} + @@ -29,35 +21,12 @@ - - - 新能源产业 - - - - 新能源产业 - - - - - 新能源产业 - - - - 新能源产业 - - - - 新能源产业 - - - - 新能源产业 - - - - 新能源产业 - + + + + {{item.directoriesName}} + + @@ -132,30 +101,15 @@ 重点企业 - + - + - 企业名称 - 社会信用代码:11010202340 + {{item.name}} + 社会信用代码:{{item.number}} - - - - 企业名称 - 社会信用代码:11010202340 - - - - - - - 企业名称 - 社会信用代码:11010202340 - - @@ -189,4 +143,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/pages/domain/domain.wxss b/pages/domain/domain.wxss index 14866b1..4fc336c 100644 --- a/pages/domain/domain.wxss +++ b/pages/domain/domain.wxss @@ -87,10 +87,33 @@ margin-top: 32rpx; padding: 20rpx; margin-right: 20rpx; - border-radius: 5rpx; + border-radius: 8rpx; width: calc((100% - 110px) / 4); } +.right-more-bg { + background: #E7E7E7; + font-weight: 500; + align-self: flex-end; + display: flex; + flex-direction: row; + justify-content: center; + padding: 5rpx 10rpx; + border-radius: 15rpx; + align-items: center; +} + +.right-more-bg .icon { + width: 20rpx; + height: 20rpx; + margin-left: 5rpx; +} + +.right-more-bg .txt { + font-size: 16rpx; + color: #256742; + text-align: center; +} .unique-item image { width: 66rpx; height: 66rpx; @@ -214,6 +237,7 @@ .enterprise-item .icon { width: 92rpx; height: 92rpx; + border-radius: 15rpx; } .enterprise-content { diff --git a/pages/index/index.js b/pages/index/index.js index 60e706c..2dcb554 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -1,15 +1,11 @@ -import AuthService from '../../utils/api/testapi'; +import IndexService from '../../utils/api/indexApi'; +import utils from '../../utils/util'; const app = getApp(); var defaultAvatarUrl = ''; const date = new Date() Page({ data: { - progress1: '60%', - progress2: '80%', - progress3: '90%', - progress4: '40%', - curTab: 1, isExpand: false, //简介展开和收起 collapseText: '收起', expandText: '查看更多>>', @@ -20,16 +16,6 @@ Page({ tempYear: '', yearValue: [0], showActionsheet: false, - motto: 'Hello World', - userInfo: { - avatarUrl: defaultAvatarUrl, - nickName: '', - }, - hasUserInfo: false, - overtop: true, //是否显示收起和展开 - canIUseGetUserProfile: wx.canIUse('getUserProfile'), - canIUseNicknameComp: wx.canIUse('input.type.nickname'), - triggered: false, list: [], isLoading: false, count: 1, @@ -45,21 +31,27 @@ Page({ defaultSliderWidth: 20, //默认指示器宽度 isShowDot: false, //是否显示指示器 testList: [], - showPageLoading: true + showPageLoading: true, + descVideoUrl: '', + descVideoCover: '', + descContent: "", + statisticsList: [], //数据统计 + investList: [], //投资机会 + investAreaId: "b4945b87-fe05-4af3-8453-65451b3137a3", //投资环境 + investAreaBean: null, + imgBasePath: app.globalData.imgPath, + superiorityList: [], //投资优势, + investAreaList: [], //投资环境List }, onLoad(e) { - this.setData({ - list: this.data.list, - overtop: false - }) + var _self = this var temp = [] - for (let i = 2010; i < 2041; i++) { + for (let i = 2010; i <= _self.data.year; i++) { temp.push(i) } - this.setData({ - years: temp + _self.setData({ + years: temp.reverse() }) - var _self = this _self.setData({ 'yearValue[0]': _self.data.years.indexOf(_self.data.year) }) @@ -83,7 +75,146 @@ Page({ _self.setData({ showPageLoading: false }) - }, 5000); + }, 300); + //获取简介 + this.getDescVideo() + //介绍 + this.getDesc() + //数据统计 + this.getStatistics() + //投资机会 + this.getInvest() + //默认获取地区概况 + this.getInvestAreaCategory() + //投资环境 + this.getSuperiority() + }, + //视频介绍 + getDescVideo() { + var _self = this + IndexService.doGetDescVideo() + .then(res => { + console.log(res) + _self.setData({ + descVideoUrl: _self.data.imgBasePath + res.rows[0].fileList[0].contentFileFileId, + descVideoCover: _self.data.imgBasePath + res.rows[0].fileList[0].contentFileCoverId + }) + }, err => { + wx.showToast({ + title: '网络错误(video)', + }) + }) + }, + //简介 + getDesc() { + var _self = this + IndexService.doGetDescInfo() + .then(res => { + if (res) { + _self.setData({ + descContent: res.rows[0].newsContentContent + }) + } + }, err => { + console.log(err) + wx.showToast({ + title: '网络错误(简介)', + }) + }) + }, + //数据统计 + getStatistics() { + var _self = this + IndexService.doGetStatistics({ + year: _self.data.year + }) + .then(res => { + if (res) { + + res.forEach(item => { + var scale = item.value > 100 ? 100 : 1 + item.progress = `${item.value}%` + item.color = utils.randomLight() + item.fontColor = utils.randomDark() + }); + + _self.setData({ + statisticsList: res + }) + } + }, err => { + console.log(err) + wx.showToast({ + title: '网络错误(数据统计)', + }) + }) + }, + //投资机会 + getInvest() { + var _self = this + IndexService.doGetInvest() + .then(res => { + if (res) { + _self.setData({ + investList: res + }) + } + }, err => { + wx.showToast({ + title: '网络错误(投资机会)', + }) + }) + }, + //地区概况,资源条件,气候条件,基础设施 + getInvestArea(id) { + var _self = this + IndexService.doGetInvestArea({ + newsDirectoriesId: id + }) + .then(res => { + if (res) { + _self.setData({ + investAreaBean: res.rows[0] + }) + } + }, err => { + wx.showToast({ + title: '网络错误(InvestArea)', + }) + }) + }, + getSuperiority() { + var _self = this + IndexService.doGetSuperiorityList() + .then(res => { + if (res) { + _self.setData({ + superiorityList: res + }) + } + }, err => { + wx.showToast({ + title: '网络错误(superiority)', + }) + }) + }, + //获取投资环境分类 + getInvestAreaCategory() { + var _self = this + IndexService.doGetInvestAreaCategory() + .then(res => { + if (res) { + _self.setData({ + investAreaList: res + }) + _self.getInvestArea(_self.data.investAreaId) + } + }, err => { + wx.showToast({ + title: '网络错误(InvestCategory)', + }) + console.log(err) + }) }, //计算滚动框的宽度 countWidth() { @@ -124,6 +255,7 @@ Page({ lastScrollLeft: offsetLeft }) }, + //展开或收起简介 expandClick() { this.setData({ isExpand: !this.data.isExpand @@ -131,11 +263,11 @@ Page({ }, changeTab(e) { this.setData({ - curTab: e.currentTarget.dataset.index + investAreaId: e.currentTarget.dataset.id }) + this.getInvestArea(this.data.investAreaId) }, showYears() { - console.log('点击') this.setData({ showActionsheet: !this.data.showActionsheet }) @@ -151,6 +283,7 @@ Page({ showActionsheet: !this.data.showActionsheet, year: this.data.tempYear }) + this.getStatistics() }, //投资环境查看更多 areaShowAll() { @@ -167,135 +300,10 @@ Page({ tempYear: _self.data.years[index] }) }, - doRefresh() { - var _self = this; - console.log('刷新中...') - setTimeout(() => { - var tempList = []; - for (var i = 0; i < 30; i++) { - tempList.push("ssss") - } - _self.setData({ - list: tempList, - hasMore: true, - triggered: false - }) - }, 3000); - }, - onPageScroll(e) { - if (e.scrollTop < 10) { - this.setData({ - opacity: 1 - }) - } else { - this.setData({ - opacity: e.scrollTop / 100 - }) - } - if (e.scrollTop >= 130) { - this.setData({ - isFixed: true - }) - } else { - this.setData({ - isFixed: false - }) - } - }, - doLoadMore() { - var _self = this; - if (_self.data.isLoading || !_self.data.hasMore) { - return - } - console.log('触底了') - _self.setData({ - isLoading: true - }) - setTimeout(() => { - var tempList = [] - for (let i = 0; i < 20; i++) { - tempList.push(`新添加==${i}`) - } - var c = ++_self.data.count - console.log(`页面=${c}`) - _self.setData({ - count: c, - hasMore: c < 3 - }) - _self.setData({ - list: _self.data.list.concat(tempList), - isLoading: false - }) - }, 3000); - }, - bindViewTap() { - AuthService.login({ - name: '223', - pwd: '1234' - }) - .then(res => { - console.log(res) - }, err => { - console.log(err) - }) - }, - onChooseAvatar(e) { - const { - avatarUrl - } = e.detail - const { - nickName - } = this.data.userInfo - this.setData({ - "userInfo.avatarUrl": avatarUrl, - hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, - }) - }, - onInputChange(e) { - const nickName = e.detail.value - const { - avatarUrl - } = this.data.userInfo - this.setData({ - "userInfo.nickName": nickName, - hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, - }) - }, - getUserProfile(e) { - // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 - wx.getUserProfile({ - desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 - success: (res) => { - console.log(res) - this.setData({ - userInfo: res.userInfo, - hasUserInfo: true - }) - } - }) - }, - onTabClick(e) { - const index = e.detail.index - this.setData({ - activeTab: index - }) - }, - - onChange(e) { - const index = e.detail.index - this.setData({ - activeTab: index - }) - }, - handleClick(e) { - wx.navigateTo({ - url: './webview', - }) - }, //投资机会-全部 showInvest() { wx.navigateTo({ url: '/pages/invest/invest', }) - } + }, }) \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml index db89600..5c319df 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -2,26 +2,26 @@ - @@ -38,34 +38,15 @@ - - 生产总值 - - - 14亿 + + + {{item.name}} + + + {{item.value}}{{item.unit}} + - - - 工业总产值 - - - 1亿 - - - - 固定资产投资 - - - 1630.99万 - - - - 招商引资项目 - - - 40个 - - + @@ -74,28 +55,19 @@ 投资环境 - - - 地区概况 - + + + + + {{item.directoriesName}} + + + - - 资源条件 - - - - 气候条件 - - - - 基础设施 - - - + - - - 总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、 + + @@ -111,10 +83,10 @@ - + - - 电子信息 + + {{item.directoriesName}} @@ -130,39 +102,39 @@ 投资机会 - + - + - 达拉特旗小商品小食品加工园建设项目 + {{item.title}} 查看详情 > - 总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、 总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、小商品、总占地面积约100亩,总建筑面积约7万平方米。建设内容包括加工车间、展示营销中心、道路建设、地下室、人防、给排水管网、电力通信等,吸引全县小商品、 + 预计总投资 - 5000万元 + {{item.money}}{{item.moneyUnit}} 所属产业 - 生物产业 + {{item.type}} 占地面积 - 1亩 + {{item.area}}{{item.areaUnit}} 用地类型 - 商业用地 + {{item.landType}} diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 96990c9..aab6f9d 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -9,6 +9,7 @@ overflow: hidden; line-height: 1.5; font-size: 24rpx; + color: #6F6F6F; text-align: justify; max-height: calc(3em * 1.5); } @@ -131,24 +132,29 @@ .invest-tabs { display: flex; flex-direction: row; - justify-content: space-between; - margin-top: 20rpx; - align-items: center; + flex-wrap: nowrap; } -.tab-select { +.item-margin { display: flex; flex-direction: row; justify-content: center; align-items: center; +} + +.item-margin:nth-of-type(n+2) { + margin-left: 20rpx; +} + +.tab-select { font-size: 20rpx; color: white; - font-family: Source Han Sans CN; background-color: #256742; text-align: center; background: #256742; border-radius: 17rpx; padding: 5rpx 15rpx; + white-space: nowrap; } .tab-select image { @@ -159,17 +165,13 @@ } .tab-normal { - display: flex; - flex-direction: row; - justify-content: center; - align-items: center; font-size: 20rpx; color: #3F3F3F; - font-family: Source Han Sans CN; background: #EAEAEA; text-align: center; border-radius: 17rpx; padding: 5rpx 30rpx; + white-space: nowrap; } .tab-normal image { @@ -303,6 +305,10 @@ border-radius: 5rpx; } +.chance-item-box:nth-of-type(n+2) { + margin-top: 20rpx; +} + .chance-item-title { display: flex; flex-direction: row; @@ -378,7 +384,7 @@ .desc-video { width: 100%; - height: 315rpx; + height: 370rpx; border-radius: 10rpx; } diff --git a/utils/api/domainApi.js b/utils/api/domainApi.js new file mode 100644 index 0000000..7448fce --- /dev/null +++ b/utils/api/domainApi.js @@ -0,0 +1,23 @@ +import { + request +} from "../http"; + +// 管理地址 +const apiPath = { + domainCategory: "/news-directories/list?directoriesParentId=b04b4dc3-020a-4a9f-a567-464d27f70b19", //特色产业 + keyEnterprise: "/query/sql/q2984a0f", //重点企业 + domainInfo: "/news-content/listpage?newsDirectoriesId=2c76e2a0-37b2-4144-9d92-64376e5a22c3", //产业基础 +} +class DomainService { + static doGetDomainCategory() { + return request(apiPath.domainCategory, "GET") + } + static doGetKeyEnterprise() { + return request(apiPath.keyEnterprise, "GET") + } + static doGetDomainInfo() { + return request(apiPath.domainInfo, "GET") + } +} + +export default DomainService; \ No newline at end of file diff --git a/utils/api/indexApi.js b/utils/api/indexApi.js new file mode 100644 index 0000000..c864159 --- /dev/null +++ b/utils/api/indexApi.js @@ -0,0 +1,42 @@ +import { + request +} from "../http"; + +// 管理地址 +const apiPath = { + descVideo: "/news-content/listpage?newsDirectoriesId=9532d411-15c5-4c9c-8d73-e9f68a482702", + descInfo: "/news-content/listpage?newsDirectoriesId=91a98b33-1133-4935-8c4c-9b37cc5fe63b&rows=1&page=1", + statistics: "/query/sql/q9ce6963", + invest: "/query/sql/q428ea76", + investAreaInfo: "/news-content/listpage?rows=1&page=1", //地区概况 //资源条件 //气候条件 //基础设施 + categoryList: "/news-directories/list", //投资优势 投资环境 +} +class IndexService { + static doGetDescVideo() { + return request(apiPath.descVideo, "GET") + } + static doGetDescInfo() { + return request(apiPath.descInfo, "GET") + } + static doGetStatistics(data) { + return request(apiPath.statistics, "GET", data) + } + static doGetInvest() { + return request(apiPath.invest, "GET") + } + static doGetInvestArea(data) { + return request(apiPath.investAreaInfo, "GET", data) + } + static doGetSuperiorityList() { + return request(apiPath.categoryList, "GET", { + directoriesParentId: 'c7fa126e-1fa7-4cdb-b13a-2afb2f7b48e9' + }) + } + static doGetInvestAreaCategory() { + return request(apiPath.categoryList, "GET", { + directoriesParentId: 'd3ba3ff5-6d9e-4aed-9331-73e50b5ac598' + }) + } +} + +export default IndexService; \ No newline at end of file diff --git a/utils/http.js b/utils/http.js index ef42c1b..f71598e 100644 --- a/utils/http.js +++ b/utils/http.js @@ -1,6 +1,6 @@ // 定义api服务地址 -const baseUrl = 'http://dev.com:12345'; - +const baseUrl = 'http://106.74.34.136:8084/daqi/app'; +// https://8182018kg.goho.co/daqi/app/news-content/listpage?newsDirectoriesId=91a98b33-1133-4935-8c4c-9b37cc5fe63b&rows=1&page=1 /** * 传入请求参数,返回Promise支持链试调用 * @param url 请求地址 @@ -23,10 +23,10 @@ function request(url, method = "GET", data = {}, params = {}) { // if (params) { // url += "?" + urlEncode(params) // } - wx.showLoading({ - title: '加载中...', - mask: true //显示蒙层 - }) + // wx.showLoading({ + // title: '加载中...', + // mask: true //显示蒙层 + // }) wx.request({ url: baseUrl + url, timeout: 8000, @@ -35,24 +35,24 @@ function request(url, method = "GET", data = {}, params = {}) { dataType: "json", // 微信官方文档中介绍会对数据进行一次JSON.parse header, success(res) { - wx.hideLoading(); - console.log(res); + // wx.hideLoading(); // HTTP状态码为200才视为成功 if (res.statusCode === 200) { // 真正的数据响应体中还有一层success字段判断业务状态,按实际情况处理 - if (res.data.success) { - resolve(res.data.result) - } else { - // 业务判断错误 - reject(res) - } + resolve(res.data) + // if (res.data.success) { + // resolve(res.data.result) + // } else { + // // 业务判断错误 + // reject(res) + // } } else { // wx.request的特性,只要有响应就会走success回调,所以在这里判断状态,非200的均视为请求失败 reject(res) } }, fail(err) { - wx.hideLoading(); + // wx.hideLoading(); // 断网、服务器挂了都会fail回调,直接reject即可 reject(err) } diff --git a/utils/util.js b/utils/util.js index f89d2be..c925d4c 100644 --- a/utils/util.js +++ b/utils/util.js @@ -26,7 +26,61 @@ const formatNumber = n => { return n[1] ? n : '0' + n } +//随机生成暖色系 +const randomLightColor = () => { + // 暖色系的范围通常是红色和黄色较多,所以红色分量范围从 128 到 255 + let red = Math.floor(Math.random() * 128) + 128; + // 绿色分量范围从 64 到 255 + let green = Math.floor(Math.random() * 192) + 64; + // 蓝色分量范围从 0 到 128 + let blue = Math.floor(Math.random() * 128); + + // 将十进制的 RGB 分量转换为十六进制,并确保长度为 2 位 + let redHex = red.toString(16).padStart(2, '0'); + let greenHex = green.toString(16).padStart(2, '0'); + let blueHex = blue.toString(16).padStart(2, '0'); + + // 组合成十六进制颜色代码 + return '#' + redHex + greenHex + blueHex; +} +//随机生成冷色系 +const randomDarkColor = () => { + // 冷色系通常蓝色和绿色较多,所以蓝色分量范围从 128 到 255 + let blue = Math.floor(Math.random() * 128) + 128; + // 绿色分量范围从 128 到 255 + let green = Math.floor(Math.random() * 128) + 128; + // 红色分量范围从 0 到 128 + let red = Math.floor(Math.random() * 128); + + // 将十进制的 RGB 分量转换为十六进制,并确保长度为 2 位 + let redHex = red.toString(16).padStart(2, '0'); + let greenHex = green.toString(16).padStart(2, '0'); + let blueHex = blue.toString(16).padStart(2, '0'); + + // 组合成十六进制颜色代码 + return '#' + redHex + greenHex + blueHex; +} + +const randomRgbColor = () => { // 随机生成RGB颜色 + var r = Math.floor(Math.random() * 256); // 随机生成256以内r值 + var g = Math.floor(Math.random() * 256); // 随机生成256以内g值 + var b = Math.floor(Math.random() * 256); // 随机生成256以内b值 + return `rgb(${r},${g},${b})`; // 返回rgb(r,g,b)格式颜色 +} +const randomRgbaColor = () => { // 随机生成RGBA颜色 + var r = Math.floor(Math.random() * 256); // 随机生成256以内r值 + var g = Math.floor(Math.random() * 256); // 随机生成256以内g值 + var b = Math.floor(Math.random() * 256); // 随机生成256以内b值 + var alpha = Math.random(); // 随机生成1以内a值 + return `rgba(${r},${g},${b},${alpha})`; // 返回rgba(r,g,b,a)格式颜色 +} + + module.exports = { formatTime: formatTime, - formatDate: formatDate + formatDate: formatDate, + randomRgb: randomRgbColor, + randomRgba: randomRgbaColor, + randomDark: randomDarkColor, + randomLight: randomLightColor } \ No newline at end of file