longPosterService.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view>
  3. <view class="poster" id="poster">
  4. <!-- 年度理赔账单 -->
  5. <image class="poster-pic" :src="posterBg?posterBg:'/library/static/images/temp1.png'" mode="widthFix"></image>
  6. <view style="position: absolute;top: 912rpx;left: 50%;transform: translateX(-50%);min-width:604rpx;">
  7. <view style="background-color: #fff;padding: 20rpx 0;">
  8. <view style="font-size: 36rpx;font-weight: bold;text-align: center;">{{dataForm[0].title?dataForm[0].title:'文本一'}}</view>
  9. <view style="font-size: 90rpx;font-weight: bold;color: #FF5700;margin-top: 5rpx;line-height: 126rpx;text-align: center;">{{dataForm[0].data?dataForm[0].data.value:'300'}}</view>
  10. </view>
  11. <view style="background-color: #fff;margin-top: 30rpx;padding: 20rpx 0;">
  12. <view style="font-size: 33rpx;font-weight: bold;text-align: center;">{{dataForm[1].title?dataForm[1].title:'文本二'}}</view>
  13. <view style="width:522rpx;font-size: 26rpx;font-weight: 400;color: #333;line-height: 48rpx;margin: 17rpx auto 0;">
  14. {{dataForm[1].data?dataForm[1].data.value:'文本二内容'}}
  15. </view>
  16. </view>
  17. <view class="table-th ddflex" v-if="dataForm[2].data.title&&dataForm[2].data.title.length>0">
  18. <view class="table-th-item fflex" v-for="item,index in dataForm[2].data.title">{{item}}</view>
  19. </view>
  20. <view>
  21. <view class="table-td" v-for="item,index in dataForm[2].data.value">
  22. <view class="ddflex">
  23. <view class="table-td-item" :class="(item.length<3&&idx==0||item.length>2)?'fflex':''" v-for="it,idx in item">{{it}}</view>
  24. </view>
  25. <view v-if="index!=dataForm[2].data.value.length-1" class="table-td-item-border"></view>
  26. </view>
  27. </view>
  28. <!-- <view class="ddflex" style="margin-top: 40rpx;">
  29. <view class="flex">
  30. <view class="poster-title">杜平 | 18665676418</view>
  31. <view class="poster-note">扫码即可咨询理赔事宜</view>
  32. </view>
  33. <image class="poster-code" src="https://img.zhiqiyun.com/test/2023/08/23/d44ab2b86522a05ee6bd026cf04ec8bd.png"></image>
  34. </view> -->
  35. </view>
  36. </view>
  37. <view class="ddflex" style="margin: 30rpx 0 10rpx;justify-content: space-between;">
  38. <view class="ddflex">
  39. <view class="option ddflex" @click="uploadImage">
  40. <image mode="aspectFit" src="../static/images/opt1.png"></image>
  41. 更换背景
  42. </view>
  43. <view class="line"></view>
  44. <view class="option ddflex" @click="jumpUrl('/library/longPosterContent/longPosterContent')">
  45. <image mode="aspectFit" src="../static/images/opt2.png"></image>
  46. 编辑内容
  47. </view>
  48. </view>
  49. <view class="option-btn" @click="toImg">发布</view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. const app = getApp();
  55. const req = require("../../utils/request.js");
  56. import html2canvas from '../static/html2canvas.min.js';
  57. export default {
  58. components: {},
  59. props: {},
  60. data() {
  61. return {
  62. posterBg:'',
  63. base64:'',
  64. title:'',
  65. time:'',
  66. dataForm:[{
  67. chineseName:'文本一',
  68. title:'',
  69. code:'',
  70. data:''
  71. },{
  72. chineseName:'文本二',
  73. title:'',
  74. code:'',
  75. data:''
  76. },{
  77. chineseName:'文本三',
  78. title:'',
  79. code:'',
  80. data:[]
  81. }],
  82. codeDetail:'',
  83. id:""
  84. }
  85. },
  86. onLoad(options) {
  87. this.getCodeDetail('nianduzhangdan')
  88. if(options.id){
  89. this.id = options.id
  90. this.getPosterDetail()
  91. }
  92. },
  93. onShow() {
  94. },
  95. methods: {
  96. jumpUrl(url){
  97. uni.navigateTo({
  98. url:url
  99. })
  100. },
  101. getCodeDetail(code){
  102. req.getRequest('/api/material/longPosterDetail',{code:code},res=>{
  103. this.codeDetail = res&&res.extForm?JSON.parse(res.extForm):[]
  104. })
  105. },
  106. getPosterDetail(){
  107. req.getRequest('/api/material/library/detail',{id:this.id},res=>{
  108. this.title = res&&res.title?res.title:''
  109. this.time = res&&res.extForm?JSON.parse(res.extForm).time:''
  110. this.posterBg = res&&res.extForm?JSON.parse(res.extForm).posterBg:''
  111. this.dataForm = res&&res.extForm?JSON.parse(res.extForm).dataForm:[]
  112. })
  113. },
  114. toImg() {
  115. if(!this.title) return req.msg('请编辑内容')
  116. if(!this.time) return req.msg('请编辑内容')
  117. if(!this.dataForm[0].title) return req.msg('请编辑文本一')
  118. if(!this.dataForm[1].title) return req.msg('请编辑文本二')
  119. if(!this.dataForm[2].title) return req.msg('请编辑文本三')
  120. uni.showLoading({
  121. title:'发布中'
  122. })
  123. // 使页面滑到顶部,避免顶部出现白边
  124. uni.pageScrollTo({
  125. scrollTop: 0,
  126. duration: 0
  127. })
  128. var dom = document.querySelector('#poster'); // 获取dom元素
  129. html2canvas(dom, {
  130. width: dom.clientWidth, //dom 原始宽度
  131. height: dom.clientHeight,
  132. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  133. scrollX: 0,
  134. useCORS: true, //支持跨域
  135. }).then((canvas) => {
  136. // 将生产的canvas转为base64图片
  137. this.base64 = canvas.toDataURL('image/png')
  138. req.postRequest('/api/nocheck/uploadBase64',{fileString:this.base64.replace('data:image/png;base64,','')},data=>{
  139. let dataP = {
  140. title:this.title,
  141. code:'nianduzhangdan',
  142. pic:data.src,
  143. extForm:{
  144. posterBg:this.posterBg,
  145. time:this.time,
  146. dataForm:this.dataForm
  147. }
  148. }
  149. dataP.extForm = JSON.stringify(dataP.extForm)
  150. let url = '/api/material/saveLongPoster'
  151. if(this.id) {
  152. dataP.id = this.id
  153. url = '/api/material/updateLongPoster'
  154. }
  155. // return false
  156. req.postRequest(url,dataP,res=>{
  157. uni.hideLoading()
  158. req.msg('发布成功')
  159. setTimeout(()=>{
  160. uni.navigateBack()
  161. },1000)
  162. })
  163. })
  164. // uni.downloadFile({
  165. // url: this.base64, //仅为示例,并非真实的资源
  166. // success: (res) => {
  167. // console.log(res)
  168. // if (res.statusCode === 200) {
  169. // console.log('下载成功');
  170. // var oA = document.createElement("a");
  171. // oA.download = ''; // 设置下载的文件名,默认是'下载'
  172. // oA.href = res.tempFilePath; //临时路径再保存到本地
  173. // document.body.appendChild(oA);
  174. // oA.click();
  175. // oA.remove(); // 下载之后把创建的元素删除
  176. // }
  177. // }
  178. // });
  179. });
  180. },
  181. uploadImage(){
  182. let that = this;
  183. let count = 1
  184. uni.chooseImage({
  185. count: count,
  186. sizeType: ['original', 'compressed'],
  187. sourceType: ['album', 'camera'],
  188. success: function({ tempFilePaths }) {
  189. var promise = Promise.all(
  190. tempFilePaths.map(tempFilePath => {
  191. return new Promise(function(resolve, reject) {
  192. req.uploadFile('/api/nocheck/upload', tempFilePath, res => {
  193. that.posterBg = res.src
  194. });
  195. });
  196. })
  197. );
  198. promise
  199. .then(function(results) {
  200. console.log(results);
  201. })
  202. .catch(function(err) {
  203. console.log(err);
  204. });
  205. }
  206. });
  207. },
  208. },
  209. mounted() {
  210. }
  211. }
  212. </script>
  213. <style>
  214. @import "./longPosterService.css";
  215. </style>