{"id":31109,"date":"2024-11-25T11:25:42","date_gmt":"2024-11-25T03:25:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31109\/"},"modified":"2024-11-25T11:25:42","modified_gmt":"2024-11-25T03:25:42","slug":"%e5%ae%9e%e4%be%8b%e8%af%a6%e8%a7%a3%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31109\/","title":{"rendered":"\u5b9e\u4f8b\u8be6\u89e3\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\u7684\u5b9e\u4f8b\u4ee3\u7801\uff0c\u5728\u6587\u7ae0\u7ed9\u5927\u5bb6\u8865\u5145\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u4e00\u6216\u591a\u5f20\u56fe\u7247 \u7684\u65b9\u6cd5\uff0c\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5177\u6709\u53c2\u8003\u501f\u9274\u52a0\u8f7d,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n<p>\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\uff1a<\/p>\n<p>1.\u5148\u5728\u524d\u7aef\u5199\u4e00\u4e2a\u9009\u62e9\u56fe\u7247\u7684\u533a\u57df\u6765\u89e6\u53d1wx.chooseImage\u63a5\u53e3\u5e76\u7528wx.setStorage\u63a5\u53e3\u628a\u56fe\u7247\u8def\u5f84\u5b58\u8d77\u6765\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/75c43d314309c3bd94448183d028f09f-0.png\" class=\"aligncenter\" title=\"\u5b9e\u4f8b\u8be6\u89e3\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\u63d2\u56fe\" alt=\"\u5b9e\u4f8b\u8be6\u89e3\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\u63d2\u56fe\" \/><\/p>\n<\/p>\n<pre>-wxml\r\n &lt;view class=\"shangchuan\" bindtap=\"choose\"&gt;\r\n  &lt;image style=\"width:100%;height:100%;\" src=\"{{tempFilePaths}}\"&gt;&lt;\/image&gt;\r\n &lt;\/view&gt;\r\n &lt;button formType='submit' class=\"fabu\"&gt;\u53d1\u5e03\u9879\u76ee&lt;\/button&gt;\r\n \/**\u9009\u62e9\u56fe\u7247 *\/\r\n choose: function () {\r\n  var that = this\r\n  wx.chooseImage({\r\n   count: 1,\r\n   sizeType: ['original', 'compressed'], \/\/ \u53ef\u4ee5\u6307\u5b9a\u662f\u539f\u56fe\u8fd8\u662f\u538b\u7f29\u56fe\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709\r\n   sourceType: ['album', 'camera'], \/\/ \u53ef\u4ee5\u6307\u5b9a\u6765\u6e90\u662f\u76f8\u518c\u8fd8\u662f\u76f8\u673a\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709\r\n   success: function (res) {\r\n    var tempFilePaths = res.tempFilePaths\r\n    that.setData({\r\n     tempFilePaths: res.tempFilePaths\r\n    })\r\n    console.log(res.tempFilePaths)\r\n    wx.setStorage({ key: \"card\", data: tempFilePaths[0] })\r\n   }\r\n  })\r\n },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2.\u4f7f\u7528wx.uploadFile\u5c06\u521a\u624d\u4e0a\u4f20\u7684\u56fe\u7247\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a<\/p>\n<\/p>\n<pre>\r\n formSubmit2: function (e) {\r\n    var that = this\r\n    var card = wx.getStorageSync('card')\r\n    wx.uploadFile({\r\n     url: app.globalData.create_funds,\r\n     filePath: card,\r\n     name: 'card',\r\n     formData: {\r\n      'user_id': app.globalData.user_id,\r\n      'person': e.detail.value.person,\r\n      'company': e.detail.value.company,\r\n     },\r\n     success: function (res) {\r\n      console.log(res)\r\n     }\r\n    })\r\n   }\r\n  }\r\n },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>PS\uff1a \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u4e00\u6216\u591a\u5f20\u56fe\u7247<\/p>\n<p>\u4e00.\u8981\u70b9<\/p>\n<p>1.\u9009\u53d6\u56fe\u7247<\/p>\n<\/p>\n<pre>wx.chooseImage({\r\n   sizeType: [], \/\/ original \u539f\u56fe\uff0ccompressed \u538b\u7f29\u56fe\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709\r\n   sourceType: [], \/\/ album \u4ece\u76f8\u518c\u9009\u56fe\uff0ccamera \u4f7f\u7528\u76f8\u673a\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709\r\n   success: function (res) {\r\n    console.log(res);\r\n    var array = res.tempFilePaths, \/\/\u56fe\u7247\u7684\u672c\u5730\u6587\u4ef6\u8def\u5f84\u5217\u8868\r\n   }\r\n  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2.\u4e0a\u4f20\u56fe\u7247<\/p>\n<\/p>\n<pre>wx.uploadFile({\r\n   url: '', \/\/\u5f00\u53d1\u8005\u670d\u52a1\u5668\u7684 url\r\n   filePath: '', \/\/ \u8981\u4e0a\u4f20\u6587\u4ef6\u8d44\u6e90\u7684\u8def\u5f84 String\u7c7b\u578b\uff01\uff01\uff01\r\n   name: 'uploadFile', \/\/ \u6587\u4ef6\u5bf9\u5e94\u7684 key ,(\u540e\u53f0\u63a5\u53e3\u89c4\u5b9a\u7684\u5173\u4e8e\u56fe\u7247\u7684\u8bf7\u6c42\u53c2\u6570)\r\n   header: {\r\n    'content-type': 'multipart\/form-data'\r\n   }, \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u7684 header\r\n   formData: { }, \/\/ HTTP \u8bf7\u6c42\u4e2d\u5176\u4ed6\u989d\u5916\u7684\u53c2\u6570\r\n   success: function (res) {\r\n   },\r\n   fail: function (res) {\r\n   }\r\n  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e8c.\u4ee3\u7801\u793a\u4f8b<\/p>\n<\/p>\n<pre>\/\/ \u70b9\u51fb\u4e0a\u4f20\u56fe\u7247\r\nupShopLogo: function () {\r\n  var that = this;\r\n  wx.showActionSheet({\r\n   itemList: ['\u4ece\u76f8\u518c\u4e2d\u9009\u62e9', '\u62cd\u7167'],\r\n   itemColor: \"#f7982a\",\r\n   success: function (res) {\r\n    if (!res.cancel) {\r\n     if (res.tapIndex == 0) {\r\n      that.chooseWxImageShop('album')  \r\n     } else if (res.tapIndex == 1) {\r\n      that.chooseWxImageShop('camera')\r\n     }\r\n    }\r\n   }\r\n  })\r\n },\r\n chooseWxImageShop: function (type) {\r\n  var that = this;\r\n  wx.chooseImage({\r\n   sizeType: ['original', 'compressed'],\r\n   sourceType: [type],\r\n   success: function (res) {\r\n\/*\u4e0a\u4f20\u5355\u5f20\r\n    that.data.orderDetail.shopImage = res.tempFilePaths[0],\r\n    that.upload_file(API_URL + 'shop\/shopIcon', res.tempFilePaths[0])\r\n*\/\r\n \/*\u4e0a\u4f20\u591a\u5f20\uff08\u904d\u5386\u6570\u7ec4\uff0c\u4e00\u6b21\u4f20\u4e00\u5f20\uff09\r\n    for (var index in res.tempFilePaths) {\r\n       that.upload_file(API_URL + 'shop\/shopImage', res.tempFilePaths[index])\r\n    }\r\n*\/\r\n   }\r\n  })\r\n },\r\nupload_file: function (url, filePath) {\r\n  var that = this;\r\n  wx.uploadFile({\r\n   url: url,\r\n   filePath: filePath,\r\n   name: 'uploadFile',\r\n   header: {\r\n    'content-type': 'multipart\/form-data'\r\n   }, \/\/ \u8bbe\u7f6e\u8bf7\u6c42\u7684 header\r\n   formData: { 'shopId': wx.getStorageSync('shopId') }, \/\/ HTTP \u8bf7\u6c42\u4e2d\u5176\u4ed6\u989d\u5916\u7684 form data\r\n   success: function (res) {\r\n    wx.showToast({\r\n       title: \"\u56fe\u7247\u4fee\u6539\u6210\u529f\",\r\n       icon: 'success',\r\n       duration: 700\r\n      })\r\n   },\r\n   fail: function (res) {\r\n   }\r\n  })\r\n },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b9e\u4f8b\u8be6\u89e3\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\u7684\u5b9e\u4f8b\u4ee3\u7801\uff0c\u5728\u6587\u7ae0\u7ed9\u5927\u5bb6\u8865\u5145\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u4e00\u6216\u591a\u5f20\u56fe\u7247 \u7684\u65b9\u6cd5\uff0c\u672c\u6587\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5177\u6709\u53c2\u8003\u501f\u9274\u52a0\u8f7d,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002 \u4e0a\u4f20\u56fe\u7247\u5230\u670d\u52a1\u5668\uff1a 1.\u5148\u5728\u524d\u7aef\u5199\u4e00\u4e2a\u9009\u62e9\u56fe\u7247\u7684\u533a\u57df\u6765\u89e6\u53d1wx.chooseImage\u63a5\u53e3\u5e76\u7528wx.setStorage\u63a5\u53e3\u628a\u56fe\u7247\u8def\u5f84\u5b58\u8d77\u6765\u3002 -wxml &lt;view class=&#8221;shangchuan&#8221; bindtap=&#8221;choose&#8221;&gt; &lt;image style=&#8221;width:100%;height:100%;&#8221; src=&#8221;{{tempFilePaths}}&#8221;&gt;&lt;\/image&gt; &lt;\/view&gt; &lt;button formType=&#8217;submit&#8217; class=&#8221;fabu&#8221;&gt;\u53d1\u5e03\u9879\u76ee&lt;\/button&gt; \/**\u9009\u62e9\u56fe\u7247 *\/ choose: function () { var that = this wx.chooseImage({ count: 1, sizeType: [&#8216;original&#8217;, &#8216;compressed&#8217;], \/\/ \u53ef\u4ee5\u6307\u5b9a\u662f\u539f\u56fe\u8fd8\u662f\u538b\u7f29\u56fe\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709 sourceType: [&#8216;album&#8217;, &#8216;camera&#8217;], \/\/ \u53ef\u4ee5\u6307\u5b9a\u6765\u6e90\u662f\u76f8\u518c\u8fd8\u662f\u76f8\u673a\uff0c\u9ed8\u8ba4\u4e8c\u8005\u90fd\u6709 success: function (res) { var tempFilePaths = res.tempFilePaths that.setData({ tempFilePaths: res.tempFilePaths }) console.log(res.tempFilePaths) wx.setStorage({ key: &#8220;card&#8221;, data: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-31109","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=31109"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31109\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}