Commit 43443090 by 柳士祥

小程序文章优化

parent 5c717289
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<div class="title_time">{{article.createDatetime}}</div> <div class="title_time">{{article.createDatetime}}</div>
</div> </div>
<div v-html="article.content" v-if="!article.msg"></div> <div v-html="article.content" v-if="!article.msg"></div>
<!-- <rich-text :datas="datas" v-if="!article.msg"></rich-text> -->
<div class="title" style="min-height: 50vh;color: #999;align-items: center;display: flex;justify-content: center;" v-else>{{article.msg}}</div> <div class="title" style="min-height: 50vh;color: #999;align-items: center;display: flex;justify-content: center;" v-else>{{article.msg}}</div>
</div> </div>
<div style="width:100%;height:10px;background-color:#EEF2F5;"></div> <div style="width:100%;height:10px;background-color:#EEF2F5;"></div>
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
<script> <script>
import article from '@/api/article' import article from '@/api/article'
import shadeGuide from "./shadeGuide.vue"; import shadeGuide from "./shadeGuide.vue";
import richText from "../../../components/basicTool/rich-text/index.vue";
const app = getApp(); const app = getApp();
const { log } = app; const { log } = app;
export default { export default {
...@@ -69,11 +70,15 @@ export default { ...@@ -69,11 +70,15 @@ export default {
query: { query: {
pageNum: 0, pageNum: 0,
pageSize: 20, pageSize: 20,
},
datas: {
componentData: {}
} }
} }
}, },
components: { components: {
"shade-guide": shadeGuide, "shade-guide": shadeGuide,
"rich-text": richText
}, },
created() { created() {
}, },
...@@ -105,13 +110,32 @@ export default { ...@@ -105,13 +110,32 @@ export default {
} }
}, },
methods: { methods: {
formatRichText(html) {
console.log(html,'html');
let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match;
});
newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
return match;
});
newContent = newContent.replace(/<br[^>]*\/>/gi, '');
newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"');
return newContent
},
init() { init() {
log.info('qq'); log.info('qq');
article.getArticleInfo(this.articleId).then(res => { article.getArticleInfo(this.articleId).then(res => {
if (res.data.data) { if (res.data.data) {
let article = res.data.data let article = res.data.data
let content = res.data.data.content.replace("<body>", "").replace("</body>", "") let content = res.data.data.content.replace("<body>", "").replace("</body>", "")
article.content = content article.content = this.formatRichText(content)
this.datas.componentData['padding'] = 0
this.datas.componentData['richText'] = content
this.datas.componentData['backgroundColor'] = '#fff'
this.article = article this.article = article
// this.createDatetime = article.createDatetime != '' ? article.createDatetime.slice(0,-3):'' // this.createDatetime = article.createDatetime != '' ? article.createDatetime.slice(0,-3):''
// log.info(this.createDatetime,'article.createDatetime'); // log.info(this.createDatetime,'article.createDatetime');
...@@ -264,8 +288,9 @@ export default { ...@@ -264,8 +288,9 @@ export default {
.title_info { .title_info {
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: 0 12px; // padding: 0 12px;
font-size: 13px; font-size: 13px;
margin-bottom: 12px;
} }
.title_user { .title_user {
width: 100%; width: 100%;
...@@ -273,7 +298,7 @@ export default { ...@@ -273,7 +298,7 @@ export default {
} }
.title_time { .title_time {
width: 100%; width: 100%;
padding-right: 13px; // padding-right: 13px;
text-align: right; text-align: right;
color: #999; color: #999;
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
<script> <script>
import { formatTime } from "@/utils/index"; import { formatTime } from "@/utils/index";
import wxPay from "@/api/wxPay"; import wxPay from "@/api/wxPay";
const app = getApp();
const { log } = app;
export default { export default {
components: { components: {
// card // card
...@@ -30,14 +32,14 @@ export default { ...@@ -30,14 +32,14 @@ export default {
title: "加载中", title: "加载中",
}); });
Object.assign(this.$data, this.$options.data()); //mpvue 的混合周期 使用小程序生命周期数据未初始化 Object.assign(this.$data, this.$options.data()); //mpvue 的混合周期 使用小程序生命周期数据未初始化
console.log("onload//", options); log.info("onload//", options);
if (options.batchNumber) { if (options.batchNumber) {
let ordercode = JSON.parse(options.ordercode); let ordercode = JSON.parse(options.ordercode);
ordercode.orderSn = ""; ordercode.orderSn = "";
ordercode.batchNumber = options.batchNumber; ordercode.batchNumber = options.batchNumber;
this.options = ordercode; this.options = ordercode;
this.batchNumber = ordercode.batchNumber; this.batchNumber = ordercode.batchNumber;
console.log(JSON.parse(options.ordercode).orderSn); log.info(JSON.parse(options.ordercode).orderSn);
if (JSON.parse(options.ordercode).orderSn) { if (JSON.parse(options.ordercode).orderSn) {
this.totalMoney = Number( this.totalMoney = Number(
JSON.parse(options.ordercode).orderSn.totalAmount JSON.parse(options.ordercode).orderSn.totalAmount
...@@ -49,7 +51,7 @@ export default { ...@@ -49,7 +51,7 @@ export default {
} }
// } // }
console.log(this.totalMoney, "totalMoney"); log.info(this.totalMoney, "totalMoney");
} else { } else {
this.options = JSON.parse(options.ordercode); this.options = JSON.parse(options.ordercode);
options.scene && (this.scene = options.scene); options.scene && (this.scene = options.scene);
...@@ -68,15 +70,15 @@ export default { ...@@ -68,15 +70,15 @@ export default {
wx.getStorage({ wx.getStorage({
key: "openid", key: "openid",
success(res) { success(res) {
console.log(that.options, "++++"); log.info(that.options, "++++");
console.log(res, "openid"); log.info(res, "openid");
that.options.openId = res.data; that.options.openId = res.data;
that.options.tradeType = "Mini"; that.options.tradeType = "Mini";
console.log("支付开始", that.options); log.info("支付开始", that.options);
that.toPay(); that.toPay();
}, },
fail(err) { fail(err) {
console.log("获取err", err); log.info("获取err", err);
}, },
}); });
}, },
...@@ -88,9 +90,9 @@ export default { ...@@ -88,9 +90,9 @@ export default {
wx.hideLoading(); wx.hideLoading();
if (res.data.code == 200) { if (res.data.code == 200) {
let payData = JSON.parse(res.data.data); let payData = JSON.parse(res.data.data);
console.log("wxPay", res.data); log.info("wxPay", res.data);
payData.success = (res) => { payData.success = (res) => {
console.log("支付成功", res, this.options); log.info("支付成功", res, this.options);
this.message = "支付成功"; this.message = "支付成功";
const orderSn = this.options.orderSn; const orderSn = this.options.orderSn;
let vm = this; let vm = this;
...@@ -123,18 +125,18 @@ export default { ...@@ -123,18 +125,18 @@ export default {
tmplIds: tmplIds, tmplIds: tmplIds,
success(res) { success(res) {
fn(vm); fn(vm);
console.log("message success response: ", res); log.info("message success response: ", res);
}, },
fail(res) { fail(res) {
fn(vm); fn(vm);
console.log("message fail response: ", res); log.info("message fail response: ", res);
}, },
}); });
} else { } else {
fn(vm); fn(vm);
} }
} else { } else {
console.log("来这里了"); log.info("来这里了");
fn(this); fn(this);
} }
} catch (err) { } catch (err) {
...@@ -184,19 +186,19 @@ export default { ...@@ -184,19 +186,19 @@ export default {
} }
}; };
payData.fail = (res) => { payData.fail = (res) => {
console.log("支付失败", res, this.options.orderSn); log.info("支付失败", res, this.options.orderSn);
this.message = "支付失败"; this.message = "支付失败";
if ((res.errMsg = "requestPayment:fail cancel")) { if ((res.errMsg = "requestPayment:fail cancel")) {
wxPay.cancelPayment(this.options.orderSn).then(() => { wxPay.cancelPayment(this.options.orderSn).then(() => {
console.log("取消成功"); log.info("取消成功");
}); });
} }
this.toPage(); this.toPage();
}; };
payData.complete = (res) => { payData.complete = (res) => {
console.log("支付completa", res, this.options.orderSn); log.info("支付completa", res, this.options.orderSn);
// if (res.errMsg == "requestPayment:fail cancel") { // if (res.errMsg == "requestPayment:fail cancel") {
// console.log("支付取消", this.options); // log.info("支付取消", this.options);
// this.message = "支付取消"; // this.message = "支付取消";
// this.toPage(); // this.toPage();
// } // }
...@@ -211,7 +213,7 @@ export default { ...@@ -211,7 +213,7 @@ export default {
}); });
}, },
toPage() { toPage() {
console.log( log.info(
"支付失败来这里了", "支付失败来这里了",
this.backUrl, this.backUrl,
this.batchNumber, this.batchNumber,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment