feedback.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_api = require("../../utils/api.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. feedbackType: "bug",
  8. // bug, suggestion, other
  9. description: "",
  10. imageList: [],
  11. isSubmitting: false
  12. };
  13. },
  14. onLoad() {
  15. const userInfo = common_vendor.index.getStorageSync("userInfo");
  16. if (!userInfo || !userInfo.id) {
  17. common_vendor.index.showToast({
  18. title: "请先登录",
  19. icon: "none"
  20. });
  21. setTimeout(() => {
  22. common_vendor.index.navigateTo({
  23. url: "/pages/login/login"
  24. });
  25. }, 1500);
  26. }
  27. },
  28. methods: {
  29. goBack() {
  30. common_vendor.index.navigateBack();
  31. },
  32. selectType(type) {
  33. this.feedbackType = type;
  34. },
  35. chooseImage() {
  36. common_vendor.index.chooseImage({
  37. count: 3 - this.imageList.length,
  38. sizeType: ["compressed"],
  39. sourceType: ["album", "camera"],
  40. success: (res) => {
  41. this.imageList = this.imageList.concat(res.tempFilePaths);
  42. },
  43. fail: (err) => {
  44. common_vendor.index.__f__("error", "at pages/feedback/feedback.vue:141", "选择图片失败:", err);
  45. common_vendor.index.showToast({
  46. title: "选择图片失败",
  47. icon: "none"
  48. });
  49. }
  50. });
  51. },
  52. deleteImage(index) {
  53. this.imageList.splice(index, 1);
  54. },
  55. async submitFeedback() {
  56. const userInfo = common_vendor.index.getStorageSync("userInfo");
  57. if (!userInfo || !userInfo.id) {
  58. common_vendor.index.showToast({
  59. title: "请先登录",
  60. icon: "none"
  61. });
  62. setTimeout(() => {
  63. common_vendor.index.navigateTo({
  64. url: "/pages/login/login"
  65. });
  66. }, 1500);
  67. return;
  68. }
  69. if (!this.description.trim()) {
  70. common_vendor.index.showToast({
  71. title: "请输入详细描述",
  72. icon: "none"
  73. });
  74. return;
  75. }
  76. if (this.isSubmitting) {
  77. return;
  78. }
  79. this.isSubmitting = true;
  80. common_vendor.index.showLoading({
  81. title: "提交中...",
  82. mask: true
  83. });
  84. try {
  85. const feedbackData = {
  86. userId: userInfo.id,
  87. type: this.feedbackType,
  88. description: this.description.trim(),
  89. images: this.imageList
  90. // 图片列表,暂时使用临时路径
  91. // 注意:在生产环境中,需要先将图片上传到服务器获取URL
  92. // images: uploadedImageUrls
  93. };
  94. const res = await utils_api.submitFeedback(feedbackData);
  95. common_vendor.index.hideLoading();
  96. this.isSubmitting = false;
  97. if (res && res.code === 200) {
  98. common_vendor.index.showToast({
  99. title: "提交成功",
  100. icon: "success"
  101. });
  102. this.description = "";
  103. this.imageList = [];
  104. this.feedbackType = "bug";
  105. setTimeout(() => {
  106. common_vendor.index.navigateBack();
  107. }, 1500);
  108. } else {
  109. common_vendor.index.showToast({
  110. title: res.message || "提交失败,请重试",
  111. icon: "none"
  112. });
  113. }
  114. } catch (error) {
  115. common_vendor.index.hideLoading();
  116. this.isSubmitting = false;
  117. common_vendor.index.__f__("error", "at pages/feedback/feedback.vue:229", "提交反馈失败:", error);
  118. common_vendor.index.showToast({
  119. title: error.message || "网络错误,请稍后再试",
  120. icon: "none"
  121. });
  122. }
  123. }
  124. }
  125. };
  126. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  127. return common_vendor.e({
  128. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  129. b: $data.feedbackType === "bug" ? 1 : "",
  130. c: common_vendor.o(($event) => $options.selectType("bug")),
  131. d: $data.feedbackType === "suggestion" ? 1 : "",
  132. e: common_vendor.o(($event) => $options.selectType("suggestion")),
  133. f: $data.feedbackType === "other" ? 1 : "",
  134. g: common_vendor.o(($event) => $options.selectType("other")),
  135. h: $data.description,
  136. i: common_vendor.o(($event) => $data.description = $event.detail.value),
  137. j: common_vendor.f($data.imageList, (image, index, i0) => {
  138. return {
  139. a: image,
  140. b: common_vendor.o(($event) => $options.deleteImage(index), index),
  141. c: index
  142. };
  143. }),
  144. k: $data.imageList.length < 3
  145. }, $data.imageList.length < 3 ? {
  146. l: common_vendor.o((...args) => $options.chooseImage && $options.chooseImage(...args))
  147. } : {}, {
  148. m: common_vendor.o((...args) => $options.submitFeedback && $options.submitFeedback(...args))
  149. });
  150. }
  151. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a24b82f2"]]);
  152. wx.createPage(MiniProgramPage);
  153. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/feedback/feedback.js.map