特易招,招聘小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.1 KiB

5 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="编辑模板" leftClick @leftClick="$utils.navigateBack" />
  4. <view style="padding: 25rpx;background-color: #fff;">
  5. <canvas-drag ref="canvasRef"
  6. id="canvas-drag" :graph="graph"
  7. :width="width" :height="height"
  8. @onDrawArrChange="onDrawArrChange"
  9. enableUndo="true"></canvas-drag>
  10. </view>
  11. <view class="btn-list">
  12. <view class="uni-color-btn" @tap="onAddImage">新建签名</view>
  13. <view class="uni-color-btn" @tap="onChangeBgImage">导入合同</view>
  14. <view class="uni-color-btn" @tap="onUndo">后退</view>
  15. <view class="uni-color-btn" @tap="onClearCanvas">清空</view>
  16. <view class="uni-color-btn" @tap="submit">保存</view>
  17. <!-- <view class="uni-color-btn" @tap="onExportJSON">导出模板</view> -->
  18. <!-- <view class="uni-color-btn" @tap="onAddText">添加文字</view> -->
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import canvasDrag from "@/components/canvas-drag/index";
  24. import setData from "@/components/canvas-drag/setData.js";
  25. export default {
  26. components: {
  27. canvasDrag
  28. },
  29. mixins : [setData],
  30. data() {
  31. return {
  32. height: 750,
  33. width: 700,
  34. drawArr : [],
  35. }
  36. },
  37. onLoad() {
  38. },
  39. mounted() {},
  40. methods: {
  41. // 签名位置更新时
  42. onDrawArrChange(arr){
  43. this.drawArr = arr
  44. },
  45. /**
  46. * 添加签名位置
  47. */
  48. onAddImage() {
  49. wx.chooseImage({
  50. success: res => {
  51. this.setData({
  52. graph: {
  53. w: 100,
  54. h: 50,
  55. type: 'image',
  56. url: res.tempFilePaths[0]
  57. }
  58. });
  59. }
  60. });
  61. },
  62. /**
  63. * 导入合同
  64. */
  65. onChangeBgImage() {
  66. let self = this
  67. wx.chooseImage({
  68. success: res => {
  69. uni.getImageInfo({
  70. src: res.tempFilePaths[0],
  71. success: image => {
  72. console.log(image);
  73. let allwh = image.height + image.width
  74. let imgw = (image.width / allwh).toFixed(2)
  75. let imgh = (image.height / allwh).toFixed(2)
  76. self.height = imgh * Math.ceil(this.width / imgw)
  77. self.$nextTick(() => {
  78. this.$refs.canvasRef.changeBgImage(image.path)
  79. })
  80. }
  81. })
  82. }
  83. });
  84. },
  85. // 后退
  86. onUndo(event) {
  87. this.$refs.canvasRef.undo();
  88. },
  89. /**
  90. * 导出当前画布为模板
  91. */
  92. onExportJSON() {
  93. this.$refs.canvasRef.exportFun().then(imgArr => {
  94. console.log(imgArr);
  95. uni.previewImage({
  96. urls: [imgArr],
  97. current: 0,
  98. })
  99. }).catch(e => {
  100. console.error(e);
  101. });
  102. },
  103. /**
  104. * 添加文本
  105. */
  106. onAddText() {
  107. this.setData({
  108. graph: {
  109. type: 'text',
  110. text: 'helloworld'
  111. }
  112. });
  113. },
  114. onClearCanvas(event) {
  115. let _this = this;
  116. _this.setData({
  117. canvasBg: null
  118. });
  119. this.$refs.canvasRef.clearCanvas();
  120. },
  121. submit() {
  122. uni.setStorageSync('drawArrJson', JSON.stringify(this.drawArr))
  123. uni.navigateBack(-1)
  124. },
  125. }
  126. }
  127. </script>
  128. <style scoped lang="scss">
  129. .page {
  130. padding-bottom: 100rpx;
  131. .btn-list {
  132. display: flex;
  133. flex-wrap: wrap;
  134. padding: 20rpx;
  135. gap: 20rpx;
  136. .uni-color-btn {
  137. margin: 0;
  138. border-radius: 10rpx;
  139. }
  140. }
  141. }
  142. </style>