certificateDetail.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view v-if="itemData" style="width: 100vw;height: 100vh;overflow: auto;">
  3. <view class="cer-img">
  4. <image src="https://minio.citupro.com/dev/static/bgc.jpg" mode="scaleToFill" style="width: 100%;height: 100%;"></image>
  5. <view class="cer-introduce">
  6. 兹有
  7. <span class="cer-text">{{ itemData?.student?.schoolName }}</span>
  8. <span class="cer-text">{{ itemData?.student?.majorName }}</span>
  9. 专业<span class="cer-text">{{ itemData?.person?.name }}</span>
  10. 同学于<span class="cer-text">{{ itemData?.startTime ? timesTampChange(itemData?.startTime, 'Y-M-D') : '' }}</span>
  11. 至<span class="cer-text">{{ itemData?.endTime ? timesTampChange(itemData?.endTime, 'Y-M-D') : '' }}</span>
  12. 在<span class="cer-text">{{ itemData?.enterprise?.enterpriseName }}</span>
  13. <span class="cer-text">{{ formatName(itemData?.enterprise?.anotherName || itemData?.enterprise?.name) }}</span>岗位实习。
  14. </view>
  15. <view class="cer-comment">{{ itemData?.evaluate }}</view>
  16. <view class="cer-prove">特此证明。</view>
  17. <view class="cer-end">
  18. <!-- <view>{{ itemData?.enterprise?.enterpriseName }}</view> -->
  19. <view>{{ itemData?.createTime ? timesTampChange(itemData?.createTime, 'Y-M-D') : '' }}</view>
  20. </view>
  21. </view>
  22. <!-- 隐藏的 canvas -->
  23. <canvas canvas-id="shareCanvas" style="width: 100vw; height: 89.5vh; position: fixed; top: -9999px;"></canvas>
  24. <view class="bottom-sticky">
  25. <view style="display: flex;justify-content: space-evenly;align-itens: center;width: 100%;margin: 20rpx 0;">
  26. <view @click="shareClick" style="display: flex;justify-content: center;flex-direction: column;align-items: center;">
  27. <uni-icons type="redo-filled" size="24" color="#00B760"/>
  28. <span style="color:#00B760;font-weight:bold;">分享</span>
  29. </view>
  30. <button v-if="itemData?.certificate" type="primary" size="default" class="buttons" @click="viewReport(itemData)">查看附件</button>
  31. <button v-else type="primary" size="default" class="buttons" style="background-color:grey;">查看附件</button>
  32. </view>
  33. </view>
  34. <!-- <uni-popup ref="sharePopup" type="dialog">
  35. <view class="f-straight" style="height: 200px;width:80vw;background-color: #fff;border-radius: 10px;">
  36. <text style="text-align:center;color:grey;">是否分享实习证书?</text>
  37. <view class="f-horizon pop-btn-wrapper">
  38. <button size="default" class="pop-confirm" pain open-type="share" @click="generateImage">确认</button>
  39. <button size="default" class="pop-cancel" pain @click="null">取消</button>
  40. </view>
  41. </view>
  42. </uni-popup> -->
  43. <!-- 分享实习证书 -->
  44. <uni-popup ref="sharePopup" type="share">
  45. <uni-popup-share title="分享到">
  46. <view class="share-pop">
  47. <button class="f-straight" open-type="share">
  48. <view class="share-round share-round-1" >
  49. <uni-icons type="weixin" color="#FFF" size="30" />
  50. </view>
  51. <view style="font-size:12px;">微信</view>
  52. </button>
  53. <button class="f-straight" @tap="null">
  54. <view class="share-round share-round-1" >
  55. <uni-icons type="pyq" color="#FFF" size="30" />
  56. </view>
  57. <view style="font-size:12px;">朋友圈</view>
  58. </button>
  59. </view>
  60. </uni-popup-share>
  61. </uni-popup>
  62. </view>
  63. </template>
  64. <script setup>
  65. import { ref, nextTick } from 'vue'
  66. import { preview } from '@/utils/preview'
  67. import { onLoad } from '@dcloudio/uni-app'
  68. import { timesTampChange } from '@/utils/date'
  69. import { formatName } from '@/utils/getText'
  70. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
  71. const itemData = ref(null)
  72. onLoad((options) => {
  73. if (options.itemData) itemData.value = JSON.parse(options.itemData)
  74. nextTick(() => {
  75. generateImage()
  76. })
  77. wx.showShareMenu({
  78. withShareTicket: true,
  79. menus: ['shareAppMessage', 'shareTimeline']
  80. })
  81. onShareTimeline()
  82. })
  83. const viewReport = (item) => {
  84. if (!item.certificate) {
  85. uni.showToast({
  86. title: '加载失败,请稍后重试',
  87. icon: 'none',
  88. duration: 2000
  89. })
  90. return
  91. }
  92. preview(item.certificate)
  93. }
  94. const sharePopup = ref()
  95. // 分享按钮点击事件
  96. const shareClick = () => {
  97. sharePopup.value.open()
  98. }
  99. const shareParams = {
  100. title: '门墩儿 专注顶尖招聘',
  101. path: '/pages/index/position'
  102. }
  103. //在点击open-type="share"按钮后会触发以下函数,可以在函数中写需要的逻辑,当然函数的返回值必须是一个对象,用于设置分享卡片的展示形式
  104. //发送给微信好友
  105. onShareAppMessage(() => {
  106. console.log('发送给微信好友:', 1)
  107. if(!canvasToTempFilePath.value){
  108. setTimeout(() => {},1000)
  109. }
  110. sharePopup.value.close()
  111. return {
  112. ...shareParams,
  113. imageUrl: canvasToTempFilePath.value
  114. }
  115. })
  116. // 转发朋圈
  117. onShareTimeline(() => {
  118. console.log('转发朋圈:', 2)
  119. return {
  120. ...shareParams,
  121. imageUrl: canvasToTempFilePath.value
  122. }
  123. })
  124. const canvasToTempFilePath = ref('')
  125. // 生成图片
  126. const generateImage = () => {
  127. const ctx = uni.createCanvasContext('shareCanvas', this)
  128. // 绘制背景图片
  129. ctx.drawImage('https://minio.citupro.com/dev/static/bgc.jpg', 0, 0, 375, 667)
  130. // 绘制文字内容
  131. ctx.setFontSize(16)
  132. ctx.fillText('兹有', 20, 100)
  133. ctx.fillText(itemData.value?.student?.schoolName, 50, 130)
  134. ctx.fillText(itemData.value?.student?.majorName, 50, 160)
  135. ctx.fillText(itemData.value?.person?.name, 50, 190)
  136. ctx.fillText('同学于', 20, 220)
  137. ctx.fillText(itemData.value?.startTime ? timesTampChange(itemData.value?.startTime, 'Y-M-D') : '', 50, 250)
  138. ctx.fillText('至', 20, 280)
  139. ctx.fillText(itemData.value?.endTime ? timesTampChange(itemData.value?.endTime, 'Y-M-D') : '', 50, 310)
  140. ctx.fillText('在', 20, 340)
  141. ctx.fillText(itemData.value?.enterprise?.enterpriseName, 50, 370)
  142. ctx.fillText(formatName(itemData.value?.enterprise?.anotherName || itemData.value?.enterprise?.name), 50, 400)
  143. ctx.fillText('岗位实习。', 20, 430)
  144. ctx.fillText(itemData.value?.evaluate, 20, 460)
  145. ctx.fillText('特此证明。', 20, 490)
  146. ctx.fillText(itemData.value?.createTime ? timesTampChange(itemData.value?.createTime, 'Y-M-D') : '', 200, 520)
  147. // 绘制完成
  148. ctx.draw(false, () => {
  149. // 生成图片
  150. uni.canvasToTempFilePath({
  151. canvasId: 'shareCanvas',
  152. success: (res) => {
  153. canvasToTempFilePath.value = res.tempFilePath
  154. // 保存图片到相册
  155. // uni.saveImageToPhotosAlbum({
  156. // filePath: res.tempFilePath,
  157. // success: () => {
  158. // uni.showToast({
  159. // title: '图片已保存,请前往朋友圈分享',
  160. // icon: 'none'
  161. // })
  162. // },
  163. // fail: (err) => {
  164. // console.error('保存图片失败', err)
  165. // }
  166. // })
  167. },
  168. fail: (err) => {
  169. console.error('生成图片失败', err)
  170. }
  171. })
  172. })
  173. }
  174. </script>
  175. <style lang="less" scoped>
  176. .cer-img{
  177. width: 100vw;
  178. height: 89.5vh;
  179. position: relative;
  180. font-weight: 600;
  181. }
  182. //实习信息
  183. .cer-introduce{
  184. width: 70vw;
  185. position: absolute;
  186. top: 49%;
  187. left: 50%;
  188. transform: translate(-50%,-50%);
  189. text-indent: 2em;
  190. }
  191. //点评内容
  192. .cer-comment{
  193. width: 70vw;
  194. position: absolute;
  195. top: 66%;
  196. left: 50%;
  197. transform: translate(-50%,-50%);
  198. text-indent: 2em;
  199. }
  200. //特此证明
  201. .cer-prove{
  202. width: 70vw;
  203. position: absolute;
  204. top: 80%;
  205. left: 50%;
  206. transform: translate(-50%,-50%);
  207. text-indent: 2em;
  208. }
  209. //公司名称
  210. .cer-end{
  211. position: absolute;
  212. top: 85%;
  213. right: 16%;
  214. }
  215. .cer-text{
  216. text-decoration: underline;
  217. margin: 0 5rpx;
  218. }
  219. button::after{
  220. border:none;
  221. }
  222. .pop-btn-wrapper{
  223. position: relative;
  224. margin-top: 15vh;
  225. .pop-confirm{
  226. background-color: #fff;
  227. color: #4b9afd;
  228. font-size: 21px;
  229. width: 45vw;
  230. position: absolute;
  231. bottom: 0;
  232. left: 0;
  233. }
  234. .pop-cancel{
  235. background-color: #fff;
  236. font-size: 21px;
  237. width: 45vw;
  238. position: absolute;
  239. bottom: 0;
  240. right: 0;
  241. }
  242. }
  243. .buttons{
  244. width: 70vw;
  245. height: 44px;
  246. border-radius: 25px;
  247. background-color: #00B760;
  248. margin: 0;
  249. }
  250. .share-pop {
  251. width: 100%;
  252. // height:300rpx;
  253. display: flex;
  254. justify-content: center;
  255. .f-straight {
  256. margin: 40rpx;
  257. background: unset;
  258. &::after{
  259. border:none !important;
  260. }
  261. }
  262. .share-round {
  263. border-radius:50%;
  264. height:100rpx;
  265. width:100rpx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. }
  270. .share-round-1 {
  271. background-color:#22a039;
  272. }
  273. .share-round-2 {
  274. background-color:#3693cd;
  275. }
  276. }
  277. </style>