enter-navigator.vue 4.3 KB

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