enter-navigator.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. export default {
  24. data() {
  25. return {
  26. dataList: [{'t': '首页', 's_icon': '/static/navigator/navigator_home.png'},
  27. {'t': 'AI聊天', 's_icon': '/static/navigator/navigator_chat.png'},
  28. {'t': 'AI画图', 's_icon': '/static/navigator/navigator_draw.png'}],
  29. currenIndex: this.selectedIndex,
  30. is_login: false
  31. }
  32. },
  33. props: {
  34. selectedIndex: {
  35. type: Number,
  36. default: 0
  37. }
  38. },
  39. watch: {
  40. selectedIndex: {
  41. handler(newVal) {
  42. this.currenIndex = newVal
  43. },
  44. immediate: true
  45. },
  46. },
  47. mounted() {
  48. this.is_login = this.tools.is_login()
  49. this.$emit('clickToIndex', this.currenIndex)
  50. let self = this
  51. uni.$on(this.config.notification.login_state_changed, function() {
  52. self.is_login = self.tools.is_login()
  53. })
  54. },
  55. onUnload() {
  56. uni.$off(this.config.notification.login_state_changed)
  57. },
  58. methods:{
  59. clickToItem(item, index) {
  60. if(this.currenIndex === index) {
  61. return
  62. }
  63. this.currenIndex = index
  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. title:'是否退出登录',
  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. width: 100%;
  107. height: 60px;
  108. top: 0%;
  109. left: 0;
  110. background: linear-gradient(to right, #303373, #C9A391);
  111. display: flex;
  112. box-sizing: border-box;
  113. align-items: center;
  114. .robot{
  115. flex-shrink: 0;
  116. width: 48px;
  117. height: 48px;
  118. margin-left: 15px;
  119. image{
  120. width: 100%;
  121. height: 100%;
  122. }
  123. }
  124. .titleText{
  125. display: flex;
  126. margin-left: 10px;
  127. // height: 100%;
  128. font-size: 30px;
  129. font-weight: 500;
  130. color: #ffffff;
  131. }
  132. .navigatorContent{
  133. display: flex;
  134. flex-direction: row;
  135. height: 100%;
  136. align-items: center;
  137. .navigator_box{
  138. display: flex;
  139. margin-left: 30px;
  140. width: 80px;
  141. height: 67px;
  142. justify-content: center;
  143. align-items: center;
  144. .navigator_box_normal{
  145. font-size: 20px;
  146. color: #ffffff;
  147. }
  148. .navigator_box_selected{
  149. width: 55px;
  150. height: 40px;
  151. image{
  152. width: 100%;
  153. height: 100%;
  154. }
  155. }
  156. }
  157. }
  158. .userState_login{
  159. position: absolute;
  160. display: flex;
  161. box-sizing: border-box;
  162. height: 100%;
  163. top: 0px;
  164. right: 15px;
  165. align-items: center;
  166. .user_regist{
  167. display: flex;
  168. width: 65px;
  169. height: 28px;
  170. border-radius: 28px;
  171. font-size: 16px;
  172. color: #878787;
  173. background-color: #ffffff;
  174. justify-content: center;
  175. align-items: center;
  176. }
  177. .user_login{
  178. display: flex;
  179. width: 65px;
  180. height: 28px;
  181. border-radius: 28px;
  182. font-size: 16px;
  183. color: #ffffff;
  184. background-color: #4C9CF1;
  185. justify-content: center;
  186. align-items: center;
  187. margin-left: 15px;
  188. }
  189. }
  190. .userState_logout{
  191. width: 145px;
  192. color: #ffffff;
  193. font-size: 18px;
  194. justify-content: center;
  195. }
  196. }
  197. </style>