securityCheck.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // pages/securityCheck/securityCheck.js
  2. import { postApi } from "../../apis/api";
  3. import { apiUrl } from "../../apis/apiConfig";
  4. import { isImage } from "../../utils/utils";
  5. Page({
  6. data: {
  7. list: [],
  8. loginStatus: wx.getStorageSync("userId"),
  9. },
  10. async login() {
  11. if (!wx.getStorageSync("openId")) return;
  12. let res1 = await postApi("/user/wx/openId/login", {
  13. openId: wx.getStorageSync("openId"),
  14. });
  15. if (res1.data.status == 0) {
  16. let data = {
  17. ...res1.data.result.userInfo,
  18. ...res1.data.result.shipInfo,
  19. };
  20. Object.keys(data).forEach(function (key) {
  21. wx.setStorageSync(key, data[key]);
  22. });
  23. this.setData({
  24. loginStatus: true,
  25. });
  26. this.getList();
  27. } else {
  28. wx.switchTab({
  29. url: "/pages/takePhoto/takePhoto",
  30. });
  31. }
  32. },
  33. async getList() {
  34. if (!wx.getStorageSync("userId")) {
  35. wx.showToast({
  36. title: "尚未登录",
  37. icon: "none",
  38. });
  39. return;
  40. }
  41. let { data } = await postApi("/security/check/list", {
  42. userId: wx.getStorageSync("userId"),
  43. shipId: wx.getStorageSync("shipId"),
  44. });
  45. wx.stopPullDownRefresh();
  46. if (data.status == 0) {
  47. for (let i of data.result) {
  48. i.isImage = isImage(i.fileKey);
  49. }
  50. this.setData({
  51. list: data.result,
  52. });
  53. } else {
  54. this.setData({
  55. list: [],
  56. });
  57. }
  58. },
  59. uploadMedia(e) {
  60. let { id: itemId } = e.currentTarget.dataset;
  61. wx.showLoading({
  62. title: "高精度定位中...",
  63. });
  64. wx.getLocation({
  65. type: "gcj02",
  66. isHighAccuracy: true,
  67. success: (e) => {
  68. let { latitude, longitude } = e;
  69. wx.chooseMedia({
  70. count: 1,
  71. mediaType: ["image", "video"],
  72. sourceType: ["album", "camera"],
  73. sizeType: ["original", "compressed"],
  74. success: (e) => {
  75. console.log("获取媒体成功!", e);
  76. let filePath = e.tempFiles[0].tempFilePath;
  77. wx.showLoading({
  78. title: "正在上传...",
  79. });
  80. wx.uploadFile({
  81. url: `${apiUrl}/security/check/upload/file`,
  82. filePath,
  83. name: "file",
  84. formData: {
  85. itemId,
  86. userId: wx.getStorageSync("userId"),
  87. location: `${longitude},${latitude}`,
  88. },
  89. success: async (e) => {
  90. let data = JSON.parse(e.data);
  91. if (data.status == 0) {
  92. this.getList();
  93. wx.showToast({
  94. title: data.msg,
  95. duration: 1500,
  96. });
  97. } else {
  98. wx.showToast({
  99. title: data.msg,
  100. icon: "none",
  101. duration: 2000,
  102. });
  103. }
  104. },
  105. fail: (err) => {
  106. wx.showToast({
  107. title: data.msg,
  108. icon: "none",
  109. duration: 2000,
  110. });
  111. },
  112. });
  113. },
  114. fail: (e) => {
  115. console.log("失败1", e);
  116. },
  117. });
  118. },
  119. fail: (e) => {
  120. this.setData({
  121. authModal: true,
  122. modalText: "位置信息",
  123. });
  124. },
  125. complete: (e) => {
  126. wx.hideLoading({
  127. success: (res) => {},
  128. });
  129. },
  130. });
  131. },
  132. onPullDownRefresh() {
  133. this.getList();
  134. },
  135. onShow() {
  136. this.setData({
  137. loginStatus: wx.getStorageSync("userId"),
  138. });
  139. },
  140. onLoad(options) {
  141. this.getList();
  142. },
  143. });