facephoto.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.uploadFile({
  52. url: 'http://dgt.dgtis.com/oneportal/userinfo/updateUserHeadImage.if',
  53. filePath: file[0],
  54. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  55. name: 'file',
  56. formData: {
  57. 'fileType': 'image',
  58. 'loginId': wx.getStorageSync('loginId'),
  59. 'isShowPhoto': isShowPhoto
  60. },
  61. success(res) {
  62. if (JSON.parse(res.data).youtuMessage.error_code==0){
  63. wx.showToast({
  64. title: '上传成功',
  65. icon:'none'
  66. })
  67. }
  68. }
  69. })
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面显示
  83. */
  84. onShow: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面隐藏
  88. */
  89. onHide: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面卸载
  93. */
  94. onUnload: function () {
  95. },
  96. /**
  97. * 页面相关事件处理函数--监听用户下拉动作
  98. */
  99. onPullDownRefresh: function () {
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. onReachBottom: function () {
  105. },
  106. /**
  107. * 用户点击右上角分享
  108. */
  109. onShareAppMessage: function () {
  110. }
  111. })