Login.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="container">
  3. <view>
  4. <!-- 提示信息弹窗 -->
  5. <uni-popup ref="message" type="message">
  6. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  7. </uni-popup>
  8. </view>
  9. </view>
  10. <view
  11. style="background-image:url(../../static/bg1.svg) ;height: 100vh;background-size: cover;background-color: #beb685;">
  12. <view class="flex-item flex-item-V uni-bg-red">
  13. <view style="height: 50px;padding: 30px;">
  14. <view class="title"><strong style="color: #414100 ;">艺术监测考试</strong></view>
  15. </view>
  16. </view>
  17. <view class="flex-item flex-item-V uni-bg-green">
  18. <view class="uni-flex uni-row">
  19. <view class="flex-item uni-bg-green">
  20. <view class="grid-content bg-purple-light" style="margin: auto">
  21. <form>
  22. <input class="uni-input" v-model="form.name" type="text" placeholder=" 账号" />
  23. <br />
  24. <br />
  25. <button type="primary" @click="submitUser"
  26. style="width: 400px;font-size: 20px;box-shadow: 2px 2px 5px #aaaaaa;">登 录
  27. </button>
  28. </form>
  29. </view>
  30. </view>
  31. <view class="flex-item uni-bg-blue">
  32. </view>
  33. </view>
  34. <uni-card :title="'浏览器下载和音频测试'"
  35. style="position: fixed;right: 10px;bottom: 10px;background-color: #a4c1bd;width: 280px;height: 180px;border-radius: 25px;padding: 20px;">
  36. <strong><uni-link href="https://browser.360.cn/" text="360浏览器" color="#780002"></uni-link> /
  37. <uni-link href="https://www.microsoft.com/zh-cn/edge/download" text="Edge浏览器"
  38. color="#780002"></uni-link> /
  39. <uni-link href="https://www.google.cn/intl/zh-CN/chrome/browser-tools/" text="谷歌浏览器"
  40. color="#780002"></uni-link></strong>
  41. <view style="width: 95%;height: 60%;background-color: #adab6f;padding: 2%;border-radius: 5px;">
  42. <slider :value="sliderValue" @change="onSliderChange" max="100" style="width: 85%;" :block-size='15'
  43. block-color='#A2ABAA' activeColor='#19C590'></slider>
  44. <button @click="onplay()"
  45. style="width: 40%;display: inline-block;margin: 0 4% ;padding: 2px;">播放/暂停</button>
  46. <button @click="stop()"
  47. style="width: 40%;display: inline-block;margin: 0 4% ;padding: 2px;">结束</button>
  48. </view>
  49. </uni-card>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getSysLogin,
  56. sysIp,
  57. sysPort,
  58. request,
  59. } from '../../examJs/examRequest';
  60. import {
  61. redirectTo
  62. } from '../../examJs/examRoute';
  63. export default {
  64. data() {
  65. return {
  66. form: {
  67. name: '',
  68. },
  69. type: 'center',
  70. msgType: 'success',
  71. messageText: '这是一条成功提示',
  72. value: '',
  73. innerAudioContext: null,
  74. audio: true,
  75. sliderValue: null,
  76. intervalIDqw: null,
  77. intervalIDs: null,
  78. duration: '',
  79. currentTime: '',
  80. }
  81. },
  82. methods: {
  83. messageToggle(type, message) {
  84. this.msgType = type
  85. this.messageText = message
  86. this.$refs.message.open()
  87. },
  88. submitUser() {
  89. if (this.form.name.toString().trim().length === 0) {
  90. this.messageToggle('error', "账号不能为空")
  91. return
  92. }
  93. getSysLogin({
  94. captcha: "",
  95. loginType: 2,
  96. password: "123456",
  97. username: this.form.name,
  98. t: Date.now()
  99. }).then(data => {
  100. console.log(data);
  101. if (data.data.code === 200) {
  102. console.log(data);
  103. this.messageToggle('success', data.data.message)
  104. console.log(data);
  105. sessionStorage.setItem("token", data.data.result.token)
  106. console.log(data);
  107. let user = JSON.stringify(data.data.result.userInfo)
  108. sessionStorage.removeItem("user")
  109. sessionStorage.setItem("user", user)
  110. this.stop()
  111. redirectTo('/pages/examPage/examInfo');
  112. } else {
  113. this.messageToggle('error', data.data.message)
  114. }
  115. })
  116. .catch(err => {
  117. this.messageToggle('error', "网络质量不佳,请重试")
  118. })
  119. },
  120. onplay() {
  121. if (this.audio) {
  122. this.audio = false
  123. this.innerAudioContext.play();
  124. this.intervalIDs = setInterval(() => {
  125. if (this.innerAudioContext.duration !== 0) {
  126. // clearInterval(intervalID);
  127. this.duration = this.formatTime(this.innerAudioContext.duration) // 总时长
  128. this.currentTime = this.formatTime(this.innerAudioContext.currentTime) // 当前时长
  129. if (this.currentTime === this.duration) {
  130. clearInterval(this.intervalIDs);
  131. }
  132. }
  133. }, 500);
  134. // 启动定时器,每秒更新一次进度条位置
  135. this.intervalIDqw = setInterval(() => {
  136. if (this.innerAudioContext.duration > 0) {
  137. this.sliderValue = (this.innerAudioContext.currentTime / this.innerAudioContext
  138. .duration) * 100;
  139. }
  140. }, 1000)
  141. } else {
  142. this.audio = true
  143. this.innerAudioContext.pause()
  144. clearInterval(this.intervalIDs);
  145. clearInterval(this.intervalIDqw);
  146. }
  147. },
  148. stop() {
  149. this.audio = true
  150. this.innerAudioContext.stop()
  151. this.sliderValue = 0
  152. clearInterval(this.intervalIDs);
  153. clearInterval(this.intervalIDqw);
  154. },
  155. formatTime(seconds) {
  156. const minutes = Math.floor(seconds / 60);
  157. const remainingSeconds = Math.floor(seconds % 60);
  158. return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
  159. },
  160. onSliderChange(event) {
  161. const value = event.detail.value;
  162. if (this.innerAudioContext && this.innerAudioContext.duration > 0) {
  163. // 验证 value 是否是有效的百分比值(0-100之间)
  164. if (isNaN(value) || value < 0 || value > 100) {
  165. console.error("Invalid value:", value);
  166. return;
  167. }
  168. // 计算新的位置
  169. const newPosition = (value / 100) * this.innerAudioContext.duration;
  170. // 验证 newPosition 是否是有效的数字,不是 NaN,并且在有效范围内
  171. if (!isNaN(newPosition) && newPosition >= 0 && newPosition <= this.innerAudioContext.duration) {
  172. // 设置音频播放位置
  173. this.innerAudioContext.seek(newPosition);
  174. console.log("Seeking to position:", newPosition);
  175. if (!this.dragging) { // 避免拖动滑块时自动更新
  176. this.sliderValue = value;
  177. }
  178. } else {
  179. console.error("Invalid newPosition:", newPosition);
  180. }
  181. }
  182. },
  183. doKey(e) {
  184. const ev = e || window.event // 获取event对象
  185. if (ev.keyCode === 13) {
  186. this.submitUser()
  187. }
  188. },
  189. },
  190. mounted() {
  191. if (sessionStorage.getItem("token") !== undefined && sessionStorage.getItem("token") !== null && sessionStorage
  192. .getItem("token") !== "") {
  193. redirectTo('/pages/examPage/examInfo');
  194. }
  195. this.innerAudioContext = uni.createInnerAudioContext();
  196. this.innerAudioContext.src = 'http://'+sysIp+':'+sysPort+'/exam-boot/sys/common/static/2025/2/jeditor/中华人民共和国国歌_1739236577891.mp3';
  197. document.onkeydown = this.doKey
  198. }
  199. }
  200. </script>
  201. <style>
  202. .uni-input {
  203. padding-left: 20px;
  204. border: 1rpx solid #EEEEEE;
  205. height: 50px;
  206. box-shadow: 2px 2px 5px #aaaaaa;
  207. margin: auto;
  208. margin-top: 25vh;
  209. color: #000000;
  210. width: 380px;
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. }
  215. .content {
  216. display: flex;
  217. flex-direction: column;
  218. align-items: center;
  219. justify-content: center;
  220. }
  221. .logo {
  222. height: 200rpx;
  223. width: 200rpx;
  224. margin-top: 200rpx;
  225. margin-left: auto;
  226. margin-right: auto;
  227. margin-bottom: 50rpx;
  228. }
  229. .text-area {
  230. display: flex;
  231. justify-content: center;
  232. }
  233. .title {
  234. font-family: '微软雅黑', serif;
  235. font-size: 40px;
  236. color: #000000;
  237. width: 600px;
  238. text-align: center;
  239. margin: 0 auto 0 auto;
  240. }
  241. </style>