Newer
Older
XiaoGanWXMini / unpackage / dist / dev / mp-weixin / pages / news / detail.js
@zhangdeliang zhangdeliang on 29 Jul 3 KB 迁移
"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_homeApi = require("../../utils/homeApi.js");
const _sfc_main = {
  __name: "detail",
  setup(__props) {
    const ifStar = common_vendor.ref(0);
    const detialData = common_vendor.ref({});
    const titleAr = common_vendor.ref("");
    function collect(type) {
      if (titleAr.value == "科普知识") {
        let params = {
          knowledgeConfigId: detialData.value.id,
          wechatMiniuserId: common_vendor.index.getStorageSync("userIdXGWXMN")
        };
        if (ifStar.value == 0) {
          utils_homeApi.knowledgeCollectAdd(params).then((res) => {
            ifStar.value = 1;
          });
        } else {
          utils_homeApi.knowledgeCollectCancel(params).then((res) => {
            ifStar.value = 0;
          });
        }
      } else {
        let params = {
          articleId: detialData.value.id,
          wechatMiniuserId: common_vendor.index.getStorageSync("userIdXGWXMN")
        };
        if (ifStar.value == 0) {
          utils_homeApi.articleCollectAdd(params).then((res) => {
            ifStar.value = 1;
          });
        } else {
          utils_homeApi.articleCollectCancel(params).then((res) => {
            ifStar.value = 0;
          });
        }
      }
    }
    function getDataDetail(id) {
      utils_homeApi.articleConfigDetail(id, { wechatMiniuserId: common_vendor.index.getStorageSync("userIdXGWXMN") }).then((res) => {
        let datas = res.data;
        datas.content = datas.content.replace(/\<img/gi, '<img class="richImgs" style="width:100%;" ');
        detialData.value = datas;
        ifStar.value = datas.collectStatus;
      });
    }
    function getKnowledgeDetail(id) {
      utils_homeApi.knowledgeConfigDetail(id, { wechatMiniuserId: common_vendor.index.getStorageSync("userIdXGWXMN") }).then((res) => {
        let datas = res.data;
        datas.content = datas.content.replace(/\<img/gi, '<img class="richImgs" style="width:100%;" ');
        detialData.value = datas;
        ifStar.value = datas.collectStatus;
      });
    }
    common_vendor.onLoad((option) => {
      common_vendor.index.setNavigationBarTitle({
        title: option.title + "详情"
      });
      titleAr.value = option.title;
      if (option.title == "科普知识") {
        getKnowledgeDetail(option.id);
      } else {
        getDataDetail(option.id);
      }
    });
    common_vendor.onShareAppMessage((res) => {
      return {
        title: "转发给朋友",
        path: "/pages/news/detail"
      };
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.t(detialData.value.title),
        b: common_vendor.t(detialData.value.createTime),
        c: ifStar.value == 0
      }, ifStar.value == 0 ? {
        d: common_vendor.o(($event) => collect())
      } : {}, {
        e: ifStar.value == 1
      }, ifStar.value == 1 ? {
        f: common_vendor.o(($event) => collect())
      } : {}, {
        g: detialData.value.content
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "E:/项目/孝感海绵城市/XiaoGanWXMini/pages/news/detail.vue"]]);
_sfc_main.__runtimeHooks = 2;
wx.createPage(MiniProgramPage);