Login.vue 7.3 KB

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