Home.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 = CLIENT_WIDTH + 'px'"
  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 = CLIENT_WIDTH + 'px'"
  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. const CLIENT_WIDTH = window.innerWidth < 480 ? window.innerWidth : 480
  49. export default {
  50. name: 'home-view',
  51. components: {
  52. MCover,
  53. MCamera,
  54. MFeature,
  55. MTry
  56. },
  57. provide: {
  58. size: {
  59. width: CLIENT_WIDTH,
  60. height: window.innerWidth < 480 ? window.innerWidth / 480 * 640 : 640
  61. }
  62. },
  63. data () {
  64. return {
  65. CLIENT_WIDTH,
  66. imgBase64: '',
  67. tab: 0,
  68. width: `${CLIENT_WIDTH}px`,
  69. error: '',
  70. tryItem: {}
  71. }
  72. },
  73. methods: {
  74. handleError (error) {
  75. this.error = error
  76. this.$modal.show('VueDialog')
  77. },
  78. handleReject (error, target) {
  79. this.width = CLIENT_WIDTH + 'px'
  80. this.tab = 0
  81. target && target(false)
  82. if (error) {
  83. this.error = error
  84. this.$modal.show('VueDialog')
  85. }
  86. },
  87. handleGet (data, imgBase64) {
  88. this.imgBase64 = imgBase64
  89. this.face = data
  90. this.width = '80%'
  91. this.tab = 1
  92. },
  93. handleTry (item) {
  94. this.tryItem = item
  95. this.width = CLIENT_WIDTH + 'px'
  96. this.tab = 2
  97. }
  98. }
  99. }
  100. </script>
  101. <style scoped lang="less">
  102. section {
  103. height: 100vh;
  104. width: 100vw;
  105. }
  106. .home {
  107. height: 100vh;
  108. width: 100vw;
  109. overflow: hidden;
  110. }
  111. .model{
  112. padding: 20px;
  113. &-title {
  114. font-size: 24px;
  115. font-weight: bolder;
  116. margin-bottom: 12px;
  117. }
  118. &-content {
  119. font-size: 14px;
  120. color: #666;
  121. margin-bottom: 12px;
  122. &-link {
  123. color: #141e8c;
  124. cursor: pointer;
  125. }
  126. }
  127. &-btn {
  128. display: flex;
  129. align-items: center;
  130. justify-content: center;
  131. .btn {
  132. -webkit-tap-highlight-color: transparent;
  133. width: 100px;
  134. height: 40px;
  135. border-radius: 20px;
  136. background: #eee;
  137. color: #666;
  138. border: none;
  139. outline: none;
  140. cursor: pointer;
  141. }
  142. ._primary {
  143. background: #141e8c;
  144. color: #fff;
  145. }
  146. .default {
  147. background: #eee;
  148. color: #666;
  149. }
  150. }
  151. }
  152. </style>