wxAuth.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. var common_vendor = require("../../common/vendor.js");
  3. var api_user = require("../../api/user.js");
  4. require("../../common/request.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. user: {
  9. nickName: "",
  10. avatar: null,
  11. user: null
  12. }
  13. };
  14. },
  15. onLoad() {
  16. },
  17. methods: {
  18. bindblur(e) {
  19. this.nickName = e.detail.value;
  20. },
  21. bindinput(e) {
  22. this.nickName = e.detail.value;
  23. },
  24. onChooseAvatar(e) {
  25. let {
  26. avatarUrl
  27. } = e.detail;
  28. common_vendor.index.uploadFile({
  29. url: common_vendor.index.getStorageSync("requestPath") + "/app/common/uploadOSS",
  30. filePath: avatarUrl,
  31. name: "file",
  32. formData: {
  33. "user": "test"
  34. },
  35. success: (uploadFileRes) => {
  36. this.user.avatar = JSON.parse(uploadFileRes.data).url;
  37. }
  38. });
  39. },
  40. submit() {
  41. if (this.nickName == null || this.nickName == "") {
  42. common_vendor.index.showToast({
  43. icon: "none",
  44. title: "\u8BF7\u8F93\u5165\u6635\u79F0"
  45. });
  46. return;
  47. }
  48. this.user.nickName = this.nickName;
  49. this.user.isWeixinAuth = 1;
  50. api_user.editUser(this.user).then((res) => {
  51. if (res.code == 200) {
  52. common_vendor.index.setStorageSync("avatar", this.avatar);
  53. common_vendor.index.setStorageSync("nickName", this.nickName);
  54. this.$emit("updateUser");
  55. } else {
  56. common_vendor.index.showToast({
  57. icon: "none",
  58. title: "\u8BF7\u6C42\u5931\u8D25"
  59. });
  60. }
  61. }, (rej) => {
  62. });
  63. },
  64. getUserInfo() {
  65. api_user.getUserInfo().then((res) => {
  66. if (res.code == 200) {
  67. if (res.user != null) {
  68. this.user = res.user;
  69. console.log(this.user);
  70. } else {
  71. this.utils.loginOut();
  72. }
  73. } else {
  74. common_vendor.index.showToast({
  75. icon: "none",
  76. title: "\u8BF7\u6C42\u5931\u8D25"
  77. });
  78. }
  79. }, (rej) => {
  80. });
  81. }
  82. }
  83. };
  84. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  85. return {
  86. a: $data.user.avatar == null ? "https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/22cb9518a55040dea74d8f730551a7a2.jpg" : $data.user.avatar,
  87. b: common_vendor.o((...args) => $options.onChooseAvatar && $options.onChooseAvatar(...args)),
  88. c: common_vendor.o((...args) => $options.bindblur && $options.bindblur(...args)),
  89. d: common_vendor.o([($event) => _ctx.nickName = $event.detail.value, (...args) => $options.bindinput && $options.bindinput(...args)]),
  90. e: _ctx.nickName,
  91. f: common_vendor.o(($event) => $options.submit())
  92. };
  93. }
  94. var Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-0a951519"], ["__file", "E:/Project/2023/\u95EE\u8BCA\u5E73\u53F0/his_user_miniapp/pages/components/wxAuth.vue"]]);
  95. wx.createComponent(Component);