index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="container">
  3. <navBar title="绘本记录" :back="true" color="#333333" background="#FFFFFF" />
  4. <view class="bgBox" :style="{'background-image':`url(${picBase+'jl_bg.png'})`}">
  5. <view class="empty" style="margin-top: 50%;" v-if="cusumerList.length==0">
  6. <u-empty mode="data" />
  7. </view>
  8. <view class="" v-else>
  9. <view class="item" v-for="(item,index) in cusumerList">
  10. <image class="mainPic" :src="'https://'+item.sd_image" mode="widthFix"></image>
  11. <view class="name">
  12. {{item.title}}
  13. </view>
  14. <view class="des">
  15. 主角:{{item.role?item.role.name:''}}
  16. </view>
  17. <view class="time">
  18. 创建时间:{{item.created_at}}
  19. </view>
  20. <view class="btnBox">
  21. <view class="item1" @click="downPdf(item.id,item)">
  22. <!-- 绘本下载 -->
  23. PDF生成
  24. </view>
  25. <view class="item1 bg" @click="toDetail(item)">
  26. 绘本详情
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <u-modal showCancelButton @cancel="showLead=false" :show="showLead" title="PDF下载提示" confirmText="去预览" content=""
  33. @confirm="prePdf">
  34. <view class="slot-content">
  35. <view class="txt1">
  36. 下载PDF,请先点击预览页面右上角...菜单按钮,如图1:
  37. </view>
  38. <image src="../../../static/other/caidan.jpg" mode="widthFix" class="caidan"></image>
  39. ,再点击弹框中的保存到手机按钮,如图2:
  40. <image src="../../../static/other/caidan_s.jpg" mode="widthFix" class="caidan"></image>
  41. </view>
  42. </u-modal>
  43. </view>
  44. </template>
  45. <script>
  46. // import navBar from '@/components/navBar/index.vue'
  47. import {
  48. // getChargeRecord,
  49. getConsumerRecord,
  50. genPdf
  51. } from '@/api/index/index.js'
  52. export default {
  53. // components: {
  54. // navBar
  55. // },
  56. data() {
  57. return {
  58. picBase: this.$picBase2,
  59. cusumerList: [],
  60. huibenItem: null,
  61. tempPdfile: '',
  62. showLead: false
  63. }
  64. },
  65. onLoad() {
  66. this.getConsumerRecord()
  67. },
  68. methods: {
  69. prePdf() {
  70. this.showLead = false
  71. uni.openDocument({
  72. filePath: this.tempPdfile,
  73. showMenu: true, //是否可以分享
  74. success: (res) => {
  75. uni.hideLoading()
  76. console.log(res);
  77. },
  78. fail: (e) => {
  79. uni.showToast({
  80. title: '打开失败',
  81. icon: "error"
  82. })
  83. }
  84. })
  85. },
  86. async downPdf(id, item) {
  87. uni.showLoading({
  88. title: '生成中'
  89. });
  90. this.huibenItem = item
  91. console.log('downPdf-------------');
  92. let res1 = await genPdf({
  93. // id:this.taskId
  94. id
  95. })
  96. console.log('获取pdfurl返回值--------2', res1);
  97. if (res1.code == 0) {
  98. console.log('pdf地址:', res1.data.url);
  99. this.download(res1.data.url, 1)
  100. } else {
  101. uni.hideLoading()
  102. this.$toast(res1.message)
  103. }
  104. },
  105. toDetail(item) {
  106. getApp().huibenDetail = item
  107. uni.navigateTo({
  108. url: '/pages/index/genRes/index'
  109. })
  110. },
  111. download(file, type) {
  112. let _this = this
  113. //下载文件
  114. uni.downloadFile({ //只能是GET请求
  115. url: file, //请求地址(后台返回的码流地址)
  116. success: (res) => {
  117. //下载成功
  118. if (res.statusCode === 200) {
  119. //保存文件
  120. let tempFile = res.tempFilePath;
  121. if (type == 2) {
  122. uni.hideLoading()
  123. return _this.pictureReview(tempFile)
  124. }
  125. //保存成功之后 打开文件
  126. uni.getFileSystemManager().saveFile({
  127. tempFilePath: tempFile,
  128. filePath: wx.env.USER_DATA_PATH + '/' + this.huibenItem.title +
  129. '.pdf', //自定义文件名
  130. success(res) {
  131. console.log(res)
  132. uni.hideLoading()
  133. _this.tempPdfile = res.savedFilePath
  134. _this.showLead = true
  135. // uni.openDocument({
  136. // filePath: res.savedFilePath,
  137. // showMenu: true, //是否可以分享
  138. // success: (res) => {
  139. // uni.hideLoading()
  140. // console.log(res);
  141. // },
  142. // fail: (e) => {
  143. // uni.showToast({
  144. // title: '打开失败',
  145. // icon: "error"
  146. // })
  147. // }
  148. // })
  149. }
  150. })
  151. }
  152. },
  153. fail: (e) => {
  154. uni.hideLoading()
  155. console.log(e, '文件下载失败')
  156. uni.showToast({
  157. title: '文件下载失败',
  158. icon: "error",
  159. })
  160. }
  161. });
  162. },
  163. async getConsumerRecord() {
  164. let res1 = await getConsumerRecord()
  165. console.log('绘画记录返回值--------2', res1);
  166. if (res1.code == 0) {
  167. this.cusumerList = res1.data.data
  168. // this.cusumerList = [1]
  169. } else {
  170. this.$toast(res1.message)
  171. }
  172. },
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. @import "./index.scss";
  178. </style>