login.vue 12 KB

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