reportDetail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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 = ref(null)
  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. console.log(report.value.hasFavi)
  167. if (report.value.hasFavi) {
  168. cancelReportFavi(id.value).then(res => {
  169. if (res?.code == 0) {
  170. report.value.hasFavi = false
  171. }
  172. })
  173. } else {
  174. reportFavi(id.value).then(res => {
  175. if (res?.code == 0) {
  176. report.value.hasFavi = true
  177. }
  178. })
  179. }
  180. }
  181. function changeApplaud() {
  182. console.log(report.value.hasApplaud)
  183. if (report.value.hasApplaud) {
  184. cancelReportApplaud(id.value).then(res => {
  185. if (res?.code == 0) {
  186. report.value.hasApplaud = false
  187. }
  188. })
  189. } else {
  190. reportApplaud(id.value).then(res => {
  191. if (res?.code == 0) {
  192. report.value.hasApplaud = true
  193. }
  194. })
  195. }
  196. }
  197. function toBuy() {
  198. // console.log("点击购买")
  199. // 修改一下,如果是会员,用会员价格,
  200. // 如果不是会员就用普通价格
  201. payForm.value.openid = openid.value
  202. payReport(payForm.value).then(res => {
  203. if (res && res.code === 0) {
  204. const params = res.data
  205. wx.requestPayment({
  206. nonceStr: params.nonceStr,
  207. package: params.package,
  208. paySign: params.paySign,
  209. signType: params.signType,
  210. timeStamp: params.timeStamp,
  211. success(res) {
  212. buyShow.value = false
  213. msgSuccess("支付成功")
  214. },
  215. fail(res) {
  216. buyShow.value = true
  217. msgError("支付失败")
  218. }
  219. })
  220. }
  221. })
  222. }
  223. function toLogin(){
  224. let url = {
  225. url: '/pages/reportDetail/reportDetail',
  226. id: id.value,
  227. title: title.value
  228. }
  229. // const decodedRedirect = decodeURIComponent(url);
  230. uni.setStorageSync("redirect", url)
  231. uni.navigateTo({
  232. url:`/pages/login/login`
  233. })
  234. }
  235. const toJoin = () =>{
  236. uni.navigateTo({
  237. url: '/pages/joinClub/joinClub'
  238. })
  239. }
  240. function init(id) {
  241. // 测试图片
  242. getReportDetail(id).then(res => {
  243. if (res.code === 0) {
  244. report.value = res.data
  245. payForm.value.id = res.data.id
  246. payForm.value.title = res.data.title
  247. payForm.value.desc = res.data.title
  248. payForm.value.amount = isMember.value ? report.value.priceMember : report.value.price
  249. report.value.content = ""
  250. if(!report.value.hasBuy && res.data.viewMode === '3'){
  251. buyShow.value = true
  252. }else if(!report.value.hasBuy && !isMember.value && res.data.viewMode === '2' ){
  253. buyShow.value = true
  254. }
  255. // console.log(report.value.hasBuy, res.data.viewMode, buyShow.value, 100)
  256. if(res.data.imgData){
  257. const path = res.data.imgData.path
  258. const type = res.data.imgData.type
  259. const size = res.data.imgData.size
  260. for(let i=1;i <= size;i++){
  261. let image = `${path}/${i}.${type}`
  262. report.value.content = report.value.content + `<img src='${image}'></img>`
  263. }
  264. }else{
  265. report.value.content = ''
  266. }
  267. imgurl.value = report.value.cover
  268. }
  269. })
  270. }
  271. onLoad((load) => {
  272. if (load.id) {
  273. id.value = load.id
  274. title.value = load.title
  275. // console.log(openid.value, 2222)
  276. if(openid.value){
  277. init(id.value)
  278. loginShow.value = false
  279. }else{
  280. loginShow.value = true
  281. }
  282. // loginShow.value = true
  283. }
  284. uni.setNavigationBarTitle({
  285. title: title.value
  286. })
  287. })
  288. onMounted(() => {
  289. console.log(uni.createSelectorQuery().select("#webview"))
  290. })
  291. onShareAppMessage((res) => {
  292. // if (res.from === 'button') {
  293. // console.log('来自按钮分享');
  294. // }
  295. // console.log(imgurl.value)
  296. return {
  297. title: title.value,
  298. path: `/pages/reportDetail/reportDetail?id=${id.value}&title=${title.value}`,
  299. imageUrl: imgurl.value
  300. };
  301. })
  302. onShareTimeline(() => {
  303. // console.log(imgurl.value)
  304. return {
  305. title: title.value,
  306. query: `id=${id.value}&title=${title.value}`,
  307. imageUrl: imgurl.value
  308. };
  309. })
  310. </script>
  311. <style>
  312. /* 新增样式 */
  313. .noscroll {
  314. height: 100vh;
  315. overflow: hidden;
  316. position: fixed;
  317. width: 100%;
  318. }
  319. /* 兼容H5和小程序 */
  320. /* #ifdef H5 */
  321. .noscroll {
  322. touch-action: none;
  323. }
  324. /* #endif */
  325. </style>
  326. <style lang="scss" scoped>
  327. .container {
  328. height: 100vh;
  329. width: 100vw;
  330. background-color: $uni-bg-color;
  331. .title {
  332. font-size: 38rpx;
  333. text-align: center;
  334. width: 60%;
  335. margin: 0 auto;
  336. padding: 20rpx 0;
  337. }
  338. .content {
  339. padding: 0 20rpx;
  340. }
  341. .mask {
  342. height: 75vh;
  343. padding: 0 20rpx;
  344. background-color: $uni-bg-color-grey;
  345. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  346. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  347. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  348. border-radius: 20rpx 20rpx 0 0;
  349. @include bottomMagnet();
  350. .mask-box {
  351. height: 100%;
  352. width: 100%;
  353. position: relative;
  354. .button {
  355. margin: 0 auto;
  356. width: 45%;
  357. }
  358. }
  359. .member-box {
  360. padding-top: 210rpx;
  361. .remark {
  362. height: 90rpx;
  363. text-align: center;
  364. letter-spacing: 3rpx;
  365. font-size: 32rpx;
  366. color: $uni-text-color-grey;
  367. }
  368. .link {
  369. position: absolute;
  370. top: 70%;
  371. width: 100%;
  372. font-size: 32rpx;
  373. color: $uni-color-error;
  374. font-size: $uni-title-font-size-2;
  375. font-weight: bold;
  376. .text {
  377. text-align: center;
  378. letter-spacing: 5rpx;
  379. &:active {
  380. text-decoration: underline;
  381. }
  382. }
  383. }
  384. }
  385. .login-box {
  386. padding-top: 300rpx;
  387. }
  388. }
  389. .disable-scroll {
  390. position: fixed;
  391. top: 0;
  392. left: 0;
  393. width: 100%;
  394. height: 100%;
  395. }
  396. .bottom-block {
  397. height: 110rpx;
  398. }
  399. .bottom-box {
  400. padding: 5rpx 25rpx;
  401. background-color: $uni-bg-color-grey;
  402. @include bottomMagnet();
  403. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  404. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  405. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  406. .menu-box {
  407. height: 100rpx;
  408. display: flex;
  409. align-items: center;
  410. justify-content: flex-end;
  411. gap: 50rpx;
  412. .menu-item {
  413. background-color: transparent;
  414. margin: 0;
  415. border: none;
  416. padding: 0;
  417. }
  418. .menu-item::after {
  419. border: none !important;
  420. }
  421. .iconfont {
  422. font-size: 42rpx;
  423. color: $uni-text-color-grey;
  424. }
  425. .active {
  426. color: yellow;
  427. }
  428. }
  429. }
  430. }
  431. </style>