reportDetail.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="container">
  3. <view class="pay-wall">
  4. <view class="title">
  5. {{ report.title }}
  6. </view>
  7. <button @click="toBuy">点击购买</button>
  8. </view>
  9. <!-- <web-view id="webview" :src="report.sourceFile">
  10. <cover-view class="close-view">
  11. <button>22222</button>
  12. </cover-view>
  13. </web-view> -->
  14. <view class="bottom-box">
  15. <view class="menu-box">
  16. <button class="menu-item" @click="changeApplaud">
  17. <i class="iconfont icon-dianzan" :class="report.hasApplaud?'active':''"></i>
  18. </button>
  19. <button class="menu-item" @click="changeFavi">
  20. <i class="iconfont icon-shoucang1" :class="report.hasFavi?'active':''"></i>
  21. </button>
  22. <button class="menu-item" open-type="share">
  23. <i class="iconfont icon-zhuanfa"></i>
  24. </button>
  25. <button class="menu-item">
  26. <i class="iconfont icon-pengyouquan"></i>
  27. </button>
  28. <button class="menu-item">
  29. <i class="iconfont icon-xiaoxi"></i>
  30. </button>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script setup>
  36. import {
  37. ref,
  38. computed,
  39. onMounted
  40. } from 'vue'
  41. import {
  42. onLoad,
  43. onShareAppMessage,
  44. onShareTimeline
  45. } from '@dcloudio/uni-app'
  46. import {
  47. getToken
  48. } from '@/utils/auth.js'
  49. import {
  50. getReportDetail,
  51. reportFavi,
  52. cancelReportFavi,
  53. reportApplaud,
  54. cancelReportApplaud,
  55. payReport
  56. } from '@/api/report.js'
  57. import {
  58. msgError,
  59. msgSuccess
  60. } from "@/utils/common.js"
  61. import {
  62. useAuthStore
  63. } from '@/store/authStore'
  64. const authStore = useAuthStore();
  65. const isMember = computed(()=>{
  66. authStore.loadUserInfo()
  67. return authStore.userInfo.isMember == '0' ? false : true
  68. })
  69. const openid = computed(()=>{
  70. authStore.loadOpenid()
  71. return authStore.openid
  72. })
  73. const webview = ref();
  74. const id = ref()
  75. const title = ref()
  76. const hasPermission = ref(false);
  77. const imgurl = '/static/images/avator-img/1.png'
  78. const report = ref({
  79. id: '01',
  80. title: '2025年2月从化区二手住宅市场交易简报',
  81. summary: "2025年2月从化区二手住宅市场交易简报",
  82. price: '9.9',
  83. memberFree: 1,
  84. free: 0,
  85. status: 0,
  86. markdown: ``
  87. })
  88. const compileMarkDown = computed(() => {
  89. if (!report.value.markdown) {
  90. return;
  91. }
  92. let htmlString = "";
  93. // 判断markdown中代码块标识符的数量是否为偶数
  94. if (report.value.markdown.split("```").length % 2) {
  95. let content = report.value.markdown;
  96. if (content[content.length - 1] != "\n") {
  97. content += "\n";
  98. }
  99. htmlString = content;
  100. } else {
  101. htmlString = report.value.markdown;
  102. }
  103. return htmlString;
  104. })
  105. // 是否登录
  106. const isLogin = computed(() => {
  107. return false
  108. // return getToken() ? true : false
  109. })
  110. // 是否购买/免费
  111. const free = computed(() => {
  112. return false
  113. })
  114. const showMask = computed(() => {
  115. // 是否登录
  116. // 是否已购买或者免费
  117. if (report.value.status || report.value.free) {
  118. return false
  119. }
  120. // 判断用户是否为会员免费
  121. if (report.value.memberFree) {
  122. //
  123. }
  124. return false
  125. })
  126. const payForm = ref({
  127. "id": null,
  128. "title": "",
  129. "desc": "",
  130. "amount": null,
  131. "openid": ""
  132. })
  133. function changeFavi() {
  134. if (report.value.hasFavi) {
  135. cancelReportFavi(id.value).then(res => {
  136. if (res?.code == 0) {
  137. report.value.hasFavi = false
  138. }
  139. })
  140. } else {
  141. reportFavi(id.value).then(res => {
  142. if (res?.code == 0) {
  143. report.value.hasFavi = true
  144. }
  145. })
  146. }
  147. }
  148. function changeApplaud() {
  149. if (report.value.hasApplaud) {
  150. cancelReportApplaud(id.value).then(res => {
  151. if (res?.code == 0) {
  152. report.value.hasApplaud = false
  153. }
  154. })
  155. } else {
  156. reportApplaud(id.value).then(res => {
  157. if (res?.code == 0) {
  158. report.value.hasApplaud = true
  159. }
  160. })
  161. }
  162. }
  163. function toBuy() {
  164. // 修改一下,如果是会员,用会员价格,
  165. // 如果不是会员就用普通价格
  166. payForm.value.amount = isMember.value? report.value.priceMember : report.value.price
  167. payForm.value.openid = openid.value
  168. payReport(payForm.value).then(res=>{
  169. if(res && res.code===0){
  170. const params = res.data
  171. wx.requestPayment({
  172. nonceStr: params.nonceStr,
  173. package: params.package,
  174. paySign: params.paySign,
  175. signType: params.signType,
  176. timeStamp: params.timeStamp,
  177. success(res){
  178. msgSuccess("支付成功")
  179. },
  180. fail(res){
  181. msgError("支付失败")
  182. }
  183. })
  184. }
  185. })
  186. }
  187. function init(id) {
  188. getReportDetail(id).then(res => {
  189. if (res.code === 0) {
  190. report.value = res.data
  191. payForm.value.id = res.data.id
  192. payForm.value.title = res.data.title
  193. payForm.value.desc = res.data.title
  194. }
  195. })
  196. }
  197. onLoad((load) => {
  198. if (load.id) {
  199. id.value = load.id
  200. title.value = load.title
  201. init(id.value)
  202. }
  203. uni.setNavigationBarTitle({
  204. title: title.value
  205. })
  206. })
  207. onMounted(() => {
  208. console.log(uni.createSelectorQuery().select("#webview"))
  209. })
  210. onShareAppMessage((res) => {
  211. if (res.from === 'button') {
  212. console.log('来自按钮分享');
  213. }
  214. return {
  215. title: '研究报告',
  216. path: `/pages/reportDetail/reportDetail?id=${id.value}`,
  217. imageUrl: imgurl.value
  218. };
  219. })
  220. onShareTimeline(() => {
  221. return {
  222. title: '朋友圈标题-研究报告',
  223. query: `id=${id.value}`,
  224. imageUrl: imgurl.value
  225. };
  226. })
  227. </script>
  228. <style lang="scss" scoped>
  229. .container {
  230. height: 100vh;
  231. width: 100vw;
  232. background-color: $uni-bg-color;
  233. .title {
  234. font-size: 38rpx;
  235. text-align: center;
  236. width: 60%;
  237. margin: 0 auto;
  238. padding: 20rpx 0;
  239. }
  240. .content {
  241. padding: 0 20rpx;
  242. }
  243. .mask {
  244. height: 75vh;
  245. padding: 0 20rpx;
  246. background-color: $uni-bg-color-grey;
  247. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  248. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  249. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  250. border-radius: 20rpx 20rpx 0 0;
  251. @include bottomMagnet();
  252. .mask-box {
  253. height: 100%;
  254. width: 100%;
  255. position: relative;
  256. .button {
  257. margin: 0 auto;
  258. width: 45%;
  259. }
  260. }
  261. .member-box {
  262. padding-top: 210rpx;
  263. .remark {
  264. height: 90rpx;
  265. text-align: center;
  266. letter-spacing: 3rpx;
  267. font-size: 32rpx;
  268. color: $uni-text-color-grey;
  269. }
  270. .link {
  271. position: absolute;
  272. top: 70%;
  273. width: 100%;
  274. font-size: 32rpx;
  275. color: $uni-color-error;
  276. font-size: $uni-title-font-size-2;
  277. font-weight: bold;
  278. .text {
  279. text-align: center;
  280. letter-spacing: 5rpx;
  281. &:active {
  282. text-decoration: underline;
  283. }
  284. }
  285. }
  286. }
  287. .login-box {
  288. padding-top: 300rpx;
  289. }
  290. }
  291. .disable-scroll {
  292. position: fixed;
  293. top: 0;
  294. left: 0;
  295. width: 100%;
  296. height: 100%;
  297. }
  298. .bottom-block {
  299. height: 110rpx;
  300. }
  301. .bottom-box {
  302. padding: 5rpx 25rpx;
  303. background-color: $uni-bg-color-grey;
  304. @include bottomMagnet();
  305. -webkit-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  306. -moz-box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  307. box-shadow: 0px -1rpx 5rpx 0px rgba(50, 50, 50, 0.25);
  308. .menu-box {
  309. height: 100rpx;
  310. display: flex;
  311. align-items: center;
  312. justify-content: flex-end;
  313. gap: 50rpx;
  314. .menu-item {
  315. background-color: transparent;
  316. margin: 0;
  317. border: none;
  318. padding: 0;
  319. }
  320. .menu-item::after {
  321. border: none !important;
  322. }
  323. .iconfont {
  324. font-size: 42rpx;
  325. color: $uni-text-color-grey;
  326. }
  327. .active {
  328. color: yellow;
  329. }
  330. }
  331. }
  332. }
  333. </style>