123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <template>
- <view class="">
- <view class="pic" @click="takePhoto">
- <u-icon v-if="!pic" class="icon" name="plus" color="#2979ff" size="50"></u-icon>
- <img v-else :src="pic" alt="">
- </view>
- <view class="upload" style="width: 100%;">
- <u-button color="red" @click="deleteFace" type="primary" size="large" text="删除人脸特征值"></u-button>
- </view>
- </view>
- </template>
- <script>
- // import UploadPhoto from "@/components/upload-photo/upload-photo.vue"
- import api from "@/utils/api.js"
- export default {
- // components: {
- // UploadPhoto
- // },
- data() {
- return {
- bgColor: '#3c9cff',
- pic: '',
- msg: {
- userId: uni.getStorageSync('userId'),
- facePic: ""
- },
- }
- },
- onLoad() {
- },
- methods: {
- takePhoto() {
- uni.chooseImage({
- count: 1, //选择图片的数量,默认9
- sizeType: ['compressed'], //原图、压缩图或者两者都有,可以指定原图或压缩图,默认两者都有
- sourceType: ['album', 'camera'], //从相册选择
- success: res => {
- const tempFilePaths = res.tempFilePaths; // 返回选定照片的本地文件路径列表
- console.log(tempFilePaths[0]);
- this.urlTobase64(tempFilePaths[0])
- }
- })
- },
- urlTobase64(url) {
- console.log('url', url);
- let that = this
- uni.getFileSystemManager().readFile({
- filePath: url, //照片的临时地址
- encoding: "base64", //编码格式
- success: async (res) => {
- let url = "data:image/jpg" + ";base64," + res.data //base64地址
- url = url.split(',')[1]
- that.msg.facePic = url
- const {
- data: result
- } = await uni.$http.post('/api/v1/test/user/face', that.msg)
- console.log(result);
- that.pic = 'data:image/jpeg;base64,' + url
- },
- fail: (res) => reject(res.errMsg),
- })
- },
- async textUpload() {
- // if (res.code === 200) {
- // } else {
- // this.$u.toast(`用户未上传人脸,请上传人脸`)
- // }
- },
- async deleteFace() {
- const {
- data: res
- } = await uni.$http.get(`/api/v1/test/user/${this.msg.userId}/hasUploadFace`)
- if (res.code === 200) {
- const {
- data: result
- } = await uni.$http.delete(`/api/v1/test/user/face/${this.msg.userId}`)
- if (result.code === 200) {
- uni.showToast({
- duration:1500,
- title:result.data,
- icon:'none'
- })
- this.pic = ''
- } else {
- uni.$showMsg('删除失败')
- }
- } else {
- uni.$showMsg('人脸未添加')
- }
- }
- }
- }
- </script>
- <style lang="scss">
- .camera {
- display: flex;
- justify-content: center;
- align-items: center;
- margin-top: 20px;
- }
- .pic {
- margin: 100px auto;
- border: 1px solid #3c9cff;
- width: 500rpx;
- height: 300px;
- display: flex;
- justify-content: center;
- align-items: center;
- .icon {}
- img {
- width: 100%;
- height: 100%;
- }
- }
- .upload {
- display: inline-block;
- position: fixed;
- bottom: 0;
- }
- </style>
|