login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="login">
  3. <Headers></Headers>
  4. <image class="bg" src="/static/images/bg.png"></image>
  5. <view class="ddflex" style="flex-direction: column;">
  6. <view class="register ddflex">
  7. <view class="re-con-pic">
  8. <image src="/static/images/loginBg1.png"></image>
  9. </view>
  10. <view class="re-con">
  11. <view class="re-tit">考生登录</view>
  12. <view class="re-li dflex">
  13. <input v-model="testNumber" type="number" placeholder="准考证号" maxlength="-1" placeholder-class="placeholder" class="re-ipt flex" />
  14. </view>
  15. <uni-data-select
  16. v-model="paperId"
  17. :localdata="range"
  18. @change="changeTestPro"
  19. placeholder="考试项目"
  20. ></uni-data-select>
  21. <view class="re-btn" @click="okLogin()">登录</view>
  22. <view class="re-btn-text" @click="queryScore">考生成绩查询</view>
  23. </view>
  24. </view>
  25. <view class="bottom-content ddflex">
  26. <!-- 考试公告 -->
  27. <view class="note-box">
  28. <view class="note-title ddflex">
  29. <image class="note-title-icon" src="/static/images/ksgg.png"></image>
  30. <view>考试公告</view>
  31. </view>
  32. <view>
  33. <view class="note-item ddflex" v-for="item,index in otherInfo" :key="index" @click="jumpUrl('/pages/contentDetail/contentDetail?id='+item.id)">
  34. <view class="note-item-content">{{item.title}}</view>
  35. <view class="note-item-date">{{dateFormat(item.createDate)}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 注意事项 -->
  40. <view class="note-box">
  41. <view class="note-title ddflex">
  42. <image class="note-title-icon" src="/static/images/zysx.png"></image>
  43. <view>注意事项</view>
  44. </view>
  45. <view>
  46. <view class="note-item ddflex" v-for="item,index in noteInfo" :key="index+'zy'" @click="jumpUrl('/pages/contentDetail/contentDetail?id='+item.id)">
  47. <view class="note-item-content">{{item.title}}</view>
  48. <view class="note-item-date">{{dateFormat(item.createDate)}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <uni-popup ref="popup" type="bottom" :is-mask-click='false'>
  55. <view class="popup-box">
  56. <view class="popup-top ddflex">
  57. <view>身份验证</view>
  58. <image src="/static/images/close.png" @click="close()"></image>
  59. </view>
  60. <view class="popup-content">您好!考试前需要进行身份验证,请手持准考证,对准摄像头进行拍照,示例如下</view>
  61. <view style="width: 400px;height: 243px;margin:30px auto;" v-show="!isPhotoing&&!imageUrl">
  62. <img style="width: 100%;height: 100%" src="/static/images/sfyz.png"/>
  63. </view>
  64. <view v-show="isPhotoing" style="width: 400px;height: 243px;margin:30px auto;position: relative;" id="video-box">
  65. <video id="video" style="width: 100%;height: 100%;" object-fit='fill' :autoplay="true" :controls="false" :show-center-play-btn="false"></video>
  66. <canvas id="canvas" style="width: 100%;height: 100%;position: absolute;top:100000px;" canvas-id="canvas"></canvas>
  67. <view style="position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);z-index: 100;font-size: 50px;color: #1AA1E6;font-weight: bold;">{{timeText}}</view>
  68. </view>
  69. <view style="width: 400px;height: 243px;margin:30px auto;" v-show="!isPhotoing&&imageUrl">
  70. <img style="width: 100%;height: 100%" :src="imageUrl"/>
  71. </view>
  72. <view class="popup-bottom ddflex">
  73. <view class="popup-btn2" @click="yanzheng" v-show="!isPhotoing">{{imageUrl?'重新验证':'立即验证'}}</view>
  74. <view class="popup-btn2" v-if="imageUrl" @click="yanzhengSubmit">确认</view>
  75. </view>
  76. </view>
  77. </uni-popup>
  78. <Foot :havaBackground='false'></Foot>
  79. </view>
  80. </template>
  81. <script>
  82. const app = getApp();
  83. const req = require('../../utils/request.js');
  84. const utils = require('../../utils/util.js');
  85. const api = require('../../utils/api.js');
  86. export default {
  87. data() {
  88. return {
  89. title: 'Hello',
  90. width: 115,
  91. height: 36,
  92. testNumber: '',
  93. code: '',
  94. isCheckArg: true,
  95. range:[],
  96. otherInfo:[],//考试公告
  97. noteInfo:[],//注意事项
  98. paperId:'',//考试id
  99. isPhotoing:false,//是否正在验证身份
  100. imageUrl:'',
  101. timeText:3,
  102. timeInterval:null
  103. };
  104. },
  105. onLoad() {
  106. var tha = this;
  107. this.getTestProject()
  108. this.getTextOtherInfo()
  109. this.getTextNoteInfo()
  110. },
  111. onShow() {
  112. },
  113. methods: {
  114. jumpUrl(url){
  115. uni.navigateTo({
  116. url:url
  117. })
  118. },
  119. // 考试下拉框
  120. changeTestPro(e){
  121. console.log("e:", e);
  122. },
  123. // 获取考试项目
  124. getTestProject(){
  125. console.log('11')
  126. req.getRequest('/api/v3/exam/user/manager',{},res=>{
  127. console.log('this.range',res)
  128. this.range = res.map(item=>{return {text:item.title,value:item.id}})
  129. console.log(this.range)
  130. })
  131. },
  132. // 考试公告
  133. getTextOtherInfo(){
  134. let form={
  135. code:req.public.ksggCode,
  136. page:1,
  137. limit:3
  138. }
  139. req.getRequest('/api/content/list',form,res=>{
  140. this.otherInfo = res
  141. })
  142. },
  143. // 注意事项
  144. getTextNoteInfo(){
  145. let form={
  146. code:req.public.zysxCode,
  147. page:1,
  148. limit:3
  149. }
  150. req.getRequest('/api/content/list',form,res=>{
  151. this.noteInfo = res
  152. })
  153. },
  154. open() {
  155. this.$refs.popup.open('center')
  156. },
  157. close() {
  158. this.$refs.popup.close()
  159. clearInterval(this.timeInterval)
  160. this.isPhotoing = false
  161. this.imageUrl = ''
  162. },
  163. okLogin() {
  164. if (!this.testNumber) {
  165. return req.msg('请输入准考证号');
  166. }
  167. if (!this.paperId) {
  168. return req.msg('请选择考试项目');
  169. }
  170. var formP = {
  171. admission: this.testNumber,
  172. paperId: this.paperId
  173. };
  174. req.postRequest('/api/admission/login', formP, data => {
  175. if(data){
  176. req.setStorage('userInfo', data);
  177. // 如果进行身份验证
  178. // this.open()
  179. // 直接考试,是否允许考试
  180. uni.navigateTo({
  181. url: '/pages/test/test?paperId='+this.paperId,
  182. success:()=> {
  183. this.close()
  184. }
  185. });
  186. }
  187. });
  188. },
  189. queryScore(){
  190. if (!this.testNumber) {
  191. return req.msg('请输入准考证号');
  192. }
  193. if (!this.paperId) {
  194. return req.msg('请选择考试项目');
  195. }
  196. var formP = {
  197. admission: this.testNumber,
  198. paperId: this.paperId
  199. };
  200. req.getRequest('/api/v3/exam/user/manager/result', formP, res => {
  201. uni.navigateTo({
  202. url:'/pages/scoreQuery/scoreQuery?paperId='+ this.paperId+'&admissionNo='+this.testNumber
  203. })
  204. });
  205. },
  206. // 验证提交
  207. yanzhengSubmit(){
  208. uni.navigateTo({
  209. url: '/pages/test/test?paperId='+this.paperId,
  210. success:()=> {
  211. this.close()
  212. }
  213. });
  214. },
  215. // 时间格式化
  216. dateFormat(date){
  217. return req.dateFormat(date).v5
  218. },
  219. getUserInfo() {
  220. req.getRequest(
  221. '/api/v3/hy/account/userInfo',
  222. {},
  223. data => {
  224. req.setStorage('userInfo', data);
  225. if(data.type==1||data.isStaff){
  226. uni.reLaunch({
  227. url: '/pages/learn/learn'
  228. });
  229. }else{
  230. uni.reLaunch({
  231. url: '/pages/index/index'
  232. });
  233. }
  234. },
  235. true
  236. );
  237. },
  238. // 身份验证
  239. yanzheng(){
  240. this.imageUrl = ''
  241. this.test()
  242. },
  243. takePhoto() {
  244. let _this = this
  245. //获得Canvas对象
  246. const query = uni.createSelectorQuery().in(this);
  247. let video = document.querySelector('video');
  248. let canvas = document.querySelector('canvas')
  249. let ctx = canvas.getContext('2d');
  250. let videoInfo = {}
  251. query.select('video').boundingClientRect(result => {
  252. console.log('videoInfo',result)
  253. videoInfo={
  254. width:result.width,
  255. height:result.height
  256. }
  257. }).exec();
  258. ctx.drawImage(video, 0, 0, videoInfo.width, videoInfo.height);
  259. // console.log(this.dataURLtoBlob(canvas.toDataURL(),'11'))
  260. // req.uploadFile('/api/upload', canvas.toDataURL(), res => {
  261. // req.msg('图片上传成功');
  262. // console.log('图片上传成功',res)
  263. // });
  264. _this.imageUrl = canvas.toDataURL()
  265. _this.isPhotoing = false
  266. // setTimeout(() => {
  267. // uni.canvasToTempFilePath({
  268. // canvasId: 'canvas',
  269. // destWidth: 60,
  270. // destHeight: 40,
  271. // success: function (res) {
  272. // console.log(res.tempFilePath) //图片路径
  273. // // resolve(res.tempFilePath)
  274. // _this.imgUrl = res.tempFilePath
  275. // },
  276. // fail: function (res) {
  277. // console.log(res.errMsg)
  278. // }
  279. // })
  280. // }, 100)
  281. },
  282. dataURLtoBlob(dataurl) {
  283. var arr = dataurl.split(','),
  284. mime = arr[0].match(/:(.*?);/)[1],
  285. bstr = atob(arr[1]),
  286. n = bstr.length,
  287. u8arr = new Uint8Array(n);//8位无符号整数,长度1个字节
  288. console.log(mime)
  289. while (n--) {
  290. u8arr[n] = bstr.charCodeAt(n);
  291. }
  292. // console.log(JSON.stringify(u8arr));
  293. return new Blob([u8arr], {
  294. type: mime
  295. });
  296. },
  297. base64toFile (dataurl, filename){
  298. var arr = dataurl.split(','),
  299. mime = arr[0].match(/:(.*?);/)[1],
  300. bstr = atob(arr[1]),
  301. n = bstr.length,
  302. u8arr = new Uint8Array(n);
  303. while (n--) {
  304. u8arr[n] = bstr.charCodeAt(n);
  305. }
  306. return new File([u8arr], filename, {
  307. type: mime
  308. });
  309. },
  310. test(){
  311. // var video = document.querySelector('video');
  312. const query = uni.createSelectorQuery().in(this);
  313. var video = query.select('#video')
  314. console.log('video',video)
  315. // 兼容代码
  316. window.URL = (window.URL || window.webkitURL || window.mozURL || window.msURL);
  317. // 获取媒体属性,旧版本浏览器可能不支持mediaDevices,我们首先设置一个空对象
  318. if (navigator.mediaDevices === undefined) {
  319. navigator.mediaDevices = {};
  320. }
  321. console.log('navigator.mediaDevices',navigator.mediaDevices)
  322. // 一些浏览器实现了部分mediaDevices,我们不能只分配一个对象
  323. // 使用getUserMedia,因为它会覆盖现有的属性。
  324. // 这里,如果缺少getUserMedia属性,就添加它。
  325. if (navigator.mediaDevices.getUserMedia === undefined) {
  326. navigator.mediaDevices.getUserMedia = function(constraints) {
  327. // 首先获取现存的getUserMedia(如果存在)
  328. var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
  329. // 有些浏览器不支持,会返回错误信息
  330. // 保持接口一致
  331. if (!getUserMedia) { //不存在则报错
  332. return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
  333. }
  334. // 否则,使用Promise将调用包装到旧的navigator.getUserMedia
  335. return new Promise(function(resolve, reject) {
  336. getUserMedia.call(navigator, constraints, resolve, reject);
  337. });
  338. }
  339. }
  340. //摄像头调用配置
  341. var mediaOpts = {
  342. audio: false,
  343. video: { facingMode: "user"}
  344. }
  345. let that=this;
  346. navigator.mediaDevices.getUserMedia(mediaOpts).then(function(stream) {
  347. that.mediaStreamTrack = stream;
  348. video = document.querySelector('video');
  349. console.log('video = document.querySelector(video);',video)
  350. // 旧的浏览器可能没有srcObject
  351. if ("srcObject" in video) {
  352. video.srcObject = stream
  353. } else {
  354. // 避免在新的浏览器中使用它,因为它正在被弃用。
  355. video.src = window.URL && window.URL.createObjectURL(stream) || stream
  356. }
  357. video.play();
  358. that.isPhotoing = true
  359. that.timeText = 3
  360. that.timeInterval = setInterval(()=>{
  361. if(that.timeText>0){
  362. that.timeText--
  363. }else{
  364. clearInterval(that.timeInterval)
  365. that.timeInterval= null
  366. that.takePhoto()
  367. }
  368. },1000)
  369. }).catch(function (err) {
  370. console.log(err)
  371. uni.showModal({
  372. title:'提示',
  373. content:'未找到摄像头',
  374. showCancel:false,
  375. success() {
  376. // uni.navigateBack({
  377. // })
  378. }
  379. })
  380. });
  381. },
  382. }
  383. };
  384. </script>
  385. <style>
  386. @import url('../login/login.css');
  387. </style>