makePoster.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view>
  3. <view class="head">
  4. <view class="left">海报预览
  5. <text class="text">
  6. (请拖动到下方编辑、保存海报)
  7. </text>
  8. </view>
  9. <my-upload @uploadCallback="handleFileLink">
  10. <view class="right">
  11. 更换背景图
  12. </view>
  13. </my-upload>
  14. </view>
  15. <view class="painter-box">
  16. <view>
  17. <l-painter ref="painter" css="position: relative;">
  18. <!-- 背景图片 -->
  19. <l-painter-image :src="file.url" css="width: 280px; height: 500px" object-fit="fill" />
  20. <!-- 模板1 底部背景图 -->
  21. <l-painter-image v-if="mode == 'model1'"
  22. src="https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712714733820B3d50bdd4.png"
  23. css="width: 280px; height: 130px;position: absolute;bottom: 0;z-index: 1;" object-fit="fill" />
  24. <block v-if="mode == 'model1' || mode == 'model2'">
  25. <!-- 站点logo -->
  26. <l-painter-image :src="siteLogo"
  27. css="width: 60px; height:60px;position: absolute;bottom: 0px;left:10px;z-index: 2;"
  28. object-fit="cover" />
  29. <!-- 文字描述 -->
  30. <l-painter-text :text="painterText"
  31. :css="'width: 190px; line-height:20px;position: absolute;bottom: 62px;left:10px;z-index: 2;font-size: 14px;color: #333333;line-clamp:2;' + 'color:' + textColor" />
  32. </block>
  33. <!-- 二维码 -->
  34. <l-painter-qrcode v-if="mode != 'default' && detail.isqrcode" :text="detail.qrcodecontent"
  35. css="width: 64px; height: 64px;position: absolute;bottom: 22px;right:10px;z-index: 2;" />
  36. </l-painter>
  37. </view>
  38. </view>
  39. <view class="custom">
  40. <view class="models">
  41. <view class="group">
  42. <view class="title">海报样式</view>
  43. <view class="options">
  44. <view class="option" v-for="option in ops.painter" hover-class="navigator-hover" :key="option.mode"
  45. @click="mode = option.mode">
  46. <image v-if="option.imgUrl" class="image" :src="option.imgUrl" />
  47. <image class="current" v-if="option.mode == mode"
  48. src="https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712715614059B373541f3.png" />
  49. </view>
  50. </view>
  51. </view>
  52. <view class="group">
  53. <view class="title">文字色彩</view>
  54. <view class="options">
  55. <view class="option" v-for="option in ops.text" hover-class="navigator-hover" :key="option.name"
  56. @click="textColor = option.color">
  57. <view class="text" :style="option.style">
  58. {{ option.name }}
  59. </view>
  60. <image class="current" v-if="option.color == textColor"
  61. src="https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712715614059B373541f3.png" />
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <view class="text-box">
  67. <view class="title">
  68. 海报文案
  69. </view>
  70. <view class="input-box">
  71. <input class="input" maxlength="16" type="text" v-model="painterText">
  72. <icon v-if="painterText" class="icon" type="clear" size="3.733vw" @click="painterText = ''" />
  73. </view>
  74. </view>
  75. <view class="but" @click="loading ? '' : saveTheImage()" hover-class="navigator-hover">
  76. <u-loading-icon v-if="loading" color="#fff" />
  77. <text v-else>
  78. 保存
  79. </text>
  80. </view>
  81. </view>
  82. <view class="tips">
  83. *自定义海报区域可以选择海报样式、文字色彩等,文案部分最多可输入16个字,若留空,则不显示自定义文案。
  84. </view>
  85. <view style="height: 20px;" />
  86. </view>
  87. </template>
  88. <script>
  89. import myUpload from "../../components/my-upload.vue";
  90. import lPainter from "../../uni_modules/lime-painter/components/l-painter/l-painter.vue"
  91. import lPainterView from "../../uni_modules/lime-painter/components/l-painter-view/l-painter-view.vue"
  92. import lPainterText from "../../uni_modules/lime-painter/components/l-painter-text/l-painter-text.vue"
  93. import lPainterImage from "../../uni_modules/lime-painter/components/l-painter-image/l-painter-image.vue"
  94. import lPainterQrcode from "../../uni_modules/lime-painter/components/l-painter-qrcode/l-painter-qrcode.vue"
  95. export default {
  96. components: { lPainter, lPainterView, lPainterText, lPainterImage, lPainterQrcode, myUpload },
  97. data() {
  98. return {
  99. detail: {},
  100. file: {},
  101. siteLogo: uni.getStorageSync('site').attinfos[0].url || '',
  102. painterText: '自定义海报区域可以选择海报样式',
  103. mode: "model1",
  104. textColor: '#000000',
  105. ops: {
  106. painter: [{
  107. mode: "model1",
  108. imgUrl: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712714638752Bc18af43.png"
  109. }, {
  110. mode: "model2",
  111. imgUrl: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712714646946B480ca84d.png"
  112. }, {
  113. mode: "model3",
  114. imgUrl: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404101712714656283B28c9d1df.png"
  115. }, {
  116. mode: "default"
  117. }],
  118. text: [{
  119. name: "灰色",
  120. color: '#999999',
  121. style: "color: #999999; background: #FFFFFF;border: 1px solid #DDDDDD;"
  122. }, {
  123. name: "黑色",
  124. color: '#000000',
  125. style: 'color: #000000; background: #FFFFFF; border: 1px solid #DDDDDD;'
  126. }, {
  127. name: "白色",
  128. color: '#FFFFFF',
  129. style: "color: #FFFFFF;background: #CCCCCC;"
  130. },]
  131. },
  132. loading: false
  133. }
  134. },
  135. onLoad() {
  136. try {
  137. this.detail = this.$Http.data.detail;
  138. this.file = this.$Http.data.file;
  139. delete (this.$Http.data)
  140. } catch (error) {
  141. }
  142. },
  143. beforeDestroy() {
  144. this.deteleFiles()
  145. },
  146. methods: {
  147. saveTheImage() {
  148. let that = this;
  149. this.loading = true;
  150. this.$refs.painter.canvasToTempFilePathSync({
  151. fileType: "jpg",
  152. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  153. pathType: 'url',
  154. quality: 1,
  155. success: (res) => {
  156. // 非H5 保存到相册
  157. // H5 提示用户长按图另存
  158. uni.saveImageToPhotosAlbum({
  159. filePath: res.tempFilePath,
  160. success: function (e) {
  161. uni.showModal({
  162. title: '提示',
  163. content: '图片已保存到系统相册',
  164. showCancel: false
  165. })
  166. that.loading = false;
  167. this.$Http.basic({
  168. "id": 20240319142702,
  169. "content": {
  170. sat_sharematerialid: that.detail.sat_sharematerialid, type: 1
  171. }
  172. }).then(res => {
  173. console.log(type, '记录', res)
  174. })
  175. },
  176. fail: ({ errMsg }) => {
  177. if (errMsg == 'saveImageToPhotosAlbum:fail auth deny') {
  178. uni.showModal({
  179. title: '提示',
  180. content: '请授权添加到相册权限后再试!',
  181. showCancel: false,
  182. complete: (complete) => {
  183. uni.openSetting({
  184. success: res => {
  185. that.loading = false;
  186. if (res.authSetting['scope.writePhotosAlbum']) {
  187. this.saveTheImage()
  188. } else {
  189. uni.showModal({
  190. title: '提示',
  191. content: '未获取授权!已取消保存',
  192. showCancel: false,
  193. })
  194. }
  195. }
  196. })
  197. },
  198. })
  199. } else {
  200. that.loading = false;
  201. uni.showModal({
  202. title: '提示',
  203. content: '已取消保存',
  204. showCancel: false,
  205. })
  206. }
  207. },
  208. });
  209. },
  210. });
  211. },
  212. handleFileLink(attachmentids, ownertable = "temporary", ownerid = 1, data) {
  213. this.deteleFiles()
  214. this.$Http.basic({
  215. "classname": "system.attachment.Attachment",
  216. "method": "createFileLink",
  217. "content": {
  218. ownertable,
  219. ownerid,
  220. usetype: 'painter',
  221. attachmentids
  222. }
  223. }).then(res => {
  224. console.log('绑定附件', res)
  225. if (this.cutoff(res.msg)) return;
  226. this.file = res.data[0];
  227. })
  228. },
  229. //删除附件
  230. deteleFiles() {
  231. if (this.file.ownertable == "temporary") this.$Http.basic({
  232. "classname": "system.attachment.Attachment",
  233. "method": "deleteFileLink",
  234. "content": {
  235. linksids: [this.file.linksid]
  236. }
  237. }).then(res => {
  238. console.log("处理删除附件", res)
  239. if (this.cutoff(res.msg)) return;
  240. });
  241. },
  242. },
  243. }
  244. </script>
  245. <style lang="scss">
  246. .head {
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. padding: 10px;
  251. .left {
  252. line-height: 20px;
  253. font-family: Source Han Sans SC, Source Han Sans SC;
  254. font-size: 14px;
  255. color: #333333;
  256. .text {
  257. color: #666666;
  258. }
  259. }
  260. .right {
  261. color: #C30D23;
  262. font-size: 12px;
  263. }
  264. }
  265. .custom {
  266. width: 355px;
  267. background: #FFFFFF;
  268. border-radius: 8px;
  269. padding: 10px;
  270. box-sizing: border-box;
  271. margin: 10px auto;
  272. .models {
  273. display: flex;
  274. justify-content: space-between;
  275. .group {
  276. .title {
  277. line-height: 20px;
  278. font-family: Source Han Sans SC, Source Han Sans SC;
  279. font-size: 14px;
  280. color: #333333;
  281. margin-bottom: 10px;
  282. }
  283. .options {
  284. display: flex;
  285. .option {
  286. position: relative;
  287. width: 40px;
  288. height: 40px;
  289. background: #CCCCCC;
  290. border-radius: 5px;
  291. margin-right: 5px;
  292. overflow: hidden;
  293. box-sizing: border-box;
  294. .image,
  295. .text {
  296. display: flex;
  297. align-items: center;
  298. justify-content: center;
  299. width: 100%;
  300. height: 100%;
  301. font-family: Source Han Sans SC, Source Han Sans SC;
  302. font-size: 12px;
  303. box-sizing: border-box;
  304. border-radius: 5px;
  305. }
  306. .current {
  307. position: absolute;
  308. height: 14px;
  309. width: 14px;
  310. top: 0;
  311. right: 0;
  312. }
  313. }
  314. .option:last-child {
  315. margin-right: 0;
  316. }
  317. }
  318. }
  319. }
  320. .text-box {
  321. margin-top: 20px;
  322. .title {
  323. line-height: 20px;
  324. font-family: Source Han Sans SC, Source Han Sans SC;
  325. font-size: 14px;
  326. color: #333333;
  327. }
  328. .input-box {
  329. display: flex;
  330. align-items: center;
  331. width: 335px;
  332. height: 50px;
  333. background: #FFFFFF;
  334. border-radius: 8px;
  335. border: 1px solid #CCCCCC;
  336. margin-top: 10px;
  337. padding: 10px;
  338. box-sizing: border-box;
  339. .input {
  340. flex: 1;
  341. }
  342. }
  343. }
  344. .but {
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. width: 333px;
  349. height: 45px;
  350. background: #C30D23;
  351. border-radius: 5px;
  352. margin-top: 20px;
  353. font-family: PingFang SC, PingFang SC;
  354. font-weight: bold;
  355. font-size: 16px;
  356. color: #FFFFFF;
  357. }
  358. }
  359. .tips {
  360. width: 355px;
  361. height: 34px;
  362. font-family: Source Han Sans SC, Source Han Sans SC;
  363. font-size: 12px;
  364. color: #666666;
  365. margin: 10px auto;
  366. }
  367. .painter-box {
  368. display: flex;
  369. justify-content: center;
  370. }
  371. </style>