longPosterService2.vue 8.1 KB

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