enter-navigator.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view class="container">
  3. <view class="robot">
  4. <image src="../../static/nav_robot.png" mode="aspectFit"></image>
  5. </view>
  6. <view class="titleText">SmartAssistant</view>
  7. <view class="selectContent">
  8. <view class="select_box" v-for="(item, index) in dataList" :key="index" @click="clickToItem(item, index)">
  9. {{ item }}
  10. </view>
  11. </view>
  12. <view class="userState_login" v-if="is_login == false">
  13. <view class="user_regist" @click="clickToRegist">注册</view>
  14. <view class="user_login" @click="clickToLogin">登录</view>
  15. </view>
  16. <view class="userState_logout userState_login" v-else @click="clickToLogout">退出登录</view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. dataList: ['首页', 'AI聊天', 'AI画图'],
  24. currenIndex: this.selectedIndex,
  25. is_login: false
  26. }
  27. },
  28. props: {
  29. selectedIndex: {
  30. type: Number,
  31. default: 0
  32. }
  33. },
  34. watch: {
  35. selectedIndex: {
  36. handler(newVal) {
  37. this.currenIndex = newVal
  38. },
  39. immediate: true
  40. },
  41. },
  42. mounted() {
  43. this.is_login = this.tools.is_login()
  44. this.$emit('clickToIndex', this.currenIndex)
  45. let self = this
  46. uni.$on(this.config.notification.login_state_changed, function() {
  47. self.is_login = self.tools.is_login()
  48. })
  49. },
  50. onUnload() {
  51. uni.$off(this.config.notification.login_state_changed)
  52. },
  53. methods:{
  54. clickToItem(item, index) {
  55. if(this.currenIndex === index) {
  56. return
  57. }
  58. this.currenIndex = index
  59. this.$emit('clickToIndex', index)
  60. },
  61. clickToRegist() {
  62. uni.showToast({
  63. icon:'none',
  64. title:'暂时无法注册',
  65. duration:2000
  66. })
  67. },
  68. clickToLogin() {
  69. if(this.tools.is_login()) {
  70. console.log('已登录了')
  71. return
  72. }
  73. uni.navigateTo({
  74. url:'/pages/login/login'
  75. })
  76. },
  77. clickToLogout() {
  78. let self = this
  79. uni.showModal({
  80. title:'是否退出登录',
  81. success: function(res) {
  82. if(res.confirm) {
  83. self.tools.request_logout(self, (success)=>{
  84. if(success === true) {
  85. uni.showToast({
  86. title:'已退出登录',
  87. duration:2000
  88. })
  89. }
  90. })
  91. }
  92. }
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss">
  99. .container{
  100. position: fixed;
  101. width: 100%;
  102. height: 60px;
  103. top: 0%;
  104. left: 0;
  105. background: linear-gradient(to right, #303373, #C9A391);
  106. display: flex;
  107. box-sizing: border-box;
  108. align-items: center;
  109. .robot{
  110. flex-shrink: 0;
  111. width: 48px;
  112. height: 48px;
  113. margin-left: 15px;
  114. image{
  115. width: 100%;
  116. height: 100%;
  117. }
  118. }
  119. .titleText{
  120. display: flex;
  121. margin-left: 10px;
  122. // height: 100%;
  123. font-size: 30px;
  124. font-weight: 500;
  125. color: #ffffff;
  126. }
  127. .selectContent{
  128. display: flex;
  129. flex-direction: row;
  130. height: 100%;
  131. align-items: center;
  132. .select_box{
  133. display: flex;
  134. margin-left: 40px;
  135. color: #ffffff;
  136. }
  137. }
  138. .userState_login{
  139. position: absolute;
  140. display: flex;
  141. box-sizing: border-box;
  142. height: 100%;
  143. top: 0px;
  144. right: 15px;
  145. align-items: center;
  146. .user_regist{
  147. display: flex;
  148. width: 65px;
  149. height: 28px;
  150. border-radius: 28px;
  151. font-size: 16px;
  152. color: #878787;
  153. background-color: #ffffff;
  154. justify-content: center;
  155. align-items: center;
  156. }
  157. .user_login{
  158. display: flex;
  159. width: 65px;
  160. height: 28px;
  161. border-radius: 28px;
  162. font-size: 16px;
  163. color: #ffffff;
  164. background-color: #4C9CF1;
  165. justify-content: center;
  166. align-items: center;
  167. margin-left: 15px;
  168. }
  169. }
  170. .userState_logout{
  171. width: 145px;
  172. color: #ffffff;
  173. font-size: 18px;
  174. justify-content: center;
  175. }
  176. }
  177. </style>