123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <template>
- <view class="main" id="main">
- <epii-camera ref="camera" class="epiiCamer" :style="{width:width,height:height}"></epii-camera>
- <cover-view>
- <image :style="{width:width,height:height}" src="../../static/sl.gif" mode="scaleToFill"></image>
- </cover-view>
- </view>
- </template>
- <script>
- import http from '../../common/http.js'
- export default {
- data() {
- return {
- cameraId: 0,
- height: "500rpx",
- width: "750rpx",
- userId: '',
- }
- },
- onLoad(options) {
- this.userId = options.id;
- this.height = uni.getSystemInfoSync().screenHeight * 2 + 'rpx';
- this.$nextTick(() => {
-
- this.openCamera(1)
- })
- },
- beforeDestroy() {
- this.release();
- },
- mounted() {
- console.log(this.$refs.camera)
-
- },
- methods: {
- takePicture(e) {
- const that = this;
- that.$refs.camera.takePicture({
- base64: false,
- quailty: 100,
- }, function(data) {
- let img = data.img;
- that.registerFace(img);
- return
- });
- },
- registerFace(img) {
- const that = this;
- uni.uploadFile({
- url: http.ip + '/sp-admin/app/AppUser/faceLogin',
- filePath: 'file://' + img,
- name: 'file',
- formData: {
- id: that.userId
- },
- header: {
- satoken: uni.getStorageSync('token')
- },
- success(resp) {
- let res = JSON.parse(resp.data);
- if (res.code == 200) {
- that.release();
- setTimeout(()=>{
- let data=res.data;
- uni.setStorageSync('token', data.tokenInfo.tokenValue);
- uni.setStorageSync('info', data.appUser);
- uni.setStorageSync('menu', data.per_list);
- uni.showToast({ title: '登录成功' });
- setTimeout(() => {
- uni.$emit('getMenu');
- uni.switchTab({ url: '/pages/index/index' });
- }, 1000);
- },500)
- } else {
- uni.showToast({
- icon:'none',
- title: res.msg
- })
- setTimeout(function() {
- that.takePicture();
- }, 1000);
- }
- }
- })
- },
- release() {
- this.$refs.camera.release();
- },
- openCamera(id) {
- if (uni.getSystemInfoSync().platform === "ios") {
- let that = this;
- this.$refs.camera.openCamera({
- cameraId: id,
- }, function(data) {
- setTimeout(function() {
- that.takePicture();
- }, 200);
- });
- } else {
-
- this.openCamera_1(id);
- }
- },
- openCamera_1(id) {
-
-
-
- this.cid = id;
- let type = 2;
- this.$refs.camera.getSupportedPreviewSizesByCameraId({
- cameraId: id
- }, (data) => {
- let bestHeight_index = 0;
-
- if (type == 1) {
- let r0 = (this.height * 1.0) / this.width;
- let diff = 1000;
- for (var i = 0; i < data.sizes.length; i++) {
- console.log(data.sizes[i]);
-
- let tmp = Math.abs(r0 - (data.sizes[i].width * 1.0) / data.sizes[bestHeight_index]
- .width);
- if (tmp < diff) {
- diff = tmp;
- bestHeight_index = i;
- }
- }
-
- } else if (type == 2) {
- for (var i = 0; i < data.sizes.length; i++) {
-
- if (data.sizes[i].width > data.sizes[bestHeight_index].width) {
- bestHeight_index = i;
- }
- }
-
-
- this.height = ((data.sizes[bestHeight_index].width / (data.sizes[bestHeight_index].height *
- 1.0)) * 750) + "rpx";
-
- } else if (type == 3) {
- bestHeight_index = 0;
- }
-
- const that = this;
- setTimeout(() => {
- this.$refs.camera.openCamera({
- cameraId: id,
- previewWidth: data.sizes[bestHeight_index].width,
- previewHeight: data.sizes[bestHeight_index].height
- }, function(data) {
- setTimeout(function() {
- that.takePicture();
- }, 800);
- });
- }, 500);
- });
- return;
- },
- switchCamera() {
- this.cameraId == 0 ? this.cameraId = 1 : this.cameraId = 0
- this.$refs.camera.switchCamera({
- cameraId: this.cameraId
- }, function(data) {
- uni.showModal({
- content: JSON.stringify(data)
- })
- });
- },
- start() {
- this.$refs.camera.startRecord({
- videoEncodingBitRate: 3 * 1920 * 1080
- });
- },
- stop() {
- this.$refs.camera.stopRecord(function(data) {
-
- uni.showModal({
- content: JSON.stringify(data)
- })
- });
- },
- release() {
- this.$refs.camera.release();
- },
- flashOpen() {
- this.$refs.camera.flashOpen();
- },
- flashClose() {
- this.$refs.camera.flashClose();
- },
- changeSize() {
- this.height = "1100rpx";
- },
- getSupportedPreviewSizes() {
- this.$refs.camera.getSupportedPreviewSizes((ret) => {
- uni.showModal({
- content: JSON.stringify(ret)
- })
- });
- }
- }
- }
- </script>
- <style scoped>
- .main {
- position: relative;
- width: 750rpx;
- flex: 1;
- overflow: hidden;
- }
- .operate-bg {
- width: 750rpx;
- background-color: #000000;
- position: absolute;
- left: 0;
- bottom: 0;
- justify-content: center;
- align-items: center;
- padding-top: 60rpx;
- padding-bottom: 60rpx;
- }
- .operate {
- width: 140rpx;
- height: 140rpx;
- background-color: #fff;
- border-radius: 50%;
- border-width: 10rpx;
- border-style: solid;
- border-color: #453f3f;
- }
- .change {
- width: 96rpx;
- height: 96rpx;
- background-color: #453f3f;
- position: absolute;
- right: 60rpx;
- bottom: 82rpx;
- border-radius: 48rpx;
- align-items: center;
- justify-content: center;
- }
- .change-img {
- width: 56rpx;
- height: 56rpx;
- }
- .portrait-frame {
- width: 750rpx;
- flex: 1;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- align-items: center;
- justify-content: center;
- background-color: rgba(0, 0, 0, 0);
- }
- .pf-img {
- width: 633.6rpx;
- height: 582rpx;
- margin-top: -280rpx;
- }
- .epiiCamer {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- }
- </style>
|