facephoto.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const api = require('../../../utils/api.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. ditu:'/images/photo.png',
  8. fengmian:'/images/photo.png'
  9. },
  10. ditu:function(res){
  11. let that=this
  12. wx.chooseImage({
  13. count: 1,
  14. sizeType: ['original', 'compressed'],
  15. sourceType: ['album', 'camera'],
  16. success(res) {
  17. // tempFilePath可以作为img标签的src属性显示图片
  18. that.data.dtFilePaths = res.tempFilePaths
  19. that.setData({
  20. ditufile: that.data.dtFilePaths
  21. })
  22. }
  23. })
  24. },
  25. fengmian:function(){
  26. let that = this
  27. wx.chooseImage({
  28. count: 1,
  29. sizeType: ['original', 'compressed'],
  30. sourceType: ['album', 'camera'],
  31. success(res) {
  32. // tempFilePath可以作为img标签的src属性显示图片
  33. that.data.fmFilePaths = res.tempFilePaths
  34. that.setData({
  35. fengmianfile: that.data.fmFilePaths
  36. })
  37. }
  38. })
  39. },
  40. submit:function(){
  41. let that=this
  42. if(that.data.dtFilePaths){
  43. that.upload(that.data.dtFilePaths,'false')
  44. }
  45. if(that.data.fmFilePaths){
  46. that.upload(that.data.fmFilePaths,true)
  47. }
  48. },
  49. upload: function (file, isShowPhoto){
  50. let that=this
  51. wx.showLoading({
  52. title: '正在上传',
  53. })
  54. wx.uploadFile({
  55. url: 'http://dgt.dgtis.com/oneportal/userinfo/updateUserHeadImage.if',
  56. filePath: file[0],
  57. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  58. name: 'file',
  59. formData: {
  60. 'fileType': 'image',
  61. 'loginId': wx.getStorageSync('loginId'),
  62. 'isShowPhoto': isShowPhoto
  63. },
  64. success(res) {
  65. wx.hideLoading()
  66. if (JSON.parse(res.data).youtuMessage.error_code==0){
  67. wx.redirectTo({
  68. url: '/pages/success/index',
  69. })
  70. }
  71. }
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function (options) {
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })