diff --git a/common/shared.js b/common/shared.js index 043dfaf..d3f334e 100644 --- a/common/shared.js +++ b/common/shared.js @@ -24,4 +24,41 @@ export function isRight(obj) { export function isValueType(value) { let str = Object.prototype.toString.call(value); return str.match(/\[object (.*?)\]/)[1].toLowerCase(); -} \ No newline at end of file +} + +export const 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; +} +// 位数不足2,前面补0 +var cover = function(par) { + par = par.toString()[1] ? par : "0" + par; + return par; +}; \ No newline at end of file diff --git a/pages/message/detail.vue b/pages/message/detail.vue index 74a5e74..90f7056 100644 --- a/pages/message/detail.vue +++ b/pages/message/detail.vue @@ -11,16 +11,21 @@ export default { data(){ return { - content: '' + content: '', + news_id: 0 } }, - onLoad(){ - // this.getData(); + onLoad(e){ + this.news_id = e.news_id + if(this.news_id) { + this.getData(); + } }, methods: { getData(){ - this.$http(this.API.API_ARTICLE_QA).then(res => { + this.$http(this.API.API_MESSAGEDETAILS,{id: this.news_id}).then(res => { this.content = res.data?.content; + console.log(this.content) }) } } diff --git a/pages/notice/article.vue b/pages/notice/article.vue index 8186775..df4d420 100644 --- a/pages/notice/article.vue +++ b/pages/notice/article.vue @@ -11,16 +11,21 @@ export default { data(){ return { - content: '' + content: '', + article_id: 0 } }, - onLoad(){ - // this.getData(); + onLoad(e){ + this.article_id = e.article_id + if(this.article_id) { + this.getData(); + } }, methods: { getData(){ - this.$http(this.API.API_ARTICLE_QA).then(res => { + this.$http(this.API.API_FINDARTICLEDETAILS,{id: this.article_id}).then(res => { this.content = res.data?.content; + console.log(this.content) }) } }