Home.vue 3.4 KB

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