index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="login">
  3. <topBar />
  4. <div class="login-content">
  5. <div class="login-content-left" />
  6. <div class="login-content-right">
  7. <p>Hello, 欢迎登录</p>
  8. <div>
  9. <Icon
  10. name="server"
  11. :size="25"
  12. />
  13. <input
  14. v-model="url"
  15. type="text"
  16. placeholder="mqtts://*******"
  17. maxlength="50"
  18. >
  19. </div>
  20. <div>
  21. <Icon
  22. name="username"
  23. :size="25"
  24. />
  25. <input
  26. v-model="room"
  27. type="text"
  28. placeholder="请输入房间"
  29. maxlength="20"
  30. >
  31. </div>
  32. <div>
  33. <Icon
  34. name="password"
  35. :size="25"
  36. />
  37. <input
  38. v-model="name"
  39. type="text"
  40. placeholder="请输入名称"
  41. maxlength="20"
  42. >
  43. </div>
  44. <span>{{ err }}</span>
  45. <div>
  46. <n-button
  47. type="info"
  48. block
  49. :disabled="disabled"
  50. @click="login"
  51. >
  52. 加入
  53. </n-button>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </template>
  59. <script setup lang="ts">
  60. import {
  61. computed, onUnmounted, ref, watch
  62. } from 'vue'
  63. import topBar from '@/components/topBar.vue'
  64. import useStore from '@/store/index'
  65. import MqttService from '@/services/mqtt.service'
  66. const err = ref('')
  67. const name = ref('test123')
  68. const room = ref('test')
  69. const url = ref('mqtts://caner.top:49659')
  70. const disabled = computed(() => !name.value || !room.value || !url.value || !url.value.startsWith('mqtts:'))
  71. const store = useStore()
  72. const mqtt = new MqttService()
  73. async function login() {
  74. if (disabled.value) return
  75. await mqtt.connect(url.value, room.value, name.value)
  76. }
  77. watch(() => store.mqtt_message, (val) => {
  78. console.log('监听', val)
  79. })
  80. </script>
  81. <style scoped lang="scss">
  82. .login {
  83. width: 100%;
  84. height: 100%;
  85. font-size: 15px;
  86. display: flex;
  87. justify-content: center;
  88. align-items: center;
  89. background: url(@/assets/img/bg.png) center center no-repeat;
  90. background-size: 100% 100%;
  91. -webkit-app-region: drag;
  92. position: relative;
  93. &-content {
  94. width: 800px;
  95. height: 400px;
  96. background: white;
  97. border-radius: 20px;
  98. display: flex;
  99. overflow: hidden;
  100. &-left {
  101. width: 500px;
  102. background: url(@/assets/img/login-left.png) center center no-repeat;
  103. background-size: 100% 100%;
  104. -webkit-app-region: drag;
  105. }
  106. &-right {
  107. width: 300px;
  108. padding: 0 30px;
  109. -webkit-app-region: no-drag;
  110. overflow: hidden;
  111. &>p {
  112. font-size: 30px;
  113. color: #5970C6;
  114. text-align: left;
  115. font-weight: 400;
  116. text-align: center;
  117. margin-top: 50px;
  118. margin-bottom: 50px;
  119. }
  120. &>div {
  121. padding: 10px 0;
  122. display: flex;
  123. align-items: center;
  124. &:not(:last-child) {
  125. border-bottom: solid 1px #D2D6E7;
  126. }
  127. input {
  128. border: none;
  129. margin-left: 5px;
  130. outline: none;
  131. width: 100%;
  132. font-size: 15px;
  133. color: #333;
  134. &::placeholder {
  135. color: #9DA1A8;
  136. font-size: 15px;
  137. }
  138. }
  139. // button {
  140. // background: #79b8fa;
  141. // border: none;
  142. // outline: none;
  143. // color: white;
  144. // font-size: 16px;
  145. // font-weight: 500;
  146. // border-radius: 10px;
  147. // margin-top: 40px;
  148. // margin-left: auto;
  149. // line-height: 35px;
  150. // padding: 0 35px;
  151. // cursor: not-allowed;
  152. // }
  153. }
  154. &>span {
  155. height: 17px;
  156. color: red;
  157. font-size: 12px;
  158. overflow: hidden;
  159. display: block;
  160. text-overflow: ellipsis;
  161. }
  162. .resetStyle {
  163. background: #2d8cf0;
  164. cursor: pointer;
  165. }
  166. }
  167. }
  168. }
  169. </style>