reportDetail.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <view class="container" :class="{noscroll: buyShow}">
  3. <view class="pay-wall" v-show="loginShow">
  4. <view class="title">
  5. {{ report.title }}
  6. </view>
  7. </view>
  8. <u-parse :html="report.content"></u-parse>
  9. <view class="bottom-box">
  10. <view class="menu-box">
  11. <button class="menu-item" @click="changeApplaud">
  12. <i class="iconfont icon-dianzan" :class="report.hasApplaud?'active':''"></i>
  13. </button>
  14. <button class="menu-item" @click="changeFavi">
  15. <i class="iconfont icon-shoucang1" :class="report.hasFavi?'active':''"></i>
  16. </button>
  17. <button class="menu-item" open-type="share">
  18. <i class="iconfont icon-zhuanfa"></i>
  19. </button>
  20. <button class="menu-item">
  21. <i class="iconfont icon-pengyouquan"></i>
  22. </button>
  23. <button class="menu-item">
  24. <i class="iconfont icon-xiaoxi"></i>
  25. </button>
  26. </view>
  27. </view>
  28. <u-popup v-model="buyShow"
  29. :mask="false" :closeable='false'
  30. mode="bottom" :mask-close-able='false'
  31. safe-area-inset-bottom>
  32. <view style="height: 70vh;padding: 40rpx;position: relative;">
  33. <view style="text-align: center;color: #cccccc;margin: 50rpx 0;">正文需付费后才可阅读</view>
  34. <view style="text-align: center;">
  35. <u-button size="medium" type="error" @click="toBuy">¥{{ payForm.amount }} 阅读全部</u-button>
  36. </view>
  37. <view style="text-align: center;
  38. color: #ff0000;
  39. position: absolute;
  40. bottom: 20%;
  41. left: 50%;
  42. width: 80%;
  43. transform: translateX(-50%);" @click="toJoin">个人会员或单位会员免费,点击现在入会></view>
  44. </view>
  45. </u-popup>
  46. <u-popup v-model="loginShow"
  47. :mask="false" :closeable='false'
  48. mode="bottom" :mask-close-able='false'
  49. safe-area-inset-bottom>
  50. <view style="height: 70vh;padding: 40rpx;position: relative;">
  51. <!-- <view style="text-align: center;color: #cccccc;margin: 50rpx 0;">正文需付费后才可阅读</view> -->
  52. <view style="text-align: center;margin: 70rpx 0;">
  53. <u-button size="medium" type="error" @click="toLogin">登录阅读原文</u-button>
  54. </view>
  55. </view>
  56. </u-popup>
  57. </view>
  58. </template>
  59. <script setup>
  60. import {
  61. ref,
  62. computed,
  63. onMounted
  64. } from 'vue'
  65. import {
  66. onLoad,
  67. onShareAppMessage,
  68. onShareTimeline
  69. } from '@dcloudio/uni-app'
  70. import {
  71. getToken
  72. } from '@/utils/auth.js'
  73. import {
  74. getReportDetail,
  75. reportFavi,
  76. cancelReportFavi,
  77. reportApplaud,
  78. cancelReportApplaud,
  79. payReport
  80. } from '@/api/report.js'
  81. import {
  82. msgError,
  83. msgSuccess
  84. } from "@/utils/common.js"
  85. import {
  86. useAuthStore
  87. } from '@/store/authStore'
  88. const authStore = useAuthStore();
  89. const isMember = computed(() => {
  90. authStore.loadUserInfo()
  91. return authStore.userInfo.isMember == '0' ? false : true
  92. })
  93. const openid = computed(() => {
  94. authStore.loadOpenid()
  95. console.log(authStore.openid, 1111)
  96. return authStore.openid
  97. })
  98. const buyShow = ref(false)
  99. const loginShow = ref(true)
  100. const webview = ref();
  101. const id = ref()
  102. const title = ref()
  103. const hasPermission = ref(false);
  104. const imgurl = '/static/images/avator-img/1.png'
  105. const report = ref({
  106. id: '01',
  107. title: '2025年2月从化区二手住宅市场交易简报',
  108. summary: "2025年2月从化区二手住宅市场交易简报",
  109. price: '9.9',
  110. memberFree: 1,
  111. free: 0,
  112. status: 0,
  113. markdown: ``
  114. })
  115. const compileMarkDown = computed(() => {
  116. if (!report.value.markdown) {
  117. return;
  118. }
  119. let htmlString = "";
  120. // 判断markdown中代码块标识符的数量是否为偶数
  121. if (report.value.markdown.split("```").length % 2) {
  122. let content = report.value.markdown;
  123. if (content[content.length - 1] != "\n") {
  124. content += "\n";
  125. }
  126. htmlString = content;
  127. } else {
  128. htmlString = report.value.markdown;
  129. }
  130. return htmlString;
  131. })
  132. // 是否登录
  133. const isLogin = computed(() => {
  134. return false
  135. // return getToken() ? true : false
  136. })
  137. // 是否购买/免费
  138. const free = computed(() => {
  139. return false
  140. })
  141. const showMask = computed(() => {
  142. // 是否登录
  143. // 是否已购买或者免费
  144. if (report.value.status || report.value.free) {
  145. return false
  146. }
  147. // 判断用户是否为会员免费
  148. if (report.value.memberFree) {
  149. //
  150. }
  151. return false
  152. })
  153. const payForm = ref({
  154. "id": null,
  155. "title": "",
  156. "desc": "",
  157. "amount": null,
  158. "openid": ""
  159. })
  160. function parseLoaded() {
  161. setTimeout(() => {
  162. this.$refs.uReadMore1.init();
  163. }, 10);
  164. }
  165. function changeFavi() {
  166. if (report.value.hasFavi) {
  167. cancelReportFavi(id.value).then(res => {
  168. if (res?.code == 0) {
  169. report.value.hasFavi = false
  170. }
  171. })
  172. } else {
  173. reportFavi(id.value).then(res => {
  174. if (res?.code == 0) {
  175. report.value.hasFavi = true
  176. }
  177. })
  178. }
  179. }
  180. function changeApplaud() {
  181. if (report.value.hasApplaud) {
  182. cancelReportApplaud(id.value).then(res => {
  183. if (res?.code == 0) {
  184. report.value.hasApplaud = false
  185. }
  186. })
  187. } else {
  188. reportApplaud(id.value).then(res => {
  189. if (res?.code == 0) {
  190. report.value.hasApplaud = true
  191. }
  192. })
  193. }
  194. }
  195. function toBuy() {
  196. // console.log("点击购买")
  197. // 修改一下,如果是会员,用会员价格,
  198. // 如果不是会员就用普通价格
  199. payForm.value.openid = openid.value
  200. payReport(payForm.value).then(res => {
  201. if (res && res.code === 0) {
  202. const params = res.data
  203. wx.requestPayment({
  204. nonceStr: params.nonceStr,
  205. package: params.package,
  206. paySign: params.paySign,
  207. signType: params.signType,
  208. timeStamp: params.timeStamp,
  209. success(res) {
  210. buyShow.value = false
  211. msgSuccess("支付成功")
  212. },
  213. fail(res) {
  214. buyShow.value = true
  215. msgError("支付失败")
  216. }
  217. })
  218. }
  219. })
  220. }
  221. function toLogin(){
  222. let url = {
  223. url: '/pages/reportDetail/reportDetail',
  224. id: id.value,
  225. title: title.value
  226. }
  227. uni.setStorageSync("redirect", JSON.parse(decodedRedirect))
  228. uni.navigateTo({
  229. url:`/pages/login/login`
  230. })
  231. }
  232. const toJoin = () =>{
  233. uni.navigateTo({
  234. url: '/pages/joinClub/joinClub'
  235. })
  236. }
  237. function init(id) {
  238. // 测试图片
  239. getReportDetail(id).then(res => {
  240. if (res.code === 0) {
  241. report.value = res.data
  242. payForm.value.id = res.data.id
  243. payForm.value.title = res.data.title
  244. payForm.value.desc = res.data.title
  245. payForm.value.amount = isMember.value ? report.value.priceMember : report.value.price
  246. report.value.content = ""
  247. if(!report.value.hasBuy){
  248. buyShow.value = true
  249. }
  250. if(res.data.imgData){
  251. const path = res.data.imgData.path
  252. const type = res.data.imgData.type
  253. const size = res.data.imgData.size
  254. for(let i=1;i <= size;i++){
  255. let image = `${path}/${i}.${type}`
  256. report.value.content = report.value.content + `<img src='${image}'></img>`
  257. }
  258. }else{
  259. report.value.content = ''
  260. }
  261. }
  262. })
  263. }
  264. onLoad((load) => {
  265. if (load.id) {
  266. id.value = load.id
  267. title.value = load.title
  268. // console.log(openid.value, 2222)
  269. if(openid.value){
  270. init(id.value)
  271. loginShow.value = false
  272. }else{
  273. loginShow.value = true
  274. }
  275. // loginShow.value = true
  276. }
  277. uni.setNavigationBarTitle({
  278. title: title.value
  279. })
  280. })
  281. onMounted(() => {
  282. console.log(uni.createSelectorQuery().select("#webview"))
  283. })
  284. onShareAppMessage((res) => {
  285. if (res.from === 'button') {
  286. console.log('来自按钮分享');
  287. }
  288. return {
  289. title: '研究报告',
  290. path: `/pages/reportDetail/reportDetail?id=${id.value}&title=${title.value}`,
  291. imageUrl: imgurl.value
  292. };
  293. })
  294. onShareTimeline(() => {
  295. return {
  296. title: '朋友圈标题-研究报告',
  297. query: `id=${id.value}&title=${title.value}`,
  298. imageUrl: imgurl.value
  299. };
  300. })
  301. </script>
  302. <style>
  303. /* 新增样式 */
  304. .noscroll {
  305. height: 100vh;
  306. overflow: hidden;
  307. position: fixed;
  308. width: 100%;
  309. }
  310. /* 兼容H5和小程序 */
  311. /* #ifdef H5 */
  312. .noscroll {
  313. touch-action: none;
  314. }
  315. /* #endif */
  316. </style>
  317. <style lang="scss" scoped>
  318. .container {
  319. height: 100vh;
  320. width: 100vw;
  321. background-color: $uni-bg-color;
  322. .title {
  323. font-size: 38rpx;
  324. text-align: center;
  325. width: 60%;
  326. margin: 0 auto;
  327. padding: 20rpx 0;
  328. }
  329. .content {
  330. padding: 0 20rpx;
  331. }
  332. .mask {
  333. height: 75vh;
  334. padding: 0 20rpx;
  335. background-color: $uni-bg-color-grey;
  336. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  337. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  338. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  339. border-radius: 20rpx 20rpx 0 0;
  340. @include bottomMagnet();
  341. .mask-box {
  342. height: 100%;
  343. width: 100%;
  344. position: relative;
  345. .button {
  346. margin: 0 auto;
  347. width: 45%;
  348. }
  349. }
  350. .member-box {
  351. padding-top: 210rpx;
  352. .remark {
  353. height: 90rpx;
  354. text-align: center;
  355. letter-spacing: 3rpx;
  356. font-size: 32rpx;
  357. color: $uni-text-color-grey;
  358. }
  359. .link {
  360. position: absolute;
  361. top: 70%;
  362. width: 100%;
  363. font-size: 32rpx;
  364. color: $uni-color-error;
  365. font-size: $uni-title-font-size-2;
  366. font-weight: bold;
  367. .text {
  368. text-align: center;
  369. letter-spacing: 5rpx;
  370. &:active {
  371. text-decoration: underline;
  372. }
  373. }
  374. }
  375. }
  376. .login-box {
  377. padding-top: 300rpx;
  378. }
  379. }
  380. .disable-scroll {
  381. position: fixed;
  382. top: 0;
  383. left: 0;
  384. width: 100%;
  385. height: 100%;
  386. }
  387. .bottom-block {
  388. height: 110rpx;
  389. }
  390. .bottom-box {
  391. padding: 5rpx 25rpx;
  392. background-color: $uni-bg-color-grey;
  393. @include bottomMagnet();
  394. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  395. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  396. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  397. .menu-box {
  398. height: 100rpx;
  399. display: flex;
  400. align-items: center;
  401. justify-content: flex-end;
  402. gap: 50rpx;
  403. .menu-item {
  404. background-color: transparent;
  405. margin: 0;
  406. border: none;
  407. padding: 0;
  408. }
  409. .menu-item::after {
  410. border: none !important;
  411. }
  412. .iconfont {
  413. font-size: 42rpx;
  414. color: $uni-text-color-grey;
  415. }
  416. .active {
  417. color: yellow;
  418. }
  419. }
  420. }
  421. }
  422. </style>