upload.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="flex">
  5. <label>输入文本:</label>
  6. <textarea v-model="supplyInfo.msg" class="area card"></textarea>
  7. </view>
  8. <view class="update_photo">
  9. <view class="title"></view>
  10. <view>选择图片:</view>
  11. <view class="update_container card upload-parent-box">
  12. <view class="update_button display-flex">
  13. <view class="upload-box" @click="getImage('album')">
  14. <view class="img">
  15. <image src="/static/photo.png" class="photo"></image>
  16. </view>
  17. <view class="txt">上传</view>
  18. </view>
  19. <view
  20. class="display-flex upload-box-photo"
  21. v-for="(item, index) in uploadList"
  22. :key="index"
  23. >
  24. <image:src="item"mode="aspectFit" style="width: 100%; height: 100%" @click="showLarge(item)"/>
  25. <image src="/static/del.png" class="del-icon"mode="aspectFit"
  26. style="width: 30rpx; height: 30rpx" @click="delPhoto(index)"></image>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="flex">
  32. <label>支部:</label>
  33. <input type="text" v-model="supplyInfo.title" class="input card" />
  34. </view>
  35. <view class="flex">
  36. <label>姓名:</label>
  37. <input type="text" v-model="supplyInfo.name" class="input card" />
  38. </view>
  39. <button class="submit" @tap="submit">提交</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import md5 from "@/common/md5.js";
  45. export default {
  46. data() {
  47. return {
  48. supplyInfo: {
  49. title: "",
  50. msg: "",
  51. name:''
  52. },
  53. uploadList: [],
  54. imgIdList: [],
  55. };
  56. },
  57. methods: {
  58. submit() {
  59. if (
  60. this.supplyInfo.name === "" ||
  61. this.supplyInfo.title === "" ||
  62. this.supplyInfo.msg === ""
  63. ) {
  64. uni.showToast({
  65. title: "内容不完善",
  66. icon: "error",
  67. });
  68. return;
  69. }
  70. let md5Sign = md5(
  71. "method=" +
  72. "activity" +
  73. "&timestamp=" +
  74. getApp().globalData.globalTimestamp +
  75. "&secret=" +
  76. getApp().globalData.secret
  77. );
  78. let url =
  79. getApp().globalData.shareUrl +
  80. "api/api.php" +
  81. "?method=activity&action=process&timestamp=" +
  82. getApp().globalData.globalTimestamp +
  83. "&sign=" +
  84. md5Sign;
  85. let postData = {
  86. openid : "asfsfsffa",
  87. activity_id : 1 , //这里固定是1
  88. content : this.supplyInfo.msg,
  89. department :this.supplyInfo.title,
  90. user_name : this.supplyInfo.name,
  91. attach_ids : '' // 3,34,5,5,6
  92. };
  93. uni.request({
  94. url: url,
  95. method: "POST",
  96. header: {
  97. "content-type": "application/x-www-form-urlencoded",
  98. },
  99. data: postData,
  100. success: (res) => {
  101. if (res.data.code === 200) {
  102. uni.showToast({
  103. title: "上传成功",
  104. icon: "none",
  105. duration: 2000,
  106. });
  107. // uni.setStorageSync("supply_name", this.company.name);
  108. // uni.setStorageSync("supply_code", this.company.code);
  109. // uni.setStorageSync("supply_tel", this.company.tel);
  110. setTimeout(() => {
  111. uni.navigateBack({});
  112. }, 1500);
  113. } else {
  114. uni.showToast({
  115. title: res.data.msg,
  116. icon: "none",
  117. duration: 2500,
  118. });
  119. }
  120. },
  121. fail: () => {
  122. console.log("连接失败");
  123. },
  124. });
  125. },
  126. bindPickerChange(e) {
  127. this.index = e.detail.value;
  128. },
  129. getImage(type) {
  130. let that = this;
  131. if (that.uploadList.length >= 3) {
  132. uni.showToast({
  133. title: "最多上传3张图片",
  134. icon: "none",
  135. duration: 2500,
  136. });
  137. return;
  138. }
  139. uni.chooseImage({
  140. sourceType: [type],
  141. count: 3 - that.uploadList.length,
  142. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  143. success: (res) => {
  144. for (let i = 0; i < res.tempFilePaths.length; i++) {
  145. that.uploadList.push(res.tempFilePaths[i]);
  146. that.uploadFileRequest(res.tempFilePaths[i]);
  147. }
  148. },
  149. });
  150. },
  151. uploadFileRequest(fileVal) {
  152. uni.showLoading({
  153. title: "上传中",
  154. mask: true,
  155. });
  156. let that = this;
  157. let md5Sign = md5(
  158. "method=" +"upload" + "&timestamp=" +
  159. getApp().globalData.globalTimestamp +
  160. "&secret=" + getApp().globalData.secret
  161. );
  162. let url =
  163. getApp().globalData.shareUrl +
  164. "api/upload.php" +
  165. "?method=upload&source=activity&id=1&timestamp=" +
  166. getApp().globalData.globalTimestamp +
  167. "&sign=" +
  168. md5Sign;
  169. uni.uploadFile({
  170. url: url, //需要设置为全局
  171. filePath: fileVal,
  172. name: "file",
  173. formData: {
  174. file: fileVal,
  175. },
  176. success: (res) => {
  177. let tmpres = JSON.parse(res.data);
  178. console.log(tmpres);
  179. uni.hideLoading();
  180. that.imgIdList.push(tmpres.data.id);
  181. },
  182. fail: (res) => {
  183. console.log("上传请求失败");
  184. console.log(res);
  185. },
  186. });
  187. },
  188. delPhoto(idx) {
  189. this.uploadList.splice(idx, 1);
  190. this.imgIdList.splice(idx, 1);
  191. },
  192. showLarge(src) {
  193. uni.previewImage({
  194. urls: [src],
  195. longPressActions: {
  196. itemList: ["发送给朋友", "保存图片"],
  197. success: function (data) {},
  198. fail: function (err) {
  199. console.log(err.errMsg);
  200. },
  201. },
  202. });
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="scss" scoped>
  208. .upload-parent-box {
  209. height: 150rpx;
  210. padding-top: 25rpx;
  211. padding-left: 20rpx;
  212. }
  213. .upload-box {
  214. display: flex;
  215. flex-flow: column;
  216. width: 25%;
  217. background-color: #e0e0e0;
  218. height: 140rpx;
  219. border-radius: 10rpx;
  220. padding-top: 15rpx;
  221. image {
  222. width: 60rpx !important;
  223. height: 60rpx !important;
  224. }
  225. }
  226. .upload-box-photo {
  227. width: 25%;
  228. height: 110rpx;
  229. border-radius: 10rpx;
  230. padding-top: 15rpx;
  231. position: relative;
  232. }
  233. .del-icon {
  234. position: absolute;
  235. right: 0;
  236. width: 30rpx;
  237. height: 30rpx;
  238. }
  239. .update_button {
  240. text-align: center;
  241. display: flex;
  242. }
  243. .content {
  244. font-size: 28rpx;
  245. font-weight: 200;
  246. padding: 1% 2%;
  247. .title {
  248. font-size: 30rpx;
  249. margin: 4% 0;
  250. }
  251. label {
  252. display: inline-block;
  253. width: 25%;
  254. vertical-align: middle;
  255. }
  256. .card {
  257. background-color: rgb(248, 247, 247);
  258. border-radius: 10rpx;
  259. }
  260. .flex {
  261. display: flex;
  262. align-items: center;
  263. margin-bottom: 2%;
  264. }
  265. .input {
  266. padding: 0 2%;
  267. margin: 2% 0;
  268. display: inline-block;
  269. width: 80%;
  270. height: 70rpx;
  271. }
  272. .supplyInfo {
  273. // border-radius: 40rpx;
  274. padding: 4%;
  275. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  276. margin: 30rpx 0 30rpx 0;
  277. .area {
  278. height: 200rpx;
  279. padding: 20rpx;
  280. box-sizing: border-box;
  281. }
  282. .picker {
  283. width: 80%;
  284. height: 70rpx;
  285. background: rgb(248, 247, 247);
  286. display: flex;
  287. align-items: center;
  288. position: relative;
  289. .pick {
  290. width: 100%;
  291. }
  292. .picker_title {
  293. display: flex;
  294. width: 100%;
  295. margin-left: 30rpx;
  296. align-items: center;
  297. justify-content: space-between;
  298. .triangle-down {
  299. width: 0;
  300. height: 0;
  301. border-top: 15rpx solid rgb(173, 173, 173);
  302. border-left: 15rpx solid transparent;
  303. border-right: 15rpx solid transparent;
  304. position: absolute;
  305. right: 10rpx;
  306. }
  307. .pickername {
  308. font-weight: 100;
  309. }
  310. }
  311. }
  312. .upload-box {
  313. width: 25%;
  314. background-color: #e0e0e0;
  315. height: 110rpx;
  316. border-radius: 10rpx;
  317. padding-top: 15rpx;
  318. }
  319. .upload-box-photo {
  320. width: 25%;
  321. height: 110rpx;
  322. border-radius: 10rpx;
  323. padding-top: 15rpx;
  324. position: relative;
  325. }
  326. .del-icon {
  327. position: absolute;
  328. right: 0;
  329. width: 30rpx;
  330. height: 30rpx;
  331. }
  332. image {
  333. width: 60rpx;
  334. height: 60rpx;
  335. }
  336. .update_button {
  337. text-align: center;
  338. display: flex;
  339. }
  340. }
  341. .info {
  342. margin-top: 2%;
  343. border-radius: 40rpx;
  344. padding: 2% 4%;
  345. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  346. }
  347. .submit {
  348. color: white;
  349. font-weight: normal;
  350. width: 70%;
  351. border-radius: 20rpx;
  352. background-color: #02a7f0;
  353. margin: 50rpx auto;
  354. }
  355. }
  356. </style>