collection.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta
  6. name="viewport"
  7. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
  8. />
  9. <title></title>
  10. <script src="./vue.min.js"></script>
  11. <style>
  12. body {
  13. margin: 0;
  14. }
  15. #app {
  16. min-width: 100vw;
  17. height: 100vh;
  18. background: #f7f1e6;
  19. box-sizing: border-box;
  20. overflow: hidden;
  21. }
  22. .top {
  23. width: 100%;
  24. height: 65%;
  25. }
  26. .top > iframe {
  27. width: 100%;
  28. height: 100%;
  29. }
  30. .bottom {
  31. position: absolute;
  32. top: calc(65% - 30px);
  33. width: 100%;
  34. min-height: 40vh;
  35. background: #f7f1e6;
  36. border-radius: 30px 30px 0px 0px;
  37. box-shadow: 0px -4px 4px 0px rgba(0, 0, 0, 0.2);
  38. padding: 20px;
  39. display: flex;
  40. flex-direction: column;
  41. align-items: center;
  42. box-sizing: border-box;
  43. }
  44. .title {
  45. font-weight: bold;
  46. }
  47. .content {
  48. white-space: pre-wrap;
  49. font-size: 14px !important;
  50. line-height: 25px !important;
  51. }
  52. .bottom > p {
  53. text-indent: 2em;
  54. font-size: 12px;
  55. overflow: auto;
  56. }
  57. .previewImg {
  58. width: 100vw;
  59. height: 100vh;
  60. z-index: 9999;
  61. background: #000000be;
  62. position: fixed;
  63. top: 0;
  64. left: 0;
  65. display: flex;
  66. align-items: center;
  67. }
  68. .previewImg > img {
  69. width: 100vw;
  70. }
  71. .levitated-box {
  72. background-color: #00000080;
  73. border-radius: 50px;
  74. width: 50px;
  75. height: 50px;
  76. box-sizing: border-box;
  77. position: fixed;
  78. right: 10px;
  79. top: 50vh;
  80. z-index: 999;
  81. padding: 10px;
  82. }
  83. .levitated-box > img {
  84. width: 100%;
  85. height: 100%;
  86. }
  87. </style>
  88. <style></style>
  89. </head>
  90. <body>
  91. <div id="app" v-if="JSON.stringify(info) != '{}'">
  92. <div class="top">
  93. <!-- <iframe
  94. src="https://4dscene.4dage.com/culturalrelics/YFYCM2/Model2.html?m=yfyc204"
  95. ></iframe> -->
  96. <iframe :src="info.modelUrl"></iframe>
  97. </div>
  98. <div class="bottom">
  99. <span class="title">{{info.name}}</span>
  100. <!-- <rich-text :nodes="info.content"></rich-text> -->
  101. <div class="content" v-html="info.content" @click="showImg"></div>
  102. </div>
  103. <!-- 富文本中图片放大预览部分 -->
  104. <div class="previewImg" @click="imgShowHandler" v-show="imgShow">
  105. <img :src="previewImg" alt="" />
  106. </div>
  107. <div class="levitated-box">
  108. <img
  109. width="40px"
  110. height="40px"
  111. :src="`https://houseoss.4dkankan.com/project/bjfljtl/img/bottomInco/collectIcon${isCollectedInfo ? 'Ac' : ''}.png`"
  112. @click="collecttion"
  113. />
  114. </div>
  115. </div>
  116. <!-- 微信的SDK -->
  117. <script
  118. type="text/javascript"
  119. src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"
  120. ></script>
  121. <!-- uni 的 SDK -->
  122. <script
  123. type="text/javascript"
  124. src="https://unpkg.com/@dcloudio/uni-webview-js@0.0.3/index.js"
  125. ></script>
  126. <script src="./axios.min.js"></script>
  127. <script>
  128. var app = new Vue({
  129. el: "#app",
  130. data() {
  131. return {
  132. info: {},
  133. isCollectedInfo: false,
  134. previewImg: "",
  135. imgShow: false,
  136. };
  137. },
  138. mounted() {},
  139. beforCreat() {},
  140. created() {
  141. let _this = this;
  142. const params = this.urlParameter(window.location.href);
  143. console.log(params, parseInt(params.isCollected) == "1");
  144. this.isCollectedInfo =
  145. parseInt(params.isCollected) == "1" ? true : false;
  146. console.log(this.isCollectedInfo);
  147. axios({
  148. method: "get",
  149. url: `https://wxfalangchang.4dage.com/api/wxShow/goods/detail/${params.id}`,
  150. }).then(function (resp) {
  151. _this.info = resp.data.data;
  152. _this.info.content = _this.formatRichText(_this.info.content);
  153. });
  154. },
  155. watch: {
  156. info: {
  157. handler(newValue, oldValue) {
  158. console.log("刷新", newValue, oldValue);
  159. },
  160. immediate: true,
  161. deep: true,
  162. },
  163. },
  164. methods: {
  165. // v-html模块点击
  166. showImg(e) {
  167. if (e.target.tagName == "IMG") {
  168. this.previewImg = e.target.src;
  169. this.imgShow = true;
  170. }
  171. },
  172. imgShowHandler() {
  173. this.imgShow = false;
  174. },
  175. urlParameter(data) {
  176. if (data) {
  177. const query = data.substring(data.indexOf("?") + 1);
  178. const arr = query.split("&");
  179. const params = {};
  180. arr.forEach((v) => {
  181. const key = v.substring(0, v.indexOf("="));
  182. const val = v.substring(v.indexOf("=") + 1);
  183. params[key] = val;
  184. });
  185. return params;
  186. } else return {};
  187. },
  188. // 富文本解析
  189. formatRichText(html) {
  190. let newContent = html.replace(
  191. /<img[^>]*>/gi,
  192. function (match, capture) {
  193. match = match
  194. .replace(/style="[^"]+"/gi, "")
  195. .replace(/style='[^']+'/gi, "");
  196. match = match
  197. .replace(/width="[^"]+"/gi, "")
  198. .replace(/width='[^']+'/gi, "");
  199. match = match
  200. .replace(/height="[^"]+"/gi, "")
  201. .replace(/height='[^']+'/gi, "");
  202. let isExist = match.includes("https://");
  203. if (!isExist) {
  204. match = match.replace(
  205. /(src=")/gi,
  206. 'src="https://wxfalangchang.4dage.com'
  207. );
  208. }
  209. return match;
  210. }
  211. );
  212. newContent = newContent.replace(
  213. /style="[^"]+"/gi,
  214. function (match, capture) {
  215. match = match
  216. .replace(/width:[^;]+;/gi, "max-width:100%;")
  217. .replace(/width:[^;]+;/gi, "max-width:100%;");
  218. return match;
  219. }
  220. );
  221. newContent = newContent.replace(/<br[^>]*\/>/gi, "");
  222. newContent = newContent.replace(
  223. /\<img/gi,
  224. '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"'
  225. );
  226. return newContent;
  227. },
  228. // 收藏
  229. collecttion() {
  230. const params = this.urlParameter(window.location.href);
  231. console.log(params);
  232. console.log(params.isLogin);
  233. if (params.isLogin == "1") {
  234. this.isCollectedInfo = !this.isCollectedInfo;
  235. uni.postMessage({
  236. data: {
  237. action: this.isCollectedInfo ? 1 : 0,
  238. },
  239. });
  240. } else {
  241. alert("身份过期,请重新登录");
  242. uni.reLaunch({
  243. url: "../../../mine/index",
  244. });
  245. }
  246. },
  247. },
  248. });
  249. </script>
  250. </body>
  251. </html>