|
- const app = getApp()
- import request from '../../utils/request'
- import Dialog from '@vant/weapp/dialog/dialog';
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- topTitle: "请添加一张正面照片",
- showScanLine: false,
- isUploaded: false,
- isSuccess: false,
- tempFilePath: "",
- onlineFilePath: "",
- id: ""
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (options.id) {
- this.setData({
- id: options.id
- })
- }
- },
-
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- app.tokenCallBack = res => {
- this.setData({
- isLogin: res
- })
- }
-
- },
-
- chooseImage(e) {
- const that = this
- wx.chooseMedia({
- mediaType: ['image'],
- sourceType: ['camera'],
- camera: 'back',
- success: res => {
- that.setData({
- tempFilePath: res.tempFiles[0].tempFilePath,
- showScanLine: true,
- isUploaded: true,
- isSuccess: false
- })
- that.imgCheckByFace()
- }
- })
- },
-
- // 检查图片是否符合人脸规范
- imgCheckByFace() {
- const that = this
- const filePath = that.data.tempFilePath
- const BaseUrl = request.baseUrl
-
- wx.uploadFile({
- filePath,
- url: BaseUrl + "/api/userDigital/checkPhoto",
- name: 'file',
- formData: {
- user: "test",
- },
- success: res => {
- const code = JSON.parse(res.data).code
- if (code == 200) {
- that.imgCheckByBaidu()
- } else {
- that.setData({
- showScanLine: false
- })
- wx.showToast({
- title: '图片不合规范,请重新上传',
- icon: "none"
- })
- }
- },
- fail: err => {
- wx.showToast({
- title: '上传失败,请稍后再试',
- icon: "none"
- })
- }
- })
- },
-
- // 检查图片合法性
- imgCheckByBaidu() {
- const that = this
- const filePath = that.data.tempFilePath
- const BaseUrl = request.baseUrl
-
- wx.uploadFile({
- filePath,
- url: BaseUrl + "/api/baidu/checkPhoto",
- name: 'file',
- formData: {
- user: "test",
- },
- success: res => {
- const code = JSON.parse(res.data).code
- if (code == 200) {
- that.doUploadImg()
- } else {
- that.setData({
- showScanLine: false
- })
- wx.showToast({
- title: '图片不合规范,请重新上传',
- icon: "none"
- })
- }
- },
- fail: err => {
- wx.showToast({
- title: '上传失败,请稍后再试',
- icon: "none"
- })
- }
- })
- },
-
- // 上传图片
- doUploadImg() {
- const that = this
- const filePath = that.data.tempFilePath
- const BaseUrl = request.baseUrl
-
- wx.uploadFile({
- filePath,
- url: BaseUrl + "/api/upload/awsImgUpload",
- name: 'file',
- formData: {
- user: "test",
- },
- header: {
- "Content-Type": "multipart/form-data"
- },
- success: res => {
- console.log(res, 'res');
- const code = JSON.parse(res.data).code
- if (code == 200) {
- that.setData({
- showScanLine: false,
- isSuccess: true
- })
- wx.showToast({
- title: '上传成功!',
- icon: "success"
- })
- } else {
- wx.showToast({
- title: '服务器繁忙,请稍后再试',
- icon: "none"
- })
- that.setData({
- showScanLine: false
- })
- }
- },
- fail: err => {
- wx.showToast({
- title: '上传失败,请稍后再试',
- icon: "none"
- })
- }
- })
- },
-
- // 确认照片
- confirmImage() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|