index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // nova-tourism/components/template2/my/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const qiniuUploader = require("../../../../utils/qiniuUploader");
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. },
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. },
  16. lifetimes: {
  17. created() {},
  18. attached() {
  19. this.refresh()
  20. },
  21. },
  22. /**
  23. * 组件的方法列表
  24. */
  25. methods: {
  26. async refresh() {
  27. this.getUptoken();
  28. this.getmy()
  29. },
  30. async getmy() {
  31. let uid = Parse.User.current().id
  32. console.log(uid);
  33. let ShopOrder = new Parse.Query('_User')
  34. let shopOrder = await ShopOrder.get(uid)
  35. this.setData({
  36. user: shopOrder.toJSON()
  37. })
  38. console.log(this.data.user);
  39. },
  40. /**
  41. *
  42. * @param {*} e
  43. * 更换头像
  44. */
  45. async onChooseAvatar(e) {
  46. console.log(e);
  47. console.log(e.detail.avatarUrl);
  48. let url = e.detail.avatarUrl
  49. let pathUrl = await this.updataAvatar(url)
  50. let user = Parse.User.current()
  51. user.set("avatar", pathUrl)
  52. await user.save()
  53. this.setData({
  54. avatarUrl: pathUrl
  55. })
  56. this.refresh()
  57. },
  58. //上传头像
  59. updataAvatar(url) {
  60. let that = this;
  61. return new Promise((resolve, rejcet) => {
  62. qiniuUploader.upload(
  63. url,
  64. async (res) => {
  65. let img = res.imageURL;
  66. resolve(img)
  67. },
  68. (error) => {
  69. console.log("error: " + error);
  70. resolve(false)
  71. }, {
  72. region: "SCN",
  73. uploadURL: that.data.uploadURL,
  74. domain: that.data.domain,
  75. uptoken: that.data.uptokenURL,
  76. }
  77. );
  78. })
  79. },
  80. async getUptoken() {
  81. // 根据config.js全局配置company的ID来获取上传口令
  82. let res = await Parse.Cloud.run('qiniu_uptoken', {
  83. company: getApp().globalData.company
  84. })
  85. this.setData({
  86. uptokenURL: res.uptoken,
  87. domain: res.domain,
  88. uploadURL: res.zoneUrl
  89. })
  90. },
  91. goUrl(e) {
  92. let {
  93. url
  94. } = e.currentTarget.dataset
  95. wx.navigateTo({
  96. url: url,
  97. })
  98. },
  99. merchant() {
  100. let merchant = wx.getStorageSync('merchant');
  101. if (merchant) {
  102. wx.navigateTo({
  103. url: '/nova-tourism/pages/my/merchant/merchant-home/index'
  104. });
  105. } else {
  106. wx.navigateTo({
  107. url: '/nova-tourism/pages/my/merchant/login/index'
  108. });
  109. }
  110. },
  111. }
  112. })