id-card.vue_bak 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-upload
  5. class="id-card-uploader"
  6. v-show="uploaderShow"
  7. :action="requestUrl"
  8. name="file"
  9. :headers="headers"
  10. :data="formData"
  11. :show-file-list="false"
  12. :before-upload="handleBefore"
  13. :on-success="handleSuccess"
  14. :disabled="uploaderDisabled"
  15. v-loading="uploaderLoading">
  16. <img v-if="imageUrl" :src="imageUrl" class="id-card">
  17. <i v-else class="el-icon-plus id-card-uploader-icon"></i>
  18. </el-upload>
  19. <div class="id-card-show">
  20. <img :src="imageUrl" alt="" width="480">
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import Vue from 'vue';
  27. import {REQUEST_URL, ACCESS_TOKEN_PREFIX} from '@/utils/config';
  28. import network from './../../utils/network';
  29. import userInfo from '@/utils/userInfo';
  30. import tool from './../../utils/tool';
  31. import store from '@/utils/vuexStore';
  32. export default {
  33. name: "user_index",
  34. mounted(){
  35. this.getData();
  36. },
  37. data(){
  38. return {
  39. uploaderShow: true,
  40. imageUrl : '',
  41. loading: false,
  42. uploaderLoading: false,
  43. formData: {
  44. 'uploadToken': '',
  45. },
  46. requestUrl: `${REQUEST_URL}user/id-card`,
  47. headers:{
  48. 'Device-Type':'pc',
  49. 'Suppress-Response-Code': '1',
  50. 'Authorization' : ACCESS_TOKEN_PREFIX+userInfo.accessToken(),
  51. },
  52. uploaderDisabled: false,
  53. }
  54. },
  55. methods: {
  56. handleBefore(){
  57. this.uploaderLoading = true;
  58. },
  59. handleSuccess(response, file){
  60. if(response.success){
  61. this.$message({
  62. message: '上传成功',
  63. type: 'success'
  64. });
  65. this.imageUrl = URL.createObjectURL(file.raw);
  66. this.uploaderShow = false;
  67. this.uploaderDisabled = true;
  68. this.uploaderLoading = false;
  69. } else {
  70. this.$message({
  71. message: response.data.message,
  72. type: 'warning'
  73. });
  74. this.uploaderLoading = false;
  75. }
  76. },
  77. getData(){
  78. network.getData('user/id-card').then(response=>{
  79. if(response.ID_IMAGE){
  80. this.imageUrl = response.ID_IMAGE;
  81. this.uploaderShow = false;
  82. this.uploaderDisabled = true;
  83. } else {
  84. this.formData.uploadToken = response;
  85. }
  86. this.loading = false;
  87. });
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. .id-card-uploader {
  94. width: 480px;
  95. height: 320px;
  96. border: 1px dashed #d9d9d9;
  97. border-radius: 6px;
  98. cursor: pointer;
  99. position: relative;
  100. overflow: hidden;
  101. }
  102. .id-card-uploader:hover {
  103. border-color: #409EFF;
  104. }
  105. .id-card-uploader-icon {
  106. font-size: 28px;
  107. color: #8c939d;
  108. width: 480px;
  109. height: 320px;
  110. line-height: 320px;
  111. text-align: center;
  112. }
  113. .id-card {
  114. width: 480px;
  115. height: 320px;
  116. display: block;
  117. }
  118. </style>