enter-navigator.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.$emit('clickToIndex', index)
  64. },
  65. clickToRegist() {
  66. uni.showToast({
  67. icon:'none',
  68. title:'暂时无法注册',
  69. duration:2000
  70. })
  71. },
  72. clickToLogin() {
  73. if(this.tools.is_login()) {
  74. console.log('已登录了')
  75. return
  76. }
  77. uni.navigateTo({
  78. url:'/pages/login/login'
  79. })
  80. },
  81. clickToLogout() {
  82. let self = this
  83. uni.showModal({
  84. title:'是否退出登录',
  85. success: function(res) {
  86. if(res.confirm) {
  87. self.tools.request_logout(self, (success)=>{
  88. if(success === true) {
  89. uni.showToast({
  90. title:'已退出登录',
  91. duration:2000
  92. })
  93. }
  94. })
  95. }
  96. }
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. .container{
  104. position: fixed;
  105. width: 100%;
  106. height: 60px;
  107. top: 0%;
  108. left: 0;
  109. background: linear-gradient(to right, #303373, #C9A391);
  110. display: flex;
  111. box-sizing: border-box;
  112. align-items: center;
  113. .robot{
  114. flex-shrink: 0;
  115. width: 48px;
  116. height: 48px;
  117. margin-left: 15px;
  118. image{
  119. width: 100%;
  120. height: 100%;
  121. }
  122. }
  123. .titleText{
  124. display: flex;
  125. margin-left: 10px;
  126. // height: 100%;
  127. font-size: 30px;
  128. font-weight: 500;
  129. color: #ffffff;
  130. }
  131. .navigatorContent{
  132. display: flex;
  133. flex-direction: row;
  134. height: 100%;
  135. align-items: center;
  136. .navigator_box{
  137. display: flex;
  138. margin-left: 30px;
  139. width: 80px;
  140. height: 67px;
  141. justify-content: center;
  142. align-items: center;
  143. .navigator_box_normal{
  144. font-size: 20px;
  145. color: #ffffff;
  146. }
  147. .navigator_box_selected{
  148. width: 55px;
  149. height: 40px;
  150. image{
  151. width: 100%;
  152. height: 100%;
  153. }
  154. }
  155. }
  156. }
  157. .userState_login{
  158. position: absolute;
  159. display: flex;
  160. box-sizing: border-box;
  161. height: 100%;
  162. top: 0px;
  163. right: 15px;
  164. align-items: center;
  165. .user_regist{
  166. display: flex;
  167. width: 65px;
  168. height: 28px;
  169. border-radius: 28px;
  170. font-size: 16px;
  171. color: #878787;
  172. background-color: #ffffff;
  173. justify-content: center;
  174. align-items: center;
  175. }
  176. .user_login{
  177. display: flex;
  178. width: 65px;
  179. height: 28px;
  180. border-radius: 28px;
  181. font-size: 16px;
  182. color: #ffffff;
  183. background-color: #4C9CF1;
  184. justify-content: center;
  185. align-items: center;
  186. margin-left: 15px;
  187. }
  188. }
  189. .userState_logout{
  190. width: 145px;
  191. color: #ffffff;
  192. font-size: 18px;
  193. justify-content: center;
  194. }
  195. }
  196. </style>