longPosterService2.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view>
  3. <view class="poster" id="poster">
  4. <!-- 日报 -->
  5. <image class="poster-pic" :src="posterBg" mode="widthFix"></image>
  6. <view style="position: absolute;top: 414rpx;left: 50%;transform: translateX(-50%);min-width:604rpx;">
  7. <view style="font-size: 36rpx;font-weight: 400;text-align: left;color: #FFFFFF;">{{dataForm[0].title?dataForm[0].title:'文本一'}}</view>
  8. <view style="font-size: 90rpx;font-weight: bold;text-align: left;color: #FFFFFF;">{{dataForm[0].data?dataForm[0].data.value:'300'}}</view>
  9. <view style="font-size: 36rpx;font-weight: 400;text-align: left;color: #FFFFFF;margin-top: 20rpx;">{{dataForm[1].title?dataForm[1].title:'文本二'}}</view>
  10. <view style="font-size: 90rpx;font-weight: bold;text-align: left;color: #FFFFFF;">{{dataForm[1].data?dataForm[1].data.value:'文本二内容'}}</view>
  11. <view style="font-size: 36rpx;font-weight: 400;text-align: left;color: #FFFFFF;margin-top: 20rpx;">{{dataForm[2].title?dataForm[2].title:'文本三'}}</view>
  12. <view style="font-size: 90rpx;font-weight: bold;text-align: left;color: #FFFFFF;">{{dataForm[2].data?dataForm[2].data.value:'文本三内容'}}</view>
  13. <view class="table-th ddflex" v-if="dataForm[3].data.title&&dataForm[3].data.title.length>0">
  14. <view class="table-th-item fflex" v-for="item,index in dataForm[3].data.title">{{item}}</view>
  15. </view>
  16. <view v-if="dataForm[3].data.value&&dataForm[3].data.value.length>0">
  17. <view class="table-td" v-for="item,index in dataForm[3].data.value">
  18. <view class="ddflex">
  19. <view class="table-td-item" :class="(item.length<3&&idx==0||item.length>2)?'fflex':''" v-for="it,idx in item">{{it}}</view>
  20. </view>
  21. <view v-if="index!=dataForm[3].data.value.length-1" class="table-td-item-border"></view>
  22. </view>
  23. </view>
  24. <!-- <view class="ddflex" style="margin-top: 40rpx;">
  25. <view class="flex">
  26. <view class="poster-title">杜平 | 18665676418</view>
  27. <view class="poster-note">扫码即可咨询理赔事宜</view>
  28. </view>
  29. <image class="poster-code" src="https://img.zhiqiyun.com/test/2023/08/23/d44ab2b86522a05ee6bd026cf04ec8bd.png"></image>
  30. </view> -->
  31. </view>
  32. </view>
  33. <view class="ddflex" style="margin: 30rpx 0 10rpx;justify-content: space-between;">
  34. <view class="ddflex">
  35. <view class="option ddflex" @click="uploadImage">
  36. <image mode="aspectFit" src="../static/images/opt1.png"></image>
  37. 更换背景
  38. </view>
  39. <view class="line"></view>
  40. <view class="option ddflex" @click="jumpUrl('/library/longPosterContent/longPosterContent2')">
  41. <image mode="aspectFit" src="../static/images/opt2.png"></image>
  42. 编辑内容
  43. </view>
  44. </view>
  45. <view class="option-btn" @click="toImg">发布</view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. const app = getApp();
  51. const req = require("../../utils/request.js");
  52. import html2canvas from '../static/html2canvas.min.js';
  53. export default {
  54. components: {},
  55. props: {},
  56. data() {
  57. return {
  58. systems: {},
  59. isTop:0,
  60. productLink:'',
  61. posterBg:'',
  62. base64:'',
  63. formType:1,//1 年报 2 月报 3日报
  64. time:'',
  65. dataForm:[{
  66. chineseName:'文本一',
  67. title:'',
  68. code:'',
  69. data:''
  70. },{
  71. chineseName:'文本二',
  72. title:'',
  73. code:'',
  74. data:''
  75. },{
  76. chineseName:'文本三',
  77. title:'',
  78. code:'',
  79. data:''
  80. },{
  81. chineseName:'文本四',
  82. title:'',
  83. code:'',
  84. data:[]
  85. }],
  86. codeDetail:''
  87. }
  88. },
  89. onLoad(options) {
  90. this.posterBg = 'https://img.zhiqiyun.com/test/2023/08/23/d2ae45f898abdb12559da237f3c92188.png'
  91. this.getCodeDetail('riyuenianbao')
  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. creatCode(){
  107. },
  108. toImg() {
  109. // 使页面滑到顶部,避免顶部出现白边
  110. uni.pageScrollTo({
  111. scrollTop: 0,
  112. duration: 0
  113. })
  114. var dom = document.querySelector('#poster'); // 获取dom元素
  115. html2canvas(dom, {
  116. width: dom.clientWidth, //dom 原始宽度
  117. height: dom.clientHeight,
  118. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  119. scrollX: 0,
  120. useCORS: true, //支持跨域,但好像没什么用
  121. }).then((canvas) => {
  122. // 将生产的canvas转为base64图片
  123. this.base64 = canvas.toDataURL('image/png')
  124. // console.log(this.base64)
  125. // let path = this.base64ToFile(this.base64,new Date().getTime())
  126. let path = uni.base64ToArrayBuffer(this.base64);
  127. console.log(path)
  128. req.uploadFile('/api/nocheck/upload', path, res => {
  129. console.log(res)
  130. });
  131. // uni.downloadFile({
  132. // url: this.base64, //仅为示例,并非真实的资源
  133. // success: (res) => {
  134. // console.log(res)
  135. // if (res.statusCode === 200) {
  136. // console.log('下载成功');
  137. // var oA = document.createElement("a");
  138. // oA.download = ''; // 设置下载的文件名,默认是'下载'
  139. // oA.href = res.tempFilePath; //临时路径再保存到本地
  140. // document.body.appendChild(oA);
  141. // oA.click();
  142. // oA.remove(); // 下载之后把创建的元素删除
  143. // }
  144. // }
  145. // });
  146. });
  147. },
  148. uploadImage(){
  149. let that = this;
  150. let count = 1
  151. uni.chooseImage({
  152. count: count,
  153. sizeType: ['original', 'compressed'],
  154. sourceType: ['album', 'camera'],
  155. success: function({ tempFilePaths }) {
  156. var promise = Promise.all(
  157. tempFilePaths.map(tempFilePath => {
  158. return new Promise(function(resolve, reject) {
  159. req.uploadFile('/api/nocheck/upload', tempFilePath, res => {
  160. that.posterBg = res.src
  161. });
  162. });
  163. })
  164. );
  165. promise
  166. .then(function(results) {
  167. console.log(results);
  168. })
  169. .catch(function(err) {
  170. console.log(err);
  171. });
  172. }
  173. });
  174. },
  175. },
  176. mounted() {
  177. },
  178. onPageScroll: function(e) {
  179. }
  180. }
  181. </script>
  182. <style>
  183. @import "./longPosterService.css";
  184. </style>