Home.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="home">
  3. <section>
  4. <MCover :width="width">
  5. <template #center="{ active, target }">
  6. <template v-if="active">
  7. <MCamera
  8. v-if="tab === 0"
  9. @reject="$event => handleReject($event, target)"
  10. @error="handleError"
  11. @photo="handleGet"
  12. @close="target(false)">
  13. </MCamera>
  14. <MFeature
  15. v-if="tab === 1"
  16. :items="face"
  17. @reTake="tab = 0; width = '480px'"
  18. @click:try="handleTry"
  19. @error="handleError"
  20. ></MFeature>
  21. <MTry
  22. v-if="tab === 2"
  23. :src="imgBase64"
  24. :item="tryItem"
  25. @feature="tab = 1; width = '80%'"
  26. @retake="tab = 0; width = '480px'"
  27. ></MTry>
  28. </template>
  29. </template>
  30. </MCover>
  31. </section>
  32. <modal name="VueDialog" height="200" width="350">
  33. <div class="model">
  34. <div class="model-title">提示</div>
  35. <div class="model-content">{{ error }}</div>
  36. <div class="model-btn">
  37. <button class="btn" @click="$modal.hide('VueDialog')">关闭</button>
  38. </div>
  39. </div>
  40. </modal>
  41. </div>
  42. </template>
  43. <script>
  44. import MCover from './components/MCover'
  45. import MCamera from './components/MCamera'
  46. import MFeature from './components/MFeature'
  47. import MTry from './components/MTry'
  48. export default {
  49. name: 'home-view',
  50. components: {
  51. MCover,
  52. MCamera,
  53. MFeature,
  54. MTry
  55. },
  56. provide: {
  57. size: {
  58. width: 480,
  59. height: 640
  60. }
  61. },
  62. data () {
  63. return {
  64. imgBase64: '',
  65. tab: 0,
  66. width: '480px',
  67. error: '',
  68. tryItem: {}
  69. }
  70. },
  71. methods: {
  72. handleError (error) {
  73. this.error = error
  74. this.$modal.show('VueDialog')
  75. },
  76. handleReject (error, target) {
  77. this.width = '480px'
  78. this.tab = 0
  79. target && target(false)
  80. if (error) {
  81. this.error = error
  82. this.$modal.show('VueDialog')
  83. }
  84. },
  85. handleGet (data, imgBase64) {
  86. this.imgBase64 = imgBase64
  87. this.face = data
  88. this.width = '80%'
  89. this.tab = 1
  90. },
  91. handleTry (item) {
  92. this.tryItem = item
  93. this.width = '480px'
  94. this.tab = 2
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped lang="less">
  100. section {
  101. height: 100vh;
  102. width: 100vw;
  103. }
  104. .home {
  105. height: 100vh;
  106. width: 100vw;
  107. overflow: hidden;
  108. }
  109. .model{
  110. padding: 20px;
  111. &-title {
  112. font-size: 24px;
  113. font-weight: bolder;
  114. margin-bottom: 12px;
  115. }
  116. &-content {
  117. font-size: 14px;
  118. color: #666;
  119. margin-bottom: 12px;
  120. &-link {
  121. color: #141e8c;
  122. cursor: pointer;
  123. }
  124. }
  125. &-btn {
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. .btn {
  130. -webkit-tap-highlight-color: transparent;
  131. width: 100px;
  132. height: 40px;
  133. border-radius: 20px;
  134. background: #eee;
  135. color: #666;
  136. border: none;
  137. outline: none;
  138. cursor: pointer;
  139. }
  140. ._primary {
  141. background: #141e8c;
  142. color: #fff;
  143. }
  144. .default {
  145. background: #eee;
  146. color: #666;
  147. }
  148. }
  149. }
  150. </style>