Cropper.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div class="wrapper" v-show="visible">
  3. <div class="model" v-show="model" @click="model = false">
  4. <div class="model-show">
  5. <img :src="modelSrc" alt="">
  6. </div>
  7. </div>
  8. <div class="content">
  9. <div class="show-info">
  10. <div class="test" :style="'width:'+cwidth+'px;height:'+cheight+'px'">
  11. <vueCropper ref="cropper" :img="cropper.img " :outputSize="cropper.size" :outputType="cropper.outputType" :info="cropper.info"
  12. :canScale="cropper.canScale" :autoCrop="cropper.autoCrop" :autoCropWidth="cropper.autoCropWidth" :autoCropHeight="cropper.autoCropHeight"
  13. :fixed="cropper.fixed" :fixedNumber="cropper.fixedNumber" :enlarge="4"></vueCropper>
  14. </div>
  15. <div style="margin-top: 10px;">
  16. <button type="button" @click="cancel" class="mui-btn">取消</button>
  17. <button type="button" @click="finish" class="mui-btn" style="float: right;">选取</button>
  18. </div>
  19. <div style="font-size: 14px;margin-top: 10px;line-height: 20px;color: red;">1.照片用于人脸识别设备,请上传清晰免冠登记照或肩部以上近照。</div>
  20. <div style="font-size: 14px;margin-top: 10px;line-height: 20px;color: #888888;">2.可以拖动图片或双手指缩放图片,最好让照片填满马赛克边框。</div>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import {
  27. VueCropper
  28. } from 'vue-cropper'
  29. export default {
  30. name: 'TopHeader',
  31. props: {
  32. cropper: {
  33. require: true,
  34. type: Object,
  35. default: () => ({
  36. //img的路径自行修改
  37. img: '',
  38. info: true,
  39. size: 0.8,
  40. outputType: 'jpeg',
  41. canScale: false,
  42. autoCrop: true,
  43. // 只有自动截图开启 宽度高度才生效
  44. autoCropWidth: 250,
  45. autoCropHeight: 350,
  46. fixed: true,
  47. // 真实的输出宽高
  48. infoTrue: true,
  49. fixedNumber: [5, 7]
  50. })
  51. },
  52. visible: {
  53. require: false,
  54. default: false,
  55. },
  56. field: {
  57. require: false,
  58. default: 'pic'
  59. },
  60. cwidth: {
  61. require: false,
  62. default: 250
  63. },
  64. cheight: {
  65. require: false,
  66. default: 350
  67. },
  68. },
  69. components: {
  70. VueCropper,
  71. },
  72. created() {},
  73. data() {
  74. return {
  75. model: false,
  76. modelSrc: '',
  77. }
  78. },
  79. methods: {
  80. //点击裁剪,这一步是可以拿到处理后的地址
  81. finish() {
  82. this.$refs.cropper.goAutoCrop();
  83. this.$refs.cropper.getCropData((data) => {
  84. this.modelSrc = data
  85. this.model = false;
  86. //裁剪后的图片显示
  87. this.cropper.img = this.modelSrc;
  88. //console.log(data)
  89. this.$emit('cropperFinish', {
  90. field: this.field,
  91. data: data
  92. });
  93. })
  94. },
  95. cancel() {
  96. this.$emit('cropperCancel');
  97. }
  98. },
  99. }
  100. </script>
  101. <style scoped>
  102. /* * {
  103. margin: 0;
  104. padding: 0;
  105. } */
  106. .wrapper {
  107. position: fixed;
  108. width: 100%;
  109. top: 0;
  110. background: #f1f1f1;
  111. z-index: 99;
  112. height: 100%;
  113. }
  114. .content {
  115. margin: auto;
  116. max-width: 585px;
  117. margin-bottom: 100px;
  118. }
  119. .test-button {
  120. display: flex;
  121. flex-wrap: wrap;
  122. }
  123. .btn {
  124. display: inline-block;
  125. line-height: 1;
  126. white-space: nowrap;
  127. cursor: pointer;
  128. background: #fff;
  129. border: 1px solid #c0ccda;
  130. color: #1f2d3d;
  131. text-align: center;
  132. box-sizing: border-box;
  133. outline: none;
  134. margin: 20px 10px 0px 0px;
  135. padding: 9px 15px;
  136. font-size: 14px;
  137. border-radius: 4px;
  138. color: #fff;
  139. background-color: #50bfff;
  140. border-color: #50bfff;
  141. transition: all .2s ease;
  142. text-decoration: none;
  143. user-select: none;
  144. }
  145. .des {
  146. line-height: 30px;
  147. }
  148. code.language-html {
  149. padding: 10px 20px;
  150. margin: 10px 0px;
  151. display: block;
  152. background-color: #333;
  153. color: #fff;
  154. overflow-x: auto;
  155. font-family: Consolas, Monaco, Droid, Sans, Mono, Source, Code, Pro, Menlo, Lucida, Sans, Type, Writer, Ubuntu, Mono;
  156. border-radius: 5px;
  157. white-space: pre;
  158. }
  159. .show-info {
  160. margin-bottom: 50px;
  161. }
  162. .show-info h2 {
  163. line-height: 50px;
  164. }
  165. .title {
  166. display: block;
  167. text-decoration: none;
  168. text-align: center;
  169. line-height: 1.5;
  170. margin: 20px 0px;
  171. background-image: -webkit-linear-gradient(left, #3498db, #f47920 10%, #d71345 20%, #f7acbc 30%, #ffd400 40%, #3498db 50%, #f47920 60%, #d71345 70%, #f7acbc 80%, #ffd400 90%, #3498db);
  172. color: transparent;
  173. -webkit-background-clip: text;
  174. background-size: 200% 100%;
  175. animation: slide 5s infinite linear;
  176. font-size: 40px;
  177. }
  178. .test {
  179. height: 285px;
  180. }
  181. .model {
  182. position: fixed;
  183. z-index: 10;
  184. width: 100vw;
  185. height: 100vh;
  186. overflow: auto;
  187. top: 0;
  188. left: 0;
  189. background: rgba(0, 0, 0, 0.8);
  190. }
  191. .model-show {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. width: 100vw;
  196. height: 100vh;
  197. }
  198. .model img {
  199. display: block;
  200. margin: auto;
  201. max-width: 80%;
  202. user-select: none;
  203. background-position: 0px 0px, 10px 10px;
  204. background-size: 20px 20px;
  205. background-image: linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%), linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);
  206. }
  207. .c-item {
  208. display: block;
  209. padding: 10px 0;
  210. user-select: none;
  211. }
  212. @keyframes slide {
  213. 0% {
  214. background-position: 0 0;
  215. }
  216. 100% {
  217. background-position: -100% 0;
  218. }
  219. }
  220. @media screen and (max-width: 1000px) {
  221. .content {
  222. max-width: 90%;
  223. margin: auto;
  224. }
  225. .test {
  226. margin-top: 10%;
  227. width: 250px;
  228. height: 350px;
  229. margin: 10% auto 0 auto;
  230. }
  231. }
  232. </style>