diff --git a/common/api.js b/common/api.js index 4a61a53..322eafb 100644 --- a/common/api.js +++ b/common/api.js @@ -25,6 +25,12 @@ export const API_ADVICEDETAILS = '/api/agent_product/show'; //推荐列表详情 export const API_PRODUCTLIST = '/api/channel/product'; //频道产品列表 export const API_SPECIALLIST = '/api/special/show'; //专题列表 +export const API_NOTICEDETAILS = '/api/notice/show'; //公告详情 + +export const API_REGISTERAGREE = '/api/agent_info/reg_protocol'; //注册协议 +export const API_BUYAGREE = '/api/agent_info/buy_protocol'; //购买协议 + + export const API_MESSAGELIST = '/api/message/list'; //消息列表 @@ -34,8 +40,14 @@ export const API_CHECKNEWS = '/api/message/read'; //消息标记为已读 export const API_RECOMMOND = '/api/agent_product/recommend'; //我的推荐列表 +//用户信息 +export const API_GETUSERINFO = '/api/user/profile'; //获取用户消息 + //订单 export const API_ORDERLIST = '/api/order/list'; //订单列表 +export const API_ORDER_DETAILS = '/api/order/show'; //订单详情 +export const API_APPLYREFUND = '/api/order/refund'; //申请退款 +export const API_UPPLOAD_APPLY = '/api/upload/image'//退款申请图片上传 //系统 diff --git a/common/mixin.js b/common/mixin.js index e48c468..99cef88 100644 --- a/common/mixin.js +++ b/common/mixin.js @@ -88,6 +88,36 @@ export default{ }else{ uni.switchTab({url:'/pages/index/index'}); } - } + }, + $timer(value, fmt) { + if(!value) return; + let newTime = new Date(value) + if(!fmt){ + fmt = 'yyyy-MM-dd hh:mm'; + } + if(/(y+)/.test(fmt)) { + fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length)); + } + let o = { + 'M+': newTime.getMonth() + 1, + 'd+': newTime.getDate(), + 'h+': newTime.getHours(), + 'm+': newTime.getMinutes(), + 's+': newTime.getSeconds() + }; + function padLeftZero(str) { + return ('00'+str).substr(str.length); + } + // 遍历这个对象 + for (let k in o) { + if (new RegExp(`(${k})`).test(fmt)) { + // console.log(`${k}`) + let str = o[k] + ''; + fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)); + } + } + return fmt; + }, + } } \ No newline at end of file diff --git a/common/uploadFile.js b/common/uploadFile.js new file mode 100644 index 0000000..69c50bf --- /dev/null +++ b/common/uploadFile.js @@ -0,0 +1,77 @@ +/* + *上传文件 + *@param - filePath :图片的本地资源路径 + *@param - dir:表示要传到哪个目录下 + *@param - successc:成功回调 + *@param - failc:失败回调 + */ +const uploadFile = function (filePath, successc, failc) { + if (!filePath || filePath.length < 9) { + wx.showModal({ + title: '图片错误', + content: '请重试', + showCancel: false, + }) + return; + } + + // 上传的服务器地址 + let url = this.API.DEVURL; + if (this.API.DEV == 'prod') { + url = this.API.PRODURL; + } + const url_a = this.API.API_UPPLOAD_APPLY; + + // 上传图片的目录 + var nowTime = formatTime(new Date()); + const dir = 'wxmini/images/' + nowTime + '/'; + + // 获取上传的文件类型 fileType + let fileTypeIndex = filePath.lastIndexOf('.'); + let fileType = filePath.substring(fileTypeIndex); + + console.log('上传方法的图片',filePath) + + uni.uploadFile({ + url: url + url_a,//开发者服务器 url + filePath: filePath,//要上传文件资源的路径 + name: 'image', + header: { + appid: 'wx0e8ebcd9ca9e4b97', + Authentication: uni.getStorageSync('userinfo').token + }, + + success: function (res) { + console.log('上传文件...', res) + if (res.statusCode != 200 || !res.data) { + failc(new Error('上传错误:' + JSON.stringify(res))) + return; + } + let res_data = JSON.parse(res.data); + successc && successc(res_data.data); + }, + fail: function (err) { + failc(err); + }, + }) +} + +// 获取当前日期(年-月-日),并不足十位补零 +function formatTime(date) { + const year = date.getFullYear() + const month = date.getMonth() + 1 + const day = date.getDate() + const hour = date.getHours() + const minute = date.getMinutes() + const second = date.getSeconds() + return [year, month, day].map(formatNumber).join('-') + // + ' ' + [hour, minute, second].map(formatNumber).join(':') +} +const formatNumber = n => { + n = n.toString() + return n[1] ? n : '0' + n +} + +module.exports = { + uploadFile +}; \ No newline at end of file diff --git a/main.js b/main.js index 6c139c5..fe46c6f 100644 --- a/main.js +++ b/main.js @@ -3,6 +3,7 @@ import App from './App'; import mixin from '@/common/mixin.js'; import * as API from '@/common/api.js'; import * as $shared from '@/common/shared.js'; +import { uploadFile } from '@/common/uploadFile.js' Vue.config.productionTip = false; @@ -14,6 +15,9 @@ Vue.mixin(mixin); Vue.prototype.API = API; // 全局共享方法 Vue.prototype.$shared = $shared; + +Vue.prototype.uploadFile = uploadFile + // 引入全局uView import uView from 'uview-ui'; Vue.use(uView); diff --git a/pages.json b/pages.json index b7af771..e298fa4 100644 --- a/pages.json +++ b/pages.json @@ -125,6 +125,18 @@ "navigationBarTitleText": "关于我们" } }, + { + "path": "pages/about/register_agree", + "style": { + "navigationBarTitleText": "注册协议" + } + }, + { + "path": "pages/about/buy_agree", + "style": { + "navigationBarTitleText": "购买协议" + } + }, { "path": "pages/channel/index", "style": { diff --git a/pages/about/buy_agree.vue b/pages/about/buy_agree.vue new file mode 100644 index 0000000..9f9a8fa --- /dev/null +++ b/pages/about/buy_agree.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/pages/about/register_agree.vue b/pages/about/register_agree.vue new file mode 100644 index 0000000..fbd3265 --- /dev/null +++ b/pages/about/register_agree.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/pages/collect/index.vue b/pages/collect/index.vue index dac5d56..fea6d94 100644 --- a/pages/collect/index.vue +++ b/pages/collect/index.vue @@ -5,7 +5,7 @@ {{ item.product.title }} - {{ timer(item.created_at*1000) || '' }} + {{ $timer(item.created_at*1000) || '' }} @@ -95,39 +95,7 @@ // 进入商品详情页 enterDetail(id){ this.$url('/pages/goodsDetail/index?goods_id='+ id); - }, - timer(value, fmt) { - if(!value) return; - let newTime = new Date(value) - if(!fmt){ - fmt = 'yyyy-MM-dd hh:mm'; - } - if(/(y+)/.test(fmt)) { - fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length)); - } - let o = { - 'M+': newTime.getMonth() + 1, - 'd+': newTime.getDate(), - 'h+': newTime.getHours(), - 'm+': newTime.getMinutes(), - 's+': newTime.getSeconds() - }; - - function padLeftZero(str) { - return ('00'+str).substr(str.length); - } - - // 遍历这个对象 - for (let k in o) { - if (new RegExp(`(${k})`).test(fmt)) { - // console.log(`${k}`) - let str = o[k] + ''; - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)); - } - } - return fmt; - }, - + } }, onReachBottom(){ if(this.isPage){ diff --git a/pages/goodsDetail/index.vue b/pages/goodsDetail/index.vue index bbb495c..1ddde8d 100644 --- a/pages/goodsDetail/index.vue +++ b/pages/goodsDetail/index.vue @@ -115,7 +115,7 @@ this.$http(this.API.API_ADVICEDETAILS, {id: this.goods_id}).then(res => { this.skeletonLoading = false; this.goods_detail = res.data; - // this.is_collect = Boolean(res.data.user.is_collect) || false; + this.is_collect = Boolean(res.data.is_collect) || false; }).catch(err => { this.skeletonLoading = false; setTimeout(() => { @@ -132,7 +132,7 @@ } this.$http(this.API.API_COLLECT_DEAL, {goods_id: this.goods_id}).then(res => { this.$msg(res.msg); - this.is_collect = Boolean(res.data.user.is_collect); + this.is_collect = Boolean(res.data.is_collect); }) }, // 拨打电话 diff --git a/pages/index/index.vue b/pages/index/index.vue index 1c8fb21..003eefd 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -12,7 +12,7 @@ {{item.title}} - 详情 + 详情 diff --git a/pages/login/index.vue b/pages/login/index.vue index e6ddb9b..079f53f 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -23,15 +23,15 @@ - + 请认真阅读并同意 - 《{{ agreement.title }}》 + 《用户协议》 ,在小程序下单购买即表示您已默认同意 - 《{{ agreement.title }}》 + 《用户协议》 的所有条款。 @@ -51,21 +51,14 @@ }, onLoad(options){ this.type = options.type || this.type; - this.getAgree(); getApp().globalData.wxlogin().then(res => { this.userInfo = res; }); }, methods: { - // 获取协议 - getAgree(){ - this.$http(this.API.API_WXLOGIN_VIEW).then(res => { - this.agreement = res.data?.agreement; - }) - }, // 进入查看协议 enterAgree(){ - this.$url('/pages/agreement/agreement?id='+ this.agreement.article_id); + this.$url('/pages/about/register_agree'); }, // 勾选协议发生变化 checkboxChange(event){ @@ -73,12 +66,13 @@ }, // 微信快捷登录获取手机号 getPhoneNumber(event){ + console.log('=====',this.API.API_GETUSERINFO) console.log(event); if(event.detail.errMsg == 'getPhoneNumber:ok'){ let encryptedData = event.detail.encryptedData; let iv = event.detail.iv; // let userInfo = uni.getStorageSync('userinfo') || {}; - this.$http(this.API.API_WECHAT_SETPHONE, { + this.$http(this.API.API_GETUSERINFO, { encryptedData, iv, // token: userInfo.token // 已在公共参数传 @@ -105,7 +99,7 @@ let signature = result.signature; // let userInfo = uni.getStorageSync('userinfo') || {}; - this.$http(this.API.API_WECHAT_SETPROFILE, { + this.$http(this.API.API_GETUSERINFO, { encryptedData, iv, // token: userInfo.token // 已在公共参数传 diff --git a/pages/message/index.vue b/pages/message/index.vue index db2c990..139d957 100644 --- a/pages/message/index.vue +++ b/pages/message/index.vue @@ -7,7 +7,7 @@ 收到一条新消息 - {{timer(item.created_at*1000) || ''}} + {{$timer(item.created_at*1000) || ''}} {{item.title}} @@ -36,35 +36,6 @@ this.getMessageList() }, methods: { - timer(value, fmt) { - if(!value) return; - let newTime = new Date(value) - if(!fmt){ - fmt = 'yyyy-MM-dd hh:mm'; - } - if(/(y+)/.test(fmt)) { - fmt = fmt.replace(RegExp.$1, (newTime.getFullYear() + '').substr(4 - RegExp.$1.length)); - } - let o = { - 'M+': newTime.getMonth() + 1, - 'd+': newTime.getDate(), - 'h+': newTime.getHours(), - 'm+': newTime.getMinutes(), - 's+': newTime.getSeconds() - }; - function padLeftZero(str) { - return ('00'+str).substr(str.length); - } - // 遍历这个对象 - for (let k in o) { - if (new RegExp(`(${k})`).test(fmt)) { - // console.log(`${k}`) - let str = o[k] + ''; - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)); - } - } - return fmt; - }, goDetails(id) { this.$url('/pages/message/detail?news_id='+id) }, diff --git a/pages/notice/notice.vue b/pages/notice/notice.vue index 8186775..174ab79 100644 --- a/pages/notice/notice.vue +++ b/pages/notice/notice.vue @@ -11,15 +11,17 @@ export default { data(){ return { - content: '' + content: '', + notice_id: 0 } }, - onLoad(){ - // this.getData(); + onLoad(e){ + this.notice_id = e.notice_id + this.getData(); }, methods: { getData(){ - this.$http(this.API.API_ARTICLE_QA).then(res => { + this.$http(this.API.API_NOTICEDETAILS,{id:this.notice_id}).then(res => { this.content = res.data?.content; }) } diff --git a/pages/order/apply_refund.vue b/pages/order/apply_refund.vue index 0d1aa15..7db712c 100644 --- a/pages/order/apply_refund.vue +++ b/pages/order/apply_refund.vue @@ -1,22 +1,22 @@