signList.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view>
  3. <view class="page_v u-flex-col">
  4. <view>
  5. <view v-if="show" v-for="(item,index) in signImg" :key="index" :class="item.isDefault ? 'active' : '' "
  6. class="lists_box" @longpress="handleTouchStart(item,index)">
  7. <view class="signImgBox">
  8. <image :src="item.signImg" mode="scaleToFill" class="signImg"></image>
  9. </view>
  10. <view class="icon-checked-box" v-if="item.isDefault">
  11. <view class="icon-checked">
  12. <u-icon name="checkbox-mark" color="#fff" size="28"></u-icon>
  13. </view>
  14. </view>
  15. <view class="sign-mask" v-if="!item.isDefault && item.isSet" :id="index">
  16. <view class="sign-mask-btn">
  17. <u-button @click.prevent="del(item.id,index)">删除</u-button>
  18. <u-button type="primary" @click.prevent="setDefault(item.id,index)">设为默认</u-button>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <JnpfSign ref="signRef" @change="signData" :showBtn="false" />
  24. <NoData v-if="!show" :paddingTop="460"></NoData>
  25. </view>
  26. <view class="flowBefore-actions">
  27. <u-button class="buttom-btn" type="primary" @click='showAction = true'>添加签名</u-button>
  28. </view>
  29. <u-action-sheet @click="handleAction" :list="actionList" :tips="{ text: '' , color: '#000' , fontSize: 30 }"
  30. v-model="showAction">
  31. </u-action-sheet>
  32. </view>
  33. </template>
  34. <script>
  35. import NoData from '@/components/noData'
  36. import {
  37. pathToBase64
  38. } from '@/libs/file.js'
  39. import {
  40. getSignImgList,
  41. createSignImg,
  42. setDefSignImg,
  43. delSignImg
  44. } from '@/api/common'
  45. export default {
  46. components: {
  47. NoData
  48. },
  49. data() {
  50. return {
  51. value: '',
  52. show: true,
  53. signImg: [],
  54. isSet: false,
  55. showAction: false,
  56. actionList: [{
  57. text: '在线签名',
  58. id: 1
  59. },
  60. {
  61. text: '图片上传',
  62. id: 2
  63. }
  64. ]
  65. }
  66. },
  67. computed: {
  68. baseURL() {
  69. return this.define.comUploadUrl
  70. },
  71. token() {
  72. return uni.getStorageSync('token')
  73. }
  74. },
  75. mounted() {
  76. this.getSignImgList()
  77. },
  78. methods: {
  79. getSignImgList() {
  80. getSignImgList().then(res => {
  81. let signList = JSON.parse(JSON.stringify(res.data)) || []
  82. this.show = signList.length > 0 ? true : false
  83. this.signImg = signList.map(o => ({
  84. isSet: false,
  85. ...o
  86. }))
  87. })
  88. },
  89. signData(e) {
  90. if (e) {
  91. let data = {
  92. 'signImg': e,
  93. 'isDefault': 0
  94. }
  95. createSignImg(data).then((res) => {
  96. this.getSignImgList()
  97. })
  98. }
  99. },
  100. handleTouchStart(item, index) {
  101. this.signImg.map((o, i) => {
  102. o.isSet = false
  103. })
  104. item.isSet = true
  105. },
  106. del(id, index) {
  107. delSignImg(id, index).then((res) => {
  108. this.signImg.splice(index, 1)
  109. })
  110. },
  111. setDefault(id, index) {
  112. let userInfo = uni.getStorageSync('userInfo')
  113. setDefSignImg(id).then((res) => {
  114. this.signImg.map((o, i) => {
  115. o.isDefault = false;
  116. if (index == i) {
  117. o.isDefault = true
  118. o.isSet = false
  119. userInfo.signImg = o.signImg
  120. uni.setStorageSync('userInfo', userInfo)
  121. }
  122. })
  123. })
  124. },
  125. handleAction(e) {
  126. if (e == 0) {
  127. this.$refs.signRef.addSign();
  128. } else {
  129. uni.chooseImage({
  130. count: 1, //默认9
  131. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  132. sourceType: ['album'],
  133. success: (res) => {
  134. let tempFilePaths = res.tempFilePaths[0]
  135. // #ifdef H5
  136. let isAccept = new RegExp('image/*').test(res.tempFiles[0].type)
  137. if (!isAccept) return this.$u.toast(`请上传图片`)
  138. // #endif
  139. if ((res.tempFiles[0].size / 1024) > 500) return this.$u.toast('操作失败,图片大小超出500K')
  140. // #ifdef APP-HARMONY
  141. this.harmony(tempFilePaths)
  142. // #endif
  143. // #ifndef APP-HARMONY
  144. pathToBase64(tempFilePaths).then(base64 => {
  145. this.signData(base64)
  146. })
  147. // #endif
  148. }
  149. });
  150. }
  151. },
  152. harmony(tempFilePaths) {
  153. uni.uploadFile({
  154. url: this.baseURL + 'imgToBase64',
  155. filePath: tempFilePaths,
  156. name: 'file',
  157. header: {
  158. 'Authorization': this.token
  159. },
  160. success: (uploadFileRes) => {
  161. let res = JSON.parse(uploadFileRes.data)
  162. this.signData(res.data)
  163. },
  164. fail: (err) => {}
  165. });
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. page {
  172. background-color: #f0f2f6;
  173. }
  174. .page_v {
  175. height: 100%;
  176. padding: 0 20rpx;
  177. .active {
  178. border: 1rpx solid #2979FF;
  179. color: #2979FF;
  180. .icon-ym-organization {
  181. &::before {
  182. color: #2979FF !important;
  183. }
  184. }
  185. }
  186. .sign-mask {
  187. width: 100%;
  188. height: 200rpx;
  189. background: rgba(0, 0, 0, .3);
  190. position: absolute;
  191. top: 0;
  192. border-radius: 12rpx;
  193. display: flex;
  194. align-items: center;
  195. flex-direction: column;
  196. justify-content: center;
  197. .sign-mask-btn {
  198. width: 60%;
  199. display: flex;
  200. }
  201. }
  202. .lists_box {
  203. width: 100%;
  204. height: 200rpx;
  205. border-radius: 8rpx;
  206. position: relative;
  207. display: flex;
  208. flex-direction: column;
  209. justify-content: center;
  210. background-color: #FFFFFF;
  211. margin-bottom: 20rpx;
  212. overflow: hidden;
  213. .signImgBox {
  214. width: 100%;
  215. height: 100%;
  216. text-align: center;
  217. .signImg {
  218. width: 100%;
  219. height: 100%;
  220. }
  221. }
  222. .icon-checked-box {
  223. display: flex;
  224. width: 140rpx;
  225. height: 80rpx;
  226. position: absolute;
  227. transform: scale(0.9);
  228. right: -4rpx;
  229. bottom: -2rpx;
  230. flex-direction: row;
  231. align-items: center;
  232. .icon-checked {
  233. width: 44rpx;
  234. height: 44rpx;
  235. border: 40rpx solid #1890ff;
  236. border-left: 40rpx solid transparent;
  237. border-top: 40rpx solid transparent;
  238. border-bottom-right-radius: 12rpx;
  239. position: absolute;
  240. transform: scale(0.95);
  241. right: -8rpx;
  242. bottom: -6rpx;
  243. }
  244. }
  245. }
  246. }
  247. </style>