notice.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="notice">
  3. <custom-nav title="录取通知书"></custom-nav>
  4. <view class="canvas_container content">
  5. <!-- <image src="https://api.jiuweiyun.cn/public/uploads/icon/new_tzs.png" mode="" class="bg"></image> -->
  6. <canvas id="canvas" canvas-id="canvas" :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }" />
  7. </view>
  8. <!-- <view class="save">(长按保存图片)</view> -->
  9. </view>
  10. </template>
  11. <script>
  12. import {
  13. mapState
  14. } from 'vuex';
  15. import {
  16. _API_GetUserSignStatus
  17. } from '@/apis/user.js';
  18. export default {
  19. data() {
  20. return {
  21. canvasWidth: 0, //canvas 宽
  22. canvasHeight: 0, //canvas 高
  23. header: '',
  24. headerImg: '',
  25. userServerInfo: ''
  26. };
  27. },
  28. computed: {},
  29. onShow() {
  30. this.userServerInfo = uni.getStorageSync('newUserInfo')
  31. _API_GetUserSignStatus().then(res => {
  32. if (res.code == 200) {
  33. if(res.data.time!==""){
  34. this.userServerInfo.enroll_time = res.data.time
  35. }else{
  36. this.userServerInfo.enroll_time = '2024-07-16'
  37. }
  38. uni.hideLoading()
  39. this.initCanvas()
  40. }
  41. })
  42. },
  43. methods: {
  44. initCanvas(cb) {
  45. const _this = this
  46. // this.header = this.userServerInfo.avatar
  47. // const nickname = uni.getStorageSync('nickName').slice(0,8)
  48. // const nickname = '柳德湖'
  49. this.header = this.userServerInfo.avatar
  50. const nickname = this.userServerInfo.nickname.slice(0, 8)
  51. uni.showLoading({
  52. title: '加载中',
  53. mask: true
  54. })
  55. uni.downloadFile({
  56. url: this.header,
  57. success: ({
  58. statusCode,
  59. tempFilePath
  60. }) => {
  61. if (statusCode === 200) {
  62. this.headerImg = tempFilePath
  63. }
  64. },
  65. fail: (e) => {
  66. uni.showModal({
  67. content: JSON.stringify(e),
  68. showCancel: false
  69. })
  70. // uni.showToast({
  71. // icon: 'none',
  72. // title: '获取用户头像失败',
  73. // duration: 3000
  74. // })
  75. },
  76. complete: () => {
  77. uni.getImageInfo({
  78. src: 'https://api.jiuweiyun.cn/public/uploads/icon/new_tzs.png',
  79. success: res => {
  80. uni.hideLoading() //停止 loading
  81. _this.canvasWidth = uni.upx2px(690);
  82. _this.canvasHeight = uni.upx2px(1100);
  83. let ctx = uni.createCanvasContext('canvas');
  84. ctx.drawImage(res.path, 0, 0, uni.upx2px(690), uni.upx2px(1100))
  85. ctx.save()
  86. ctx.beginPath()
  87. ctx.arc(uni.upx2px(342), uni.upx2px(430), uni.upx2px(60), 0, 2 *
  88. Math.PI, false)
  89. ctx.clip()
  90. ctx.drawImage(_this.headerImg, uni.upx2px(282), uni.upx2px(370),
  91. uni.upx2px(120), uni.upx2px(120))
  92. ctx.restore()
  93. ctx.font = 'normal normal 20px PingFang SC'
  94. let year = new Date(_this.userServerInfo.enroll_time)
  95. .getFullYear();
  96. let month = new Date(_this.userServerInfo.enroll_time).getMonth() +
  97. 1;
  98. let day = new Date(_this.userServerInfo.enroll_time).getDate();
  99. ctx.setFillStyle("#333333")
  100. ctx.textAlign = "left"
  101. ctx.setFontSize(uni.upx2px(32));
  102. ctx.fillText(_this.userServerInfo.season, uni.upx2px(200), uni
  103. .upx2px(678));
  104. ctx.setFontSize(uni.upx2px(28));
  105. ctx.fillText(year, uni.upx2px(380), uni.upx2px(918));
  106. ctx.fillText(month > 10 ? month : `0${month}`, uni.upx2px(478), uni
  107. .upx2px(918));
  108. ctx.fillText(day > 10 ? day : `0${day}`, uni.upx2px(535), uni
  109. .upx2px(918));
  110. ctx.setFontSize(uni.upx2px(30));
  111. ctx.setFillStyle("#193669")
  112. ctx.font = 'normal bold 15px PingFang SC'
  113. ctx.textAlign = "center"
  114. ctx.fillText(nickname, uni.upx2px(338), uni.upx2px(560));
  115. ctx.draw();
  116. }
  117. })
  118. }
  119. })
  120. },
  121. saveImage() {
  122. this.getCanvas()
  123. },
  124. getCanvas() {
  125. uni.showLoading({
  126. title: '下载中...'
  127. });
  128. uni.canvasToTempFilePath({
  129. width: uni.upx2px(690),
  130. height: uni.upx2px(1100),
  131. canvasId: 'canvas',
  132. success: function(res) {
  133. uni.saveImageToPhotosAlbum({
  134. filePath: res.tempFilePath,
  135. success: res => {
  136. uni.showModal({
  137. content: '录取通知书保存成功',
  138. showCancel: false
  139. });
  140. },
  141. fail: err => {
  142. if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
  143. uni.showModal({
  144. title: '提示',
  145. content: '您好,请先授权,再保存此图片。',
  146. showCancel: false,
  147. success: res => {
  148. if (res.confirm) {
  149. uni.openSetting({
  150. success(settingdata) {
  151. console.log(
  152. settingdata);
  153. if (settingdata
  154. .authSetting[
  155. 'scope.writePhotosAlbum'
  156. ]) {
  157. uni.showModal({
  158. content: '请重新长按保存图片',
  159. showCancel: false
  160. });
  161. } else {
  162. uni.showModal({
  163. content: '您拒绝了保存到相册权限',
  164. showCancel: false
  165. });
  166. }
  167. },
  168. fail: err => {
  169. uni.showModal({
  170. content: '手动打开相册权限失败',
  171. showCancel: false
  172. });
  173. }
  174. });
  175. }
  176. }
  177. });
  178. } else {
  179. _this.initCanvas()
  180. }
  181. },
  182. complete() {
  183. uni.hideLoading();
  184. }
  185. });
  186. }
  187. });
  188. }
  189. }
  190. };
  191. </script>
  192. <style scoped lang="scss">
  193. .notice {
  194. // @include page();
  195. width: 100%;
  196. height: 100%;
  197. min-height: 100%;
  198. // display: flex;
  199. // justify-content: space-between;
  200. // flex-direction: column;
  201. background-color: #ededed;
  202. .canvas_container {
  203. // flex: 1;
  204. padding: 170rpx 30rpx 0rpx 30rpx;
  205. position: relative;
  206. .bg {
  207. width: 690rpx;
  208. height: 1100rpx;
  209. }
  210. #canvas {
  211. width: 690rpx;
  212. height: 1100rpx;
  213. // position: absolute;
  214. // top: 169rpx;
  215. // bottom: 0;
  216. // left: 30rpx;
  217. // right: 0;
  218. }
  219. }
  220. }
  221. .save {
  222. width: 100%;
  223. text-align: center;
  224. margin-top: 10rpx;
  225. }
  226. </style>