reportDetail.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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.navigateTo({
  228. url:`/pages/login/login?redirect=${JSON.stringify(url)}`
  229. })
  230. }
  231. const toJoin = () =>{
  232. uni.navigateTo({
  233. url: '/pages/joinClub/joinClub'
  234. })
  235. }
  236. function init(id) {
  237. // 测试图片
  238. getReportDetail(id).then(res => {
  239. if (res.code === 0) {
  240. report.value = res.data
  241. payForm.value.id = res.data.id
  242. payForm.value.title = res.data.title
  243. payForm.value.desc = res.data.title
  244. payForm.value.amount = isMember.value ? report.value.priceMember : report.value.price
  245. report.value.content = ""
  246. if(!report.value.hasBuy){
  247. buyShow.value = true
  248. }
  249. if(res.data.imgData){
  250. const path = res.data.imgData.path
  251. const type = res.data.imgData.type
  252. const size = res.data.imgData.size
  253. for(let i=1;i <= size;i++){
  254. let image = `${path}/${i}.${type}`
  255. report.value.content = report.value.content + `<img src='${image}'></img>`
  256. }
  257. }else{
  258. report.value.content = ''
  259. }
  260. }
  261. })
  262. }
  263. onLoad((load) => {
  264. if (load.id) {
  265. id.value = load.id
  266. title.value = load.title
  267. // console.log(openid.value, 2222)
  268. if(openid.value){
  269. init(id.value)
  270. loginShow.value = false
  271. }else{
  272. loginShow.value = true
  273. }
  274. // loginShow.value = true
  275. }
  276. uni.setNavigationBarTitle({
  277. title: title.value
  278. })
  279. })
  280. onMounted(() => {
  281. console.log(uni.createSelectorQuery().select("#webview"))
  282. })
  283. onShareAppMessage((res) => {
  284. if (res.from === 'button') {
  285. console.log('来自按钮分享');
  286. }
  287. return {
  288. title: '研究报告',
  289. path: `/pages/reportDetail/reportDetail?id=${id.value}&title=${title.value}`,
  290. imageUrl: imgurl.value
  291. };
  292. })
  293. onShareTimeline(() => {
  294. return {
  295. title: '朋友圈标题-研究报告',
  296. query: `id=${id.value}&title=${title.value}`,
  297. imageUrl: imgurl.value
  298. };
  299. })
  300. </script>
  301. <style>
  302. /* 新增样式 */
  303. .noscroll {
  304. height: 100vh;
  305. overflow: hidden;
  306. position: fixed;
  307. width: 100%;
  308. }
  309. /* 兼容H5和小程序 */
  310. /* #ifdef H5 */
  311. .noscroll {
  312. touch-action: none;
  313. }
  314. /* #endif */
  315. </style>
  316. <style lang="scss" scoped>
  317. .container {
  318. height: 100vh;
  319. width: 100vw;
  320. background-color: $uni-bg-color;
  321. .title {
  322. font-size: 38rpx;
  323. text-align: center;
  324. width: 60%;
  325. margin: 0 auto;
  326. padding: 20rpx 0;
  327. }
  328. .content {
  329. padding: 0 20rpx;
  330. }
  331. .mask {
  332. height: 75vh;
  333. padding: 0 20rpx;
  334. background-color: $uni-bg-color-grey;
  335. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  336. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  337. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  338. border-radius: 20rpx 20rpx 0 0;
  339. @include bottomMagnet();
  340. .mask-box {
  341. height: 100%;
  342. width: 100%;
  343. position: relative;
  344. .button {
  345. margin: 0 auto;
  346. width: 45%;
  347. }
  348. }
  349. .member-box {
  350. padding-top: 210rpx;
  351. .remark {
  352. height: 90rpx;
  353. text-align: center;
  354. letter-spacing: 3rpx;
  355. font-size: 32rpx;
  356. color: $uni-text-color-grey;
  357. }
  358. .link {
  359. position: absolute;
  360. top: 70%;
  361. width: 100%;
  362. font-size: 32rpx;
  363. color: $uni-color-error;
  364. font-size: $uni-title-font-size-2;
  365. font-weight: bold;
  366. .text {
  367. text-align: center;
  368. letter-spacing: 5rpx;
  369. &:active {
  370. text-decoration: underline;
  371. }
  372. }
  373. }
  374. }
  375. .login-box {
  376. padding-top: 300rpx;
  377. }
  378. }
  379. .disable-scroll {
  380. position: fixed;
  381. top: 0;
  382. left: 0;
  383. width: 100%;
  384. height: 100%;
  385. }
  386. .bottom-block {
  387. height: 110rpx;
  388. }
  389. .bottom-box {
  390. padding: 5rpx 25rpx;
  391. background-color: $uni-bg-color-grey;
  392. @include bottomMagnet();
  393. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  394. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  395. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  396. .menu-box {
  397. height: 100rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: flex-end;
  401. gap: 50rpx;
  402. .menu-item {
  403. background-color: transparent;
  404. margin: 0;
  405. border: none;
  406. padding: 0;
  407. }
  408. .menu-item::after {
  409. border: none !important;
  410. }
  411. .iconfont {
  412. font-size: 42rpx;
  413. color: $uni-text-color-grey;
  414. }
  415. .active {
  416. color: yellow;
  417. }
  418. }
  419. }
  420. }
  421. </style>