login.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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/loginBg2.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" @blur="getTestProject" 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. let data = {
  127. }
  128. if(this.testNumber) data.idNumber = this.testNumber
  129. else delete data.idNumber
  130. req.getRequest('/api/v3/exam/user/manager',data,res=>{
  131. console.log('this.range',res)
  132. this.range = res.map(item=>{return {text:item.title,value:item.id}})
  133. console.log(this.range)
  134. })
  135. },
  136. // 考试公告
  137. getTextOtherInfo(){
  138. let form={
  139. code:req.public.ksggCode,
  140. page:1,
  141. limit:3
  142. }
  143. req.getRequest('/api/content/list',form,res=>{
  144. this.otherInfo = res
  145. })
  146. },
  147. // 注意事项
  148. getTextNoteInfo(){
  149. let form={
  150. code:req.public.zysxCode,
  151. page:1,
  152. limit:3
  153. }
  154. req.getRequest('/api/content/list',form,res=>{
  155. this.noteInfo = res
  156. })
  157. },
  158. open() {
  159. this.$refs.popup.open('center')
  160. },
  161. close() {
  162. this.$refs.popup.close()
  163. clearInterval(this.timeInterval)
  164. this.isPhotoing = false
  165. this.imageUrl = ''
  166. },
  167. okLogin() {
  168. if (!this.testNumber) {
  169. return req.msg('请输入准考证号');
  170. }
  171. if (!this.paperId) {
  172. return req.msg('请选择考试项目');
  173. }
  174. var formP = {
  175. admission: this.testNumber,
  176. paperId: this.paperId
  177. };
  178. req.postRequest('/api/admission/login', formP, data => {
  179. if(data){
  180. req.setStorage('userInfo', data);
  181. // 如果进行身份验证
  182. // this.open()
  183. // 直接考试,是否允许考试
  184. uni.navigateTo({
  185. // url: '/pages/test/test?paperId='+this.paperId,
  186. url: '/pages/selectTest/selectTest?paperId='+this.paperId,
  187. success:()=> {
  188. this.close()
  189. }
  190. });
  191. }
  192. });
  193. },
  194. queryScore(){
  195. if (!this.testNumber) {
  196. return req.msg('请输入准考证号');
  197. }
  198. if (!this.paperId) {
  199. return req.msg('请选择考试项目');
  200. }
  201. var formP = {
  202. admission: this.testNumber,
  203. paperId: this.paperId
  204. };
  205. req.getRequest('/api/v3/exam/user/manager/result', formP, res => {
  206. uni.navigateTo({
  207. url:'/pages/scoreQuery/scoreQuery?paperId='+ this.paperId+'&admissionNo='+this.testNumber
  208. })
  209. });
  210. },
  211. // 验证提交
  212. yanzhengSubmit(){
  213. uni.navigateTo({
  214. url: '/pages/test/test?paperId='+this.paperId,
  215. success:()=> {
  216. this.close()
  217. }
  218. });
  219. },
  220. // 时间格式化
  221. dateFormat(date){
  222. return req.dateFormat(date).v5
  223. },
  224. getUserInfo() {
  225. req.getRequest(
  226. '/api/v3/hy/account/userInfo',
  227. {},
  228. data => {
  229. req.setStorage('userInfo', data);
  230. if(data.type==1||data.isStaff){
  231. uni.reLaunch({
  232. url: '/pages/learn/learn'
  233. });
  234. }else{
  235. uni.reLaunch({
  236. url: '/pages/index/index'
  237. });
  238. }
  239. },
  240. true
  241. );
  242. },
  243. // 身份验证
  244. yanzheng(){
  245. this.imageUrl = ''
  246. this.test()
  247. },
  248. takePhoto() {
  249. let _this = this
  250. //获得Canvas对象
  251. const query = uni.createSelectorQuery().in(this);
  252. let video = document.querySelector('video');
  253. let canvas = document.querySelector('canvas')
  254. let ctx = canvas.getContext('2d');
  255. let videoInfo = {}
  256. query.select('video').boundingClientRect(result => {
  257. console.log('videoInfo',result)
  258. videoInfo={
  259. width:result.width,
  260. height:result.height
  261. }
  262. }).exec();
  263. ctx.drawImage(video, 0, 0, videoInfo.width, videoInfo.height);
  264. // console.log(this.dataURLtoBlob(canvas.toDataURL(),'11'))
  265. // req.uploadFile('/api/upload', canvas.toDataURL(), res => {
  266. // req.msg('图片上传成功');
  267. // console.log('图片上传成功',res)
  268. // });
  269. _this.imageUrl = canvas.toDataURL()
  270. _this.isPhotoing = false
  271. // setTimeout(() => {
  272. // uni.canvasToTempFilePath({
  273. // canvasId: 'canvas',
  274. // destWidth: 60,
  275. // destHeight: 40,
  276. // success: function (res) {
  277. // console.log(res.tempFilePath) //图片路径
  278. // // resolve(res.tempFilePath)
  279. // _this.imgUrl = res.tempFilePath
  280. // },
  281. // fail: function (res) {
  282. // console.log(res.errMsg)
  283. // }
  284. // })
  285. // }, 100)
  286. },
  287. dataURLtoBlob(dataurl) {
  288. var arr = dataurl.split(','),
  289. mime = arr[0].match(/:(.*?);/)[1],
  290. bstr = atob(arr[1]),
  291. n = bstr.length,
  292. u8arr = new Uint8Array(n);//8位无符号整数,长度1个字节
  293. console.log(mime)
  294. while (n--) {
  295. u8arr[n] = bstr.charCodeAt(n);
  296. }
  297. // console.log(JSON.stringify(u8arr));
  298. return new Blob([u8arr], {
  299. type: mime
  300. });
  301. },
  302. base64toFile (dataurl, filename){
  303. var arr = dataurl.split(','),
  304. mime = arr[0].match(/:(.*?);/)[1],
  305. bstr = atob(arr[1]),
  306. n = bstr.length,
  307. u8arr = new Uint8Array(n);
  308. while (n--) {
  309. u8arr[n] = bstr.charCodeAt(n);
  310. }
  311. return new File([u8arr], filename, {
  312. type: mime
  313. });
  314. },
  315. test(){
  316. // var video = document.querySelector('video');
  317. const query = uni.createSelectorQuery().in(this);
  318. var video = query.select('#video')
  319. console.log('video',video)
  320. // 兼容代码
  321. window.URL = (window.URL || window.webkitURL || window.mozURL || window.msURL);
  322. // 获取媒体属性,旧版本浏览器可能不支持mediaDevices,我们首先设置一个空对象
  323. if (navigator.mediaDevices === undefined) {
  324. navigator.mediaDevices = {};
  325. }
  326. console.log('navigator.mediaDevices',navigator.mediaDevices)
  327. // 一些浏览器实现了部分mediaDevices,我们不能只分配一个对象
  328. // 使用getUserMedia,因为它会覆盖现有的属性。
  329. // 这里,如果缺少getUserMedia属性,就添加它。
  330. if (navigator.mediaDevices.getUserMedia === undefined) {
  331. navigator.mediaDevices.getUserMedia = function(constraints) {
  332. // 首先获取现存的getUserMedia(如果存在)
  333. var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
  334. // 有些浏览器不支持,会返回错误信息
  335. // 保持接口一致
  336. if (!getUserMedia) { //不存在则报错
  337. return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
  338. }
  339. // 否则,使用Promise将调用包装到旧的navigator.getUserMedia
  340. return new Promise(function(resolve, reject) {
  341. getUserMedia.call(navigator, constraints, resolve, reject);
  342. });
  343. }
  344. }
  345. //摄像头调用配置
  346. var mediaOpts = {
  347. audio: false,
  348. video: { facingMode: "user"}
  349. }
  350. let that=this;
  351. navigator.mediaDevices.getUserMedia(mediaOpts).then(function(stream) {
  352. that.mediaStreamTrack = stream;
  353. video = document.querySelector('video');
  354. console.log('video = document.querySelector(video);',video)
  355. // 旧的浏览器可能没有srcObject
  356. if ("srcObject" in video) {
  357. video.srcObject = stream
  358. } else {
  359. // 避免在新的浏览器中使用它,因为它正在被弃用。
  360. video.src = window.URL && window.URL.createObjectURL(stream) || stream
  361. }
  362. video.play();
  363. that.isPhotoing = true
  364. that.timeText = 3
  365. that.timeInterval = setInterval(()=>{
  366. if(that.timeText>0){
  367. that.timeText--
  368. }else{
  369. clearInterval(that.timeInterval)
  370. that.timeInterval= null
  371. that.takePhoto()
  372. }
  373. },1000)
  374. }).catch(function (err) {
  375. console.log(err)
  376. uni.showModal({
  377. title:'提示',
  378. content:'未找到摄像头',
  379. showCancel:false,
  380. success() {
  381. // uni.navigateBack({
  382. // })
  383. }
  384. })
  385. });
  386. },
  387. }
  388. };
  389. </script>
  390. <style>
  391. @import url('../login/login.css');
  392. </style>