Rboy-upload-sfz.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div>
  3. <view class="Rboy-box">
  4. <view class="Rboy-obverse">
  5. <image class="obverseimg" :src="obverseUrl ? obverseUrl : obverse" @click="obverse_btn" mode="">
  6. </image>
  7. <image class="del_btn" :src="del" mode="" v-if="obverseUrl" @click="del_btn('obverse')"></image>
  8. <view class="bottom">
  9. <text>身份证正面照</text>
  10. </view>
  11. </view>
  12. <view class="Rboy-reverse">
  13. <image class="reverseimg" :src="reverseUrl ? reverseUrl : reverse" @click="reverse_btn" mode="">
  14. </image>
  15. <image class="del_btn" :src="del" mode="" v-if="reverseUrl" @click="del_btn('reverse')"></image>
  16. <view class="bottom">
  17. <text>身份证反面照</text>
  18. </view>
  19. </view>
  20. </view>
  21. </div>
  22. </template>
  23. <script>
  24. import file from "./file.js"
  25. export default {
  26. name: "Rboy-upload-sfz",
  27. props: {
  28. // 正面
  29. obverseUrl: {
  30. type: String,
  31. default: ""
  32. },
  33. // 反面
  34. reverseUrl: {
  35. type: String,
  36. default: ""
  37. },
  38. // album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
  39. sourceType: {
  40. type: Array || Object,
  41. default: () => {
  42. return ['album', 'camera']
  43. }
  44. }
  45. },
  46. data() {
  47. return {
  48. obverse: file.obverse,
  49. reverse: file.reverse,
  50. del: file.del,
  51. }
  52. },
  53. created() {
  54. },
  55. methods: {
  56. obverse_btn() {
  57. if (this.obverseUrl) {
  58. // 预览
  59. this.previewImage(this.obverseUrl)
  60. } else {
  61. // 上传
  62. this.select_change("obverse")
  63. }
  64. },
  65. reverse_btn() {
  66. if (this.reverseUrl) {
  67. // 预览
  68. this.previewImage(this.reverseUrl)
  69. } else {
  70. // 上传
  71. this.select_change("reverse")
  72. }
  73. },
  74. // 上传
  75. select_change(name) {
  76. uni.chooseImage({
  77. count: 1, //默认9
  78. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  79. sourceType: this.sourceType, // 从相册选择
  80. success: (res) => {
  81. this.$emit("selectChange", {
  82. msg: `${name}Image:ok`,
  83. name,
  84. tempFilePath: res.tempFilePaths[0],
  85. tempFile: res.tempFiles[0]
  86. })
  87. }
  88. });
  89. },
  90. // 预览
  91. previewImage(current = 0) {
  92. uni.previewImage({
  93. current,
  94. urls: [this.obverseUrl, this.reverseUrl],
  95. });
  96. },
  97. // 删除
  98. del_btn(name) {
  99. console.log(name)
  100. this.$emit("del", {
  101. name,
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped lang="less">
  108. @imgWidth: 345rpx;
  109. @imgheight: 220rpx;
  110. @boxheight: 280rpx;
  111. .Rboy-box {
  112. display: flex;
  113. justify-content: space-between;
  114. // align-items: center;
  115. .Rboy-obverse {
  116. border-radius: 10rpx;
  117. width: @imgWidth;
  118. height: @boxheight;
  119. overflow: hidden;
  120. display: flex;
  121. flex-direction: column;
  122. position: relative;
  123. .obverseimg {
  124. width: @imgWidth;
  125. height: @imgheight;
  126. }
  127. .bottom {
  128. text-align: center;
  129. height: calc(@boxheight - @imgheight);
  130. background-color: #B7D7FF;
  131. color: #3B5FD2;
  132. font-size: 28rpx;
  133. display: flex;
  134. align-items: center;
  135. justify-content: center;
  136. }
  137. .del_btn {
  138. position: absolute;
  139. top: 5rpx;
  140. right: 5rpx;
  141. width: 50rpx;
  142. height: 50rpx;
  143. border-radius: 50%;
  144. z-index: 20;
  145. }
  146. }
  147. .Rboy-reverse {
  148. border-radius: 10rpx;
  149. width: @imgWidth;
  150. height: @boxheight;
  151. overflow: hidden;
  152. display: flex;
  153. flex-direction: column;
  154. position: relative;
  155. .reverseimg {
  156. width: @imgWidth;
  157. height: @imgheight;
  158. }
  159. .bottom {
  160. text-align: center;
  161. height: calc(@boxheight - @imgheight);
  162. background-color: #B7D7FF;
  163. color: #3B5FD2;
  164. font-size: 28rpx;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. }
  169. .del_btn {
  170. position: absolute;
  171. top: 5rpx;
  172. right: 5rpx;
  173. width: 50rpx;
  174. height: 50rpx;
  175. border-radius: 50%;
  176. z-index: 20;
  177. }
  178. }
  179. }
  180. </style>