| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <template>
- <view>
- <artical-deatil :model="model" :enclosureIds="enclosureId"></artical-deatil>
- </view>
- </template>
- <script>
- import md5 from "@/common/md5.js";
- import ArticalDeatil from "../../components/artical-deatil/index";
- export default {
- data() {
- return {
- model: {
- title: "",
- way: "",
- time: "",
- artical: "",
- id: "",
- },
- enclosureId:'',
- };
- },
- components: {
- ArticalDeatil,
- },
- onLoad(op) {
- this.model.id = op.id;
- this.getNotice();
- },
- methods: {
- getNotice() {
- let md5Sign = md5(
- "method=" +
- "common" +
- "×tamp=" +
- getApp().globalData.globalTimestamp +
- "&secret=" +
- getApp().globalData.secret
- );
- let url =
- getApp().globalData.shareUrl +
- "api/api.php" +
- "?method=common&source=notice&action=info_by_id×tamp=" +
- getApp().globalData.globalTimestamp +
- "&sign=" +
- md5Sign;
- let postData = {
- id: this.model.id,
- };
- //获取文章
- uni.request({
- url: url,
- method: "POST",
- header: {
- "content-type": "application/x-www-form-urlencoded",
- },
- data: postData,
- success: (res) => {
- if (res.data.code === 200) {
- let data = res.data.data;
- this.model.title = data.title;
- this.model.way = data.sponsor;
- this.enclosureId = data.attach_ids;
- console.log(this.enclosureId)
- let time = this.$options.filters["globalTime"](data.publish_time);
- let timeSecond = this.$options.filters["globalTimeSecond"](
- data.publish_time
- );
- this.model.time = time + " " + timeSecond;
- this.getRich();
- }
- },
- fail: () => {
- console.log("连接失败");
- },
- });
- },
- replaceImg(html) {
- let result = html.replace(
- /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
- function (match, capture) {
- if(capture.includes('http')){
- return (
- "<img src=" +
- capture +
- ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
- );
- }else {
- return (
- "<img src=" +
- getApp().globalData.shareUrl +
- capture +
- ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
- );
- }
- }
- );
- return result;
- },
- getRich() {
- uni.request({
- url:getApp().globalData.shareUrl + `content/notice/${Math.floor(this.model.id / 1000)}/${this.model.id}.html`+'?version='+ Math.random(),
- method: "GET",
- header: {
- "content-type": "application/x-www-form-urlencoded",
- },
- success: (res) => {
- if (res.statusCode === 200) {
- this.model.artical = this.replaceImg(res.data);
- }
- },
- fail: () => {
- console.log("连接失败");
- },
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- </style>
|