12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- require("../../utils/request.js");
- const common_config = require("../../common/config.js");
- const _sfc_main = {
- data() {
- return {
- agreementContent: "",
- loading: true,
- error: false,
- errorMsg: "加载失败,请重试"
- };
- },
- computed: {
- parsedContent() {
- if (!this.agreementContent)
- return "";
- return this.parseMarkdown(this.agreementContent);
- }
- },
- onLoad() {
- this.fetchAgreement();
- },
- methods: {
- // 简单的 markdown 解析函数
- parseMarkdown(markdown) {
- if (!markdown)
- return "";
- let html = markdown.replace(/^### (.*$)/gim, "<h3>$1</h3>").replace(/^## (.*$)/gim, "<h2>$1</h2>").replace(/^# (.*$)/gim, "<h1>$1</h1>").replace(/\*\*(.*)\*\*/gim, "<strong>$1</strong>").replace(/\*(.*)\*/gim, "<em>$1</em>").replace(/\[([^\]]*)\]\(([^\)]*)\)/gim, '<a href="$2">$1</a>').replace(/```(.*?)```/gims, "<pre><code>$1</code></pre>").replace(/`([^`]*)`/gim, "<code>$1</code>").replace(/^\* (.*$)/gim, "<li>$1</li>").replace(/^\d+\. (.*$)/gim, "<li>$1</li>").replace(/\n\n/gim, "</p><p>").replace(/\n/gim, "<br>");
- html = html.replace(/(<li>.*<\/li>)/gim, "<ul>$1</ul>");
- if (html && !html.startsWith("<h") && !html.startsWith("<ul") && !html.startsWith("<ol")) {
- html = "<p>" + html + "</p>";
- }
- return html;
- },
- goBack() {
- common_vendor.index.navigateBack();
- },
- async fetchAgreement() {
- this.loading = true;
- this.error = false;
- const res = await common_vendor.index.request({
- url: `${common_config.apiBaseUrl}/api/public/agreements/terms_of_service/`,
- method: "GET"
- });
- console.log(res);
- if (res.statusCode == 200) {
- this.loading = false;
- this.agreementContent = res.data.content || "";
- }
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $data.loading
- }, $data.loading ? {} : $data.error ? {
- c: common_vendor.t($data.errorMsg),
- d: common_vendor.o((...args) => $options.fetchAgreement && $options.fetchAgreement(...args))
- } : {
- e: $options.parsedContent
- }, {
- b: $data.error
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|