Login.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. minioIP,
  57. minioPort,
  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. if (data.data.code === 200) {
  101. this.messageToggle('success', data.data.message)
  102. sessionStorage.setItem("token", data.data.result.token)
  103. let user = JSON.stringify(data.data.result.userInfo)
  104. sessionStorage.removeItem("user")
  105. sessionStorage.setItem("user", user)
  106. this.stop()
  107. redirectTo('/pages/examPage/examInfo');
  108. } else {
  109. this.messageToggle('error', data.data.message)
  110. }
  111. })
  112. .catch(err => {
  113. this.messageToggle('error', "网络质量不佳,请重试")
  114. })
  115. },
  116. onplay() {
  117. if (this.audio) {
  118. this.audio = false
  119. this.innerAudioContext.play();
  120. this.intervalIDs = setInterval(() => {
  121. if (this.innerAudioContext.duration !== 0) {
  122. // clearInterval(intervalID);
  123. this.duration = this.formatTime(this.innerAudioContext.duration) // 总时长
  124. this.currentTime = this.formatTime(this.innerAudioContext.currentTime) // 当前时长
  125. if (this.currentTime === this.duration) {
  126. clearInterval(this.intervalIDs);
  127. }
  128. }
  129. }, 500);
  130. // 启动定时器,每秒更新一次进度条位置
  131. this.intervalIDqw = setInterval(() => {
  132. if (this.innerAudioContext.duration > 0) {
  133. this.sliderValue = (this.innerAudioContext.currentTime / this.innerAudioContext
  134. .duration) * 100;
  135. }
  136. }, 1000)
  137. } else {
  138. this.audio = true
  139. this.innerAudioContext.pause()
  140. clearInterval(this.intervalIDs);
  141. clearInterval(this.intervalIDqw);
  142. }
  143. },
  144. stop() {
  145. this.audio = true
  146. this.innerAudioContext.stop()
  147. this.sliderValue = 0
  148. clearInterval(this.intervalIDs);
  149. clearInterval(this.intervalIDqw);
  150. },
  151. formatTime(seconds) {
  152. const minutes = Math.floor(seconds / 60);
  153. const remainingSeconds = Math.floor(seconds % 60);
  154. return `${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
  155. },
  156. onSliderChange(event) {
  157. const value = event.detail.value;
  158. if (this.innerAudioContext && this.innerAudioContext.duration > 0) {
  159. // 验证 value 是否是有效的百分比值(0-100之间)
  160. if (isNaN(value) || value < 0 || value > 100) {
  161. console.error("Invalid value:", value);
  162. return;
  163. }
  164. // 计算新的位置
  165. const newPosition = (value / 100) * this.innerAudioContext.duration;
  166. // 验证 newPosition 是否是有效的数字,不是 NaN,并且在有效范围内
  167. if (!isNaN(newPosition) && newPosition >= 0 && newPosition <= this.innerAudioContext.duration) {
  168. // 设置音频播放位置
  169. this.innerAudioContext.seek(newPosition);
  170. console.log("Seeking to position:", newPosition);
  171. if (!this.dragging) { // 避免拖动滑块时自动更新
  172. this.sliderValue = value;
  173. }
  174. } else {
  175. console.error("Invalid newPosition:", newPosition);
  176. }
  177. }
  178. },
  179. doKey(e) {
  180. const ev = e || window.event // 获取event对象
  181. if (ev.keyCode === 13) {
  182. this.submitUser()
  183. }
  184. },
  185. },
  186. mounted() {
  187. if (sessionStorage.getItem("token") !== undefined && sessionStorage.getItem("token") !== null && sessionStorage
  188. .getItem("token") !== "") {
  189. redirectTo('/pages/examPage/examInfo');
  190. }
  191. this.innerAudioContext = uni.createInnerAudioContext();
  192. this.innerAudioContext.src = 'http://'+minioIP+':'+minioPort+'/exam-bucket/中华人民共和国国歌.mp3';
  193. document.onkeydown = this.doKey
  194. }
  195. }
  196. </script>
  197. <style>
  198. .uni-input {
  199. padding-left: 20px;
  200. border: 1rpx solid #EEEEEE;
  201. height: 50px;
  202. box-shadow: 2px 2px 5px #aaaaaa;
  203. margin: auto;
  204. margin-top: 25vh;
  205. color: #000000;
  206. width: 380px;
  207. display: flex;
  208. justify-content: center;
  209. align-items: center;
  210. }
  211. .content {
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. justify-content: center;
  216. }
  217. .logo {
  218. height: 200rpx;
  219. width: 200rpx;
  220. margin-top: 200rpx;
  221. margin-left: auto;
  222. margin-right: auto;
  223. margin-bottom: 50rpx;
  224. }
  225. .text-area {
  226. display: flex;
  227. justify-content: center;
  228. }
  229. .title {
  230. font-family: '微软雅黑', serif;
  231. font-size: 40px;
  232. color: #000000;
  233. width: 600px;
  234. text-align: center;
  235. margin: 0 auto 0 auto;
  236. }
  237. </style>