|
@@ -1,10 +1,15 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <view>
|
|
|
|
|
|
|
+ <view style="position: relative;">
|
|
|
<Headers></Headers>
|
|
<Headers></Headers>
|
|
|
<view class="project">
|
|
<view class="project">
|
|
|
- <view style="width: 1200px;margin: auto;">二手车评估师考试</view>
|
|
|
|
|
|
|
+ <view style="width: 1200px;margin: auto;">{{paper.title}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
|
|
+ <view class="video-box" id="video-box" @click="takePhoto">
|
|
|
|
|
+ <video id="video" style="width: 100%;height: 100%;" :autoplay="true" :controls="true" :show-center-play-btn="false"></video>
|
|
|
|
|
+ <canvas id="canvas" style="width: 100%;height: 100%;" canvas-id="canvas"></canvas>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <img :src="imgUrl" ></img>
|
|
|
<view class="project-content ddflex">
|
|
<view class="project-content ddflex">
|
|
|
<!-- 考试区域 -->
|
|
<!-- 考试区域 -->
|
|
|
<view class="test-box">
|
|
<view class="test-box">
|
|
@@ -54,19 +59,19 @@
|
|
|
<!-- 答题卡区域 -->
|
|
<!-- 答题卡区域 -->
|
|
|
<view class="test-info ddflex">
|
|
<view class="test-info ddflex">
|
|
|
<view class="test-people ddflex">
|
|
<view class="test-people ddflex">
|
|
|
- <image></image>
|
|
|
|
|
|
|
+ <image :src="userInfo.avatar"></image>
|
|
|
<view class="test-people-info ddflex">
|
|
<view class="test-people-info ddflex">
|
|
|
<view class="ddflex">
|
|
<view class="ddflex">
|
|
|
<view class="test-people-label">考生姓名</view>
|
|
<view class="test-people-label">考生姓名</view>
|
|
|
- <view class="fflex">李田</view>
|
|
|
|
|
|
|
+ <view class="fflex">{{userInfo.userName}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="ddflex">
|
|
<view class="ddflex">
|
|
|
<view class="test-people-label">准考证号</view>
|
|
<view class="test-people-label">准考证号</view>
|
|
|
- <view class="fflex" style="word-break: break-all;">4512541244</view>
|
|
|
|
|
|
|
+ <view class="fflex" style="word-break: break-all;">{{userInfo.admissionNo}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="ddflex">
|
|
<view class="ddflex">
|
|
|
<view class="test-people-label">考试科目</view>
|
|
<view class="test-people-label">考试科目</view>
|
|
|
- <view class="fflex">二手车评估师</view>
|
|
|
|
|
|
|
+ <view class="fflex">{{userInfo.cateName}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -114,12 +119,12 @@
|
|
|
<view class="popup-box" v-if="state==1">
|
|
<view class="popup-box" v-if="state==1">
|
|
|
<view class="popup-top ddflex">
|
|
<view class="popup-top ddflex">
|
|
|
<view>您正在结束作答</view>
|
|
<view>您正在结束作答</view>
|
|
|
- <image src="/static/images/close.png" @click="close()"></image>
|
|
|
|
|
|
|
+ <image src="/static/images/close.png" v-if="time > 0" @click="close()"></image>
|
|
|
</view>
|
|
</view>
|
|
|
<!-- {{(quests.filter(item=>{return item.isSubmit}).length<quests.length)?'您还有未完成的考题,是否确定交卷?':'您已完成全部考题,是否确定交卷?'}} -->
|
|
<!-- {{(quests.filter(item=>{return item.isSubmit}).length<quests.length)?'您还有未完成的考题,是否确定交卷?':'您已完成全部考题,是否确定交卷?'}} -->
|
|
|
<view class="popup-content">{{(quests.filter(item=>{return item.isSubmit}).length < quests.length ? '您还有未完成的考题,是否确定交卷?':'您已完成全部考题,是否确定交卷?')}}</view>
|
|
<view class="popup-content">{{(quests.filter(item=>{return item.isSubmit}).length < quests.length ? '您还有未完成的考题,是否确定交卷?':'您已完成全部考题,是否确定交卷?')}}</view>
|
|
|
<view class="popup-bottom ddflex">
|
|
<view class="popup-bottom ddflex">
|
|
|
- <view class="popup-btn1" @click="close()">继续考试</view>
|
|
|
|
|
|
|
+ <view class="popup-btn1" @click="close()" v-if="time > 0">继续考试</view>
|
|
|
<view class="popup-btn2" @click="submit">确定交卷</view>
|
|
<view class="popup-btn2" @click="submit">确定交卷</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -129,21 +134,23 @@
|
|
|
<image src="/static/images/close.png" @click="close()"></image>
|
|
<image src="/static/images/close.png" @click="close()"></image>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="popup-content" style="margin-top: 23px;">
|
|
<view class="popup-content" style="margin-top: 23px;">
|
|
|
- <view class="chufen-title">二手车评估师考试</view>
|
|
|
|
|
- <view class="chufen-number">
|
|
|
|
|
- 84<text style="font-size: 18px;margin-left: 10px;">分</text>
|
|
|
|
|
- <view style="font-size: 16px;">考试不合格</view>
|
|
|
|
|
|
|
+ <view class="chufen-title">{{result.title}}</view>
|
|
|
|
|
+ <view class="chufen-number" :style="result.score>=paper.passScore?'color:green;':''">
|
|
|
|
|
+ {{result.score}}<text style="font-size: 18px;margin-left: 10px;">分</text>
|
|
|
|
|
+ <view style="font-size: 16px;">{{result.score>=paper.passScore?'考试合格':'考试不合格'}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="popup-bottom ddflex" style="margin-top: 30px;margin-bottom: 60px;padding-left: 30px">
|
|
<view class="popup-bottom ddflex" style="margin-top: 30px;margin-bottom: 60px;padding-left: 30px">
|
|
|
<view>
|
|
<view>
|
|
|
<view class="popup-bottom-label">总题数</view>
|
|
<view class="popup-bottom-label">总题数</view>
|
|
|
- <view class="popup-bottom-value">23</view>
|
|
|
|
|
|
|
+ <view class="popup-bottom-value">{{result.questToal}}</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="line"></view>
|
|
<view class="line"></view>
|
|
|
<view>
|
|
<view>
|
|
|
<view class="popup-bottom-label">考试用时</view>
|
|
<view class="popup-bottom-label">考试用时</view>
|
|
|
- <view class="popup-bottom-value">20:42:14</view>
|
|
|
|
|
|
|
+ <view class="popup-bottom-value">
|
|
|
|
|
+ {{timeChangeHMS(result.duration)}}
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -157,11 +164,15 @@
|
|
|
const app = getApp();
|
|
const app = getApp();
|
|
|
const req = require('../../utils/request.js');
|
|
const req = require('../../utils/request.js');
|
|
|
const utils = require('../../utils/util.js');
|
|
const utils = require('../../utils/util.js');
|
|
|
|
|
+ const api = require('../../utils/api.js')
|
|
|
|
|
+ import html2canvas from "../../utils/html2canvas.min.js";
|
|
|
export default {
|
|
export default {
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
state:1,
|
|
state:1,
|
|
|
|
|
|
|
|
|
|
+ userInfo:{},
|
|
|
|
|
+
|
|
|
paperId: '', //考试题目
|
|
paperId: '', //考试题目
|
|
|
paperTitle: '', //考试标题
|
|
paperTitle: '', //考试标题
|
|
|
paperType: '', //1每日一练 2模拟试题 3大厂真题 5企业真题
|
|
paperType: '', //1每日一练 2模拟试题 3大厂真题 5企业真题
|
|
@@ -182,14 +193,51 @@
|
|
|
|
|
|
|
|
answerTxt: '', //填空题、简答题答案
|
|
answerTxt: '', //填空题、简答题答案
|
|
|
isGoBack: false,
|
|
isGoBack: false,
|
|
|
- isShowView: false
|
|
|
|
|
|
|
+ isShowView: false,
|
|
|
|
|
+
|
|
|
|
|
+ isClearLogin:true,//是否离开页面清除缓存
|
|
|
|
|
+
|
|
|
|
|
+ result:null,//考试结果
|
|
|
|
|
+
|
|
|
|
|
+ buffer:null,
|
|
|
|
|
+ video:{src:null},
|
|
|
|
|
+ canvas:null,
|
|
|
|
|
+ ctx:null,
|
|
|
|
|
+ imgUrl:null
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
onReady() {},
|
|
onReady() {},
|
|
|
- onLoad() {
|
|
|
|
|
- this.getQuests()
|
|
|
|
|
|
|
+ async onLoad(options) {
|
|
|
|
|
+ this.paperId = options.paperId;
|
|
|
|
|
+
|
|
|
|
|
+ console.log(this.userInfo)
|
|
|
|
|
+ // 需要先判断用户是否还能考试
|
|
|
|
|
+ await this.getQuests();
|
|
|
|
|
+
|
|
|
|
|
+ // 摄像头
|
|
|
|
|
+ const query = uni.createSelectorQuery().in(this);
|
|
|
|
|
+ this.video = query.select('#video')
|
|
|
|
|
+ this.canvas = query.select('#canvas');
|
|
|
|
|
+ this.test()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 考生信息
|
|
|
|
|
+ this.getUserInfo()
|
|
|
|
|
+ // 考试数据
|
|
|
|
|
+ this.getPaper();
|
|
|
|
|
+ // this.getQuests();
|
|
|
|
|
+ },
|
|
|
|
|
+ onUnload() {
|
|
|
|
|
+ if(this.isClearLogin)
|
|
|
|
|
+ uni.clearStorageSync();
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ // 考试信息
|
|
|
|
|
+ getUserInfo(){
|
|
|
|
|
+ req.getRequest('/api/v3/exam/user/manager/info',{},res=>{
|
|
|
|
|
+ this.userInfo = res
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
getQuestType() {
|
|
getQuestType() {
|
|
|
// <!-- 1单选 2多选 3 判断 4 填空 5 简答', -->
|
|
// <!-- 1单选 2多选 3 判断 4 填空 5 简答', -->
|
|
|
var text = '';
|
|
var text = '';
|
|
@@ -241,20 +289,23 @@
|
|
|
|
|
|
|
|
getQuests(){
|
|
getQuests(){
|
|
|
let _ts = this
|
|
let _ts = this
|
|
|
- req.getRequest('https://mock.apifox.cn/m1/2171629-0-default/api/paper/quest/init/2834',{},quests=>{
|
|
|
|
|
- console.log(quests)
|
|
|
|
|
- if (quests && quests.length > 0) {
|
|
|
|
|
- _ts.questTotal = quests.length;
|
|
|
|
|
- for (var k = 0; k < quests.length; k++) {
|
|
|
|
|
- var quest = quests[k];
|
|
|
|
|
- quest.eitype = _ts.etype;
|
|
|
|
|
- quest.title = quest.title.replace(/<code class="(.*?)"/gi, '<code class="Java" ');
|
|
|
|
|
- }
|
|
|
|
|
- if (_ts.questTotal > 0) {
|
|
|
|
|
- _ts.quest = _ts.setQuest(quests[0]);
|
|
|
|
|
|
|
+ return new Promise((r,j)=>{
|
|
|
|
|
+ req.getRequest(api.get_exam_question + _ts.paperId,{},quests=>{
|
|
|
|
|
+ console.log(quests)
|
|
|
|
|
+ if (quests && quests.length > 0) {
|
|
|
|
|
+ _ts.questTotal = quests.length;
|
|
|
|
|
+ for (var k = 0; k < quests.length; k++) {
|
|
|
|
|
+ var quest = quests[k];
|
|
|
|
|
+ quest.eitype = _ts.etype;
|
|
|
|
|
+ quest.title = quest.title.replace(/<code class="(.*?)"/gi, '<code class="Java" ');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (_ts.questTotal > 0) {
|
|
|
|
|
+ _ts.quest = _ts.setQuest(quests[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ _ts.quests = quests;
|
|
|
|
|
+ r()
|
|
|
}
|
|
}
|
|
|
- _ts.quests = quests;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -267,7 +318,8 @@
|
|
|
if (_ts.ptime) {
|
|
if (_ts.ptime) {
|
|
|
clearTimeout(_ts.ptime);
|
|
clearTimeout(_ts.ptime);
|
|
|
}
|
|
}
|
|
|
- _ts.submitTest();
|
|
|
|
|
|
|
+ _ts.open()
|
|
|
|
|
+ // _ts.submitTest();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
var times = {};
|
|
var times = {};
|
|
@@ -282,7 +334,17 @@
|
|
|
_ts.setTime();
|
|
_ts.setTime();
|
|
|
}, 1000);
|
|
}, 1000);
|
|
|
}, //下次继续
|
|
}, //下次继续
|
|
|
-
|
|
|
|
|
|
|
+ // 秒转换时分秒
|
|
|
|
|
+ timeChangeHMS(time){
|
|
|
|
|
+ let _ts = this
|
|
|
|
|
+ var times = {};
|
|
|
|
|
+ times.hour = _ts.cut22(Math.floor(time / 3600));
|
|
|
|
|
+ var leave2 = time % 3600;
|
|
|
|
|
+ times.minutes = _ts.cut22(Math.floor(leave2 / 60));
|
|
|
|
|
+ var leave3 = leave2 % 60;
|
|
|
|
|
+ times.seconds = _ts.cut22(Math.round(leave3));
|
|
|
|
|
+ return times.hour+":"+times.minutes+":"+times.seconds
|
|
|
|
|
+ },
|
|
|
cut22(n) {
|
|
cut22(n) {
|
|
|
n = n.toString();
|
|
n = n.toString();
|
|
|
return n[1] ? n : '0' + n;
|
|
return n[1] ? n : '0' + n;
|
|
@@ -416,10 +478,9 @@
|
|
|
|
|
|
|
|
toQuestTip(index) {
|
|
toQuestTip(index) {
|
|
|
var _ts = this;
|
|
var _ts = this;
|
|
|
- var _ts = this;
|
|
|
|
|
_ts.cIndex = index;
|
|
_ts.cIndex = index;
|
|
|
_ts.quest = _ts.setQuest(_ts.quests[_ts.cIndex]);
|
|
_ts.quest = _ts.setQuest(_ts.quests[_ts.cIndex]);
|
|
|
- _ts.closeCeng();
|
|
|
|
|
|
|
+ // _ts.closeCeng();
|
|
|
// });
|
|
// });
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -460,17 +521,13 @@
|
|
|
|
|
|
|
|
//提交考试+答案
|
|
//提交考试+答案
|
|
|
submit() {
|
|
submit() {
|
|
|
- uni.redirectTo({
|
|
|
|
|
- url:'/pages/scoreQuery/scoreQuery'
|
|
|
|
|
- })
|
|
|
|
|
- return
|
|
|
|
|
var _ts = this;
|
|
var _ts = this;
|
|
|
if (_ts.ptime) {
|
|
if (_ts.ptime) {
|
|
|
clearTimeout(_ts.ptime);
|
|
clearTimeout(_ts.ptime);
|
|
|
}
|
|
}
|
|
|
var dataP = {
|
|
var dataP = {
|
|
|
uniqueId: _ts.paperId,
|
|
uniqueId: _ts.paperId,
|
|
|
- uniqueType: _ts.type
|
|
|
|
|
|
|
+ uniqueType: 1
|
|
|
};
|
|
};
|
|
|
//组装考试题目
|
|
//组装考试题目
|
|
|
dataP.questionList = this.quests.map(it => {
|
|
dataP.questionList = this.quests.map(it => {
|
|
@@ -501,13 +558,17 @@
|
|
|
dataP,
|
|
dataP,
|
|
|
res => {
|
|
res => {
|
|
|
if (!_ts.paper.isScore) {//手动阅卷
|
|
if (!_ts.paper.isScore) {//手动阅卷
|
|
|
|
|
+ _ts.isClearLogin = false
|
|
|
uni.redirectTo({
|
|
uni.redirectTo({
|
|
|
- url: '/learn/marking/index?id=' + res.id
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ url:'/pages/scoreQuery/scoreQuery?paperId='+ _ts.paperId+'&admissionNo='+_ts.userInfo.admissionNo
|
|
|
|
|
+ })
|
|
|
|
|
+ return
|
|
|
} else {//自动阅卷
|
|
} else {//自动阅卷
|
|
|
- uni.redirectTo({
|
|
|
|
|
- url: '/learn/result/index?id=' + res.id
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // uni.redirectTo({
|
|
|
|
|
+ // url: '/learn/result/index?id=' + res.id
|
|
|
|
|
+ // });
|
|
|
|
|
+ this.state=2
|
|
|
|
|
+ this.result = res
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
true
|
|
true
|
|
@@ -520,7 +581,136 @@
|
|
|
close() {
|
|
close() {
|
|
|
this.$refs.popup.close()
|
|
this.$refs.popup.close()
|
|
|
},
|
|
},
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ takePhoto() {
|
|
|
|
|
+ let _this = this
|
|
|
|
|
+ //获得Canvas对象
|
|
|
|
|
+ const query = uni.createSelectorQuery().in(this);
|
|
|
|
|
+ let video = document.querySelector('video');
|
|
|
|
|
+ let canvas = document.querySelector('canvas')
|
|
|
|
|
+ let ctx = canvas.getContext('2d');
|
|
|
|
|
+ let videoInfo = {}
|
|
|
|
|
+ query.select('video').boundingClientRect(result => {
|
|
|
|
|
+ console.log('videoInfo',result)
|
|
|
|
|
+ videoInfo={
|
|
|
|
|
+ width:result.width,
|
|
|
|
|
+ height:result.height
|
|
|
|
|
+ }
|
|
|
|
|
+ }).exec();
|
|
|
|
|
+ ctx.drawImage(video, 0, 0, videoInfo.width, videoInfo.height);
|
|
|
|
|
+ console.log(this.dataURLtoBlob(canvas.toDataURL(),'11'))
|
|
|
|
|
+ // setTimeout(() => {
|
|
|
|
|
+ // uni.canvasToTempFilePath({
|
|
|
|
|
+ // canvasId: 'canvas',
|
|
|
|
|
+ // destWidth: 60,
|
|
|
|
|
+ // destHeight: 40,
|
|
|
|
|
+ // success: function (res) {
|
|
|
|
|
+ // console.log(res.tempFilePath) //图片路径
|
|
|
|
|
+ // // resolve(res.tempFilePath)
|
|
|
|
|
+ // _this.imgUrl = res.tempFilePath
|
|
|
|
|
+ // },
|
|
|
|
|
+ // fail: function (res) {
|
|
|
|
|
+ // console.log(res.errMsg)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // }, 100)
|
|
|
|
|
+ },
|
|
|
|
|
+ dataURLtoBlob(dataurl) {
|
|
|
|
|
+ var arr = dataurl.split(','),
|
|
|
|
|
+ mime = arr[0].match(/:(.*?);/)[1],
|
|
|
|
|
+ bstr = atob(arr[1]),
|
|
|
|
|
+ n = bstr.length,
|
|
|
|
|
+ u8arr = new Uint8Array(n);//8位无符号整数,长度1个字节
|
|
|
|
|
+ console.log(mime)
|
|
|
|
|
+ while (n--) {
|
|
|
|
|
+ u8arr[n] = bstr.charCodeAt(n);
|
|
|
|
|
+ }
|
|
|
|
|
+ // console.log(JSON.stringify(u8arr));
|
|
|
|
|
+ return new Blob([u8arr], {
|
|
|
|
|
+ type: mime
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ base64toFile (dataurl, filename){
|
|
|
|
|
+ var arr = dataurl.split(','),
|
|
|
|
|
+ mime = arr[0].match(/:(.*?);/)[1],
|
|
|
|
|
+ bstr = atob(arr[1]),
|
|
|
|
|
+ n = bstr.length,
|
|
|
|
|
+ u8arr = new Uint8Array(n);
|
|
|
|
|
+ while (n--) {
|
|
|
|
|
+ u8arr[n] = bstr.charCodeAt(n);
|
|
|
|
|
+ }
|
|
|
|
|
+ return new File([u8arr], filename, {
|
|
|
|
|
+ type: mime
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ test(){
|
|
|
|
|
+ // var video = document.querySelector('video');
|
|
|
|
|
+ const query = uni.createSelectorQuery().in(this);
|
|
|
|
|
+ var video = query.select('#video')
|
|
|
|
|
+ console.log('video',video)
|
|
|
|
|
+ // 兼容代码
|
|
|
|
|
+ window.URL = (window.URL || window.webkitURL || window.mozURL || window.msURL);
|
|
|
|
|
+ // 获取媒体属性,旧版本浏览器可能不支持mediaDevices,我们首先设置一个空对象
|
|
|
|
|
+ if (navigator.mediaDevices === undefined) {
|
|
|
|
|
+ navigator.mediaDevices = {};
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log('navigator.mediaDevices',navigator.mediaDevices)
|
|
|
|
|
+ // 一些浏览器实现了部分mediaDevices,我们不能只分配一个对象
|
|
|
|
|
+ // 使用getUserMedia,因为它会覆盖现有的属性。
|
|
|
|
|
+ // 这里,如果缺少getUserMedia属性,就添加它。
|
|
|
|
|
+ if (navigator.mediaDevices.getUserMedia === undefined) {
|
|
|
|
|
+ navigator.mediaDevices.getUserMedia = function(constraints) {
|
|
|
|
|
+ // 首先获取现存的getUserMedia(如果存在)
|
|
|
|
|
+ var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
|
|
|
|
|
+ // 有些浏览器不支持,会返回错误信息
|
|
|
|
|
+ // 保持接口一致
|
|
|
|
|
+ if (!getUserMedia) { //不存在则报错
|
|
|
|
|
+ return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 否则,使用Promise将调用包装到旧的navigator.getUserMedia
|
|
|
|
|
+ return new Promise(function(resolve, reject) {
|
|
|
|
|
+ getUserMedia.call(navigator, constraints, resolve, reject);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //摄像头调用配置
|
|
|
|
|
+ var mediaOpts = {
|
|
|
|
|
+ audio: false,
|
|
|
|
|
+ video: { facingMode: "user"}
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let that=this;
|
|
|
|
|
+ navigator.mediaDevices.getUserMedia(mediaOpts).then(function(stream) {
|
|
|
|
|
+ that.mediaStreamTrack = stream;
|
|
|
|
|
+ video = document.querySelector('video');
|
|
|
|
|
+ console.log('video = document.querySelector(video);',video)
|
|
|
|
|
+ // 旧的浏览器可能没有srcObject
|
|
|
|
|
+ if ("srcObject" in video) {
|
|
|
|
|
+ video.srcObject = stream
|
|
|
|
|
+ that.video.srcObject = stream
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 避免在新的浏览器中使用它,因为它正在被弃用。
|
|
|
|
|
+ video.src = window.URL && window.URL.createObjectURL(stream) || stream
|
|
|
|
|
+ that.video.src = window.URL && window.URL.createObjectURL(stream) || stream
|
|
|
|
|
+ }
|
|
|
|
|
+ video.play();
|
|
|
|
|
+ }).catch(function (err) {
|
|
|
|
|
+ console.log(err)
|
|
|
|
|
+ uni.showModal({
|
|
|
|
|
+ title:'提示',
|
|
|
|
|
+ content:'未找到摄像头',
|
|
|
|
|
+ showCancel:false,
|
|
|
|
|
+ success() {
|
|
|
|
|
+ // uni.navigateBack({
|
|
|
|
|
+
|
|
|
|
|
+ // })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
</script>
|