当前位置:   article > 正文

uniApp中图片文件上传插件(uniFilePicker)_uni-file-picker 手动上传

uni-file-picker 手动上传

首先去下载插件uni-file-picker 文件选择上传 - DCloud 插件市场

1.图片上传

  1. <template>
  2. <view class="content">
  3. <view class="wrap">
  4. <timeWeek></timeWeek>
  5. <view class="data_info">
  6. <view class="list">
  7. <text style="color: #666666;">{{dataFrom.checkUserName}}</text>
  8. </view>
  9. <view class="foods" v-if="details">
  10. <view class="foods_img">
  11. <view class="text">
  12. <text>菜谱图片</text>
  13. </view>
  14. <view class="img" @click="previewImage">
  15. <image :src="supplyPicture[0]" v-if="details"></image>
  16. <image v-else></image>
  17. </view>
  18. </view>
  19. <view class="foods_text">
  20. <view class="text">
  21. <text>菜谱内容</text>
  22. </view>
  23. <view class="foods_list">
  24. <text v-for="(item,index) in supplyMenu" :key="index" v-if="supplyMenu">{{item}}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="list">
  29. <text>菜品数量:</text>
  30. <view class="checkbox">
  31. <radio-group>
  32. <label v-for="(item,index) in scoreList" :key="index" @click="number_change(index)">
  33. <radio color="#007aff" :value="item.id + ''" :checked="item.id==numberCurrent" />
  34. <text>{{item.text}}</text>
  35. </label>
  36. </radio-group>
  37. </view>
  38. </view>
  39. <view class="list">
  40. <text>菜品味道:</text>
  41. <view class="checkbox">
  42. <radio-group>
  43. <label v-for="(item,index) in scoreList" :key="index" @click="taste_change(index)">
  44. <radio color="#007aff" :value="item.id + ''" :checked="item.id==tasteCurrent" />
  45. <text>{{item.text}}</text>
  46. </label>
  47. </radio-group>
  48. </view>
  49. </view>
  50. <view class="feedback">
  51. <text>意见留言</text>
  52. <textarea placeholder-style="color:#999999" placeholder="请填写意见留言" v-model="dataFrom.suggestion" />
  53. </view>
  54. <view class="add_image">
  55. <text>添加图片</text>
  56. <view class="upload">
  57. <uni-file-picker limit="9" @select="select" @delete='del_img' v-model="fileLists">
  58. <view class="add">
  59. <image src="@/static/images/imgAdd.png" mode="widthFix"></image>
  60. </view>
  61. </uni-file-picker>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="btn" @click="submit" v-if="!stateFlag">
  66. <button type="primary">提交</button>
  67. </view>
  68. <view class="btn" @click="modification" v-if="stateFlag">
  69. <button type="primary">修改</button>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import timeWeek from "@/common/time-week/index.vue"
  76. import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
  77. import urlConfig from "@/utils/config.js"
  78. import {
  79. foodSafetyMenuDetailByTime,
  80. foodSafetyParentCheckAdd,
  81. foodSafetyParentCheckDetail,
  82. foodSafetyParentCheckEdit
  83. } from "@/api/food_safety.js"
  84. import upload from "@/api/upload.js"
  85. export default {
  86. components: {
  87. timeWeek
  88. },
  89. data() {
  90. return {
  91. scoreList: [{ //评分标准
  92. text: '优',
  93. id: 1
  94. },
  95. {
  96. text: '中',
  97. id: 2
  98. }, {
  99. text: '差',
  100. id: 3
  101. }
  102. ],
  103. id: null,
  104. timer: null,
  105. numberCurrent: null, //菜品数量状态
  106. tasteCurrent: null, //菜品味道状态
  107. dataFrom: {
  108. checkType: null, //检查类型
  109. checkUserCode: null, //检查者
  110. checkUserName: null, //检查者姓名
  111. pictures: null, //检查记录图片
  112. suggestion: null, //意见建议
  113. tasteEvaluate: null, //菜品味道评价
  114. quantityEvaluate: null //菜品数量评价
  115. },
  116. details: "", //详情
  117. supplyMenu: [], //菜谱列表
  118. supplyPicture: [], //菜谱图片列表
  119. fileImg: [], //上传图片列表
  120. fileLists: [],
  121. stateFlag: false
  122. }
  123. },
  124. created() {
  125. this.get_details() //获取数据详情
  126. this.get_detaisl_same() //查询当天是否有检查记录
  127. },
  128. methods: {
  129. number_change(index) { //菜品数量
  130. if (this.numberCurrent == this.scoreList[index].id) {
  131. this.numberCurrent = null
  132. this.dataFrom.quantityEvaluate = null
  133. } else {
  134. this.numberCurrent = this.scoreList[index].id
  135. this.dataFrom.quantityEvaluate = this.scoreList[index].id
  136. }
  137. },
  138. taste_change(index) { //菜品味道
  139. if (this.tasteCurrent == this.scoreList[index].id) {
  140. this.tasteCurrent = null
  141. this.dataFrom.tasteEvaluate = null
  142. } else {
  143. this.tasteCurrent = this.scoreList[index].id
  144. this.dataFrom.tasteEvaluate = this.scoreList[index].id
  145. }
  146. },
  147. get_detaisl_same() { //查询当天是否有检查记录
  148. var time = new Date();
  149. var year = time.getFullYear(); //年
  150. var month = (time.getMonth() + 1 + "").padStart(2, "0"); //月
  151. var date = (time.getDate() + "").padStart(2, "0"); //日
  152. this.timer = `${year}-${month}-${date}`
  153. var data = {
  154. createTime: this.timer,
  155. checkType: 0
  156. }
  157. foodSafetyParentCheckDetail(data).then(res => {
  158. if (res.data) {
  159. this.stateFlag = true
  160. this.dataFrom.checkUserName = res.data.checkUserName //获取新的检测员
  161. this.dataFrom.suggestion = res.data.suggestion //获取新的意见留言
  162. this.numberCurrent = res.data.quantityEvaluate //获取新的菜品数量状态
  163. this.tasteCurrent = res.data.tasteEvaluate //获取新的菜品数量状态
  164. this.dataFrom.tasteEvaluate = res.data.tasteEvaluate //获取新的菜品数量
  165. this.dataFrom.quantityEvaluate = res.data.quantityEvaluate //获取新的菜品数量
  166. this.dataFrom.checkType = res.data.checkTyp //获取新的检查类型
  167. this.id = res.data.id //获取id
  168. this.imgDetailsList = res.data.pictures //获取返回的图片
  169. this.fileLists = []
  170. if (res.data.pictures) {
  171. var arrImg = res.data.pictures.split(',')
  172. for (var i = 0; i < arrImg.length; i++) {
  173. var url = urlConfig +
  174. '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=' +
  175. arrImg[i]
  176. var mydata = {
  177. "url": url,
  178. "fileID": arrImg[i]
  179. }
  180. this.fileLists.push(mydata);
  181. }
  182. }
  183. } else {
  184. this.stateFlag = false
  185. }
  186. })
  187. },
  188. get_details() { //获取数据详情
  189. this.dataFrom.checkUserName = uni.getStorageSync('Admin-Account'); //获取用户
  190. var time = new Date();
  191. var year = time.getFullYear(); //年
  192. var month = (time.getMonth() + 1 + "").padStart(2, "0"); //月
  193. var date = (time.getDate() + "").padStart(2, "0"); //日
  194. this.timer = `${year}-${month}-${date}`
  195. var data = {
  196. supplyTime: this.timer
  197. }
  198. foodSafetyMenuDetailByTime(data).then(res => { //获取详情
  199. if (res.data) {
  200. this.details = res.data
  201. this.dataFrom.checkUserCode = this.details.supplyCode; //检查者
  202. this.supplyMenu = this.details.supplyMenu.split(/,| |,/)
  203. if (this.details.supplyPicture) {
  204. var imgList = this.details.supplyPicture.split(',')
  205. imgList.forEach(item => {
  206. this.supplyPicture.push(urlConfig +
  207. '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=' +
  208. item);
  209. })
  210. }
  211. }
  212. })
  213. },
  214. submit() { //提交
  215. var arrImg = [];
  216. for (var i = 0; i < this.fileImg.length; i++) {
  217. arrImg.push(this.fileImg[i].fileObjectName)
  218. }
  219. this.dataFrom.pictures = arrImg.join(','); //检查记录图片
  220. this.dataFrom.checkType = 0 //检查类型
  221. if (this.dataFrom.quantityEvaluate == null) {
  222. uni.showToast({
  223. icon: 'none',
  224. title: '请评价菜品数量',
  225. duration: 2000
  226. })
  227. } else if (this.dataFrom.tasteEvaluate == null) {
  228. uni.showToast({
  229. icon: 'none',
  230. title: '请评价菜品味道',
  231. duration: 2000
  232. })
  233. } else if (this.dataFrom.suggestion == null) {
  234. uni.showToast({
  235. icon: 'none',
  236. title: '请输入意见留言',
  237. duration: 2000
  238. })
  239. } else if (this.dataFrom.pictures == "") {
  240. uni.showToast({
  241. icon: 'none',
  242. title: '请添加图片',
  243. duration: 2000
  244. })
  245. } else {
  246. foodSafetyParentCheckAdd(this.dataFrom).then(res => {
  247. if (res.code == "00000") {
  248. uni.showToast({
  249. title: '提交成功',
  250. duration: 2000
  251. })
  252. this.dataFrom = {
  253. pictures: null, //检查记录图片
  254. suggestion: null, //意见建议
  255. tasteEvaluate: null, //菜品味道评价
  256. quantityEvaluate: null //菜品数量评价
  257. }
  258. this.fileImg = []
  259. this.fileLists = []
  260. this.numberCurrent = null //菜品数量状态
  261. this.tasteCurrent = null //菜品味道状态
  262. this.get_details()
  263. this.get_detaisl_same()
  264. }
  265. })
  266. }
  267. },
  268. modification() { //修改
  269. this.dataFrom.id = this.id //获取修改id
  270. var oldList = null
  271. var arr = []
  272. if (this.fileLists && this.fileLists.length > 0) {
  273. oldList = this.fileLists.map(item => item.fileID).join(',')
  274. }
  275. //检查记录图片
  276. if (this.fileImg != null && this.fileImg.length > 0) {
  277. this.fileImg.forEach(item => {
  278. arr.push(item.fileObjectName)
  279. })
  280. if (oldList) {
  281. this.dataFrom.pictures = oldList + ',' + arr.join(',')
  282. this.fileImg = []
  283. } else {
  284. this.dataFrom.pictures = arr.join(',')
  285. this.fileImg = []
  286. }
  287. } else {
  288. if (oldList) {
  289. this.dataFrom.pictures = oldList
  290. } else {
  291. this.dataFrom.pictures = arr.join(',')
  292. }
  293. }
  294. // this.dataFrom.pictures = ""
  295. foodSafetyParentCheckEdit(this.dataFrom).then(res => {
  296. if (res.code == "00000") {
  297. uni.showToast({
  298. title: '修改成功',
  299. duration: 2000
  300. })
  301. this.get_detaisl_same() //查询当天是否有检查记录
  302. }
  303. })
  304. },
  305. select(e) { //上传图片
  306. let that = this
  307. uni.showLoading({
  308. title: "上传中"
  309. });
  310. const tempFilePaths = e.tempFilePaths;
  311. for (var i = 0; i < tempFilePaths.length; i++) {
  312. const tempFile = e.tempFiles[i];
  313. uni.uploadFile({
  314. url: urlConfig + '/sysFileInfo/upload',
  315. header: {
  316. 'Authorization': uni.getStorageSync('Admin-Token')
  317. },
  318. formData: {
  319. secretFlag: 'N',
  320. fileLocation: 5
  321. },
  322. filePath: tempFilePaths[i],
  323. name: 'file',
  324. success: (uploadFileRes) => {
  325. uni.hideLoading();
  326. const back = JSON.parse(uploadFileRes.data);
  327. if (uploadFileRes.statusCode == 200) {
  328. that.$set(back.data, "uuid", tempFile.uuid)
  329. that.$set(back.data, "path", tempFile.path)
  330. that.$set(back.data, "url", tempFile.url)
  331. that.fileImg.push(back.data);
  332. }
  333. },
  334. fail: () => {
  335. uni.hideLoading();
  336. uni.showToast("上传失败,请联系开发!")
  337. },
  338. complete: function() {
  339. uni.hideLoading();
  340. }
  341. });
  342. }
  343. },
  344. del_img(e) { //删除图片
  345. this.fileImg.map((item, index) => {
  346. if (item.url == e.tempFile.url) {
  347. this.fileImg.splice(index, 1)
  348. }
  349. })
  350. this.fileLists.map((item, index) => {
  351. if (item.fileID == e.tempFile.fileID) {
  352. this.fileLists.splice(index, 1)
  353. }
  354. })
  355. },
  356. previewImage() { //预览图片
  357. uni.previewImage({
  358. current: 0,
  359. urls: this.supplyPicture
  360. })
  361. }
  362. }
  363. }
  364. </script>
  365. <style lang="scss" scoped>
  366. .content {
  367. .title {
  368. background-color: #F5F5F5;
  369. margin-bottom: 24rpx;
  370. margin-top: 24rpx;
  371. display: flex;
  372. align-items: center;
  373. text {
  374. display: block;
  375. padding: 20rpx 0;
  376. &:last-child {
  377. padding-left: 10rpx;
  378. }
  379. &:first-child {
  380. padding-right: 10rpx;
  381. padding-left: 20rpx;
  382. }
  383. }
  384. }
  385. .wrap {
  386. width: 95%;
  387. margin: 0 auto;
  388. }
  389. .data_info {
  390. .list {
  391. display: flex;
  392. align-items: center;
  393. margin-bottom: 24rpx;
  394. background-color: #F5F5F5;
  395. padding: 20rpx;
  396. box-sizing: border-box;
  397. text {
  398. display: inline-block;
  399. &:last-child {
  400. color: #999999;
  401. flex: 3;
  402. }
  403. }
  404. .checkbox {
  405. display: flex;
  406. align-items: center;
  407. label {
  408. padding-right: 20rpx;
  409. }
  410. radio {
  411. transform: scale(.8)
  412. }
  413. }
  414. }
  415. .foods {
  416. padding-bottom: 24rpx;
  417. text {
  418. font-size: 28rpx;
  419. color: #666666;
  420. display: block;
  421. text-align: center;
  422. }
  423. .foods_img {
  424. display: flex;
  425. align-items: center;
  426. justify-content: space-between;
  427. border: 1px solid #EEEEEE;
  428. .text {
  429. flex: 1;
  430. width: 50%;
  431. }
  432. .img {
  433. flex: 1;
  434. width: 50%;
  435. box-sizing: border-box;
  436. border-left: 1px solid #EEEEEE;
  437. image {
  438. width: 80%;
  439. height: 180rpx;
  440. display: block;
  441. margin: 24rpx auto;
  442. }
  443. }
  444. }
  445. .foods_text {
  446. border: 1px solid #EEEEEE;
  447. border-top: none;
  448. display: flex;
  449. align-items: center;
  450. justify-content: space-between;
  451. .text {
  452. flex: 1;
  453. width: 50%;
  454. }
  455. .foods_list {
  456. border-left: 1px solid #EEEEEE;
  457. flex: 1;
  458. width: 50%;
  459. padding: 24rpx 0;
  460. text {
  461. line-height: 40rpx;
  462. }
  463. }
  464. }
  465. }
  466. .feedback {
  467. padding-bottom: 24rpx;
  468. text {
  469. display: block;
  470. background-color: #F5F5F5;
  471. padding: 20rpx;
  472. }
  473. }
  474. .add_image {
  475. padding-bottom: 24rpx;
  476. text {
  477. display: block;
  478. background-color: #F5F5F5;
  479. padding: 20rpx;
  480. }
  481. .upload {
  482. .add {
  483. image {
  484. width: 100rpx;
  485. }
  486. }
  487. }
  488. }
  489. }
  490. }
  491. </style>

2.文件上传

  1. <template>
  2. <view class="file">
  3. <uni-file-picker file-mediatype="all" @select="select" @delete='del' v-model="showDetalistFile">
  4. <view class="text_img">
  5. <image src="@/static/images/upload.png" mode=""></image>
  6. <text>添加附件</text>
  7. </view>
  8. </uni-file-picker>
  9. </view>
  10. </template>
  11. <script>
  12. import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
  13. import {
  14. courseActivityTeacheractivityCode
  15. } from "@/api/course_activity.js"
  16. import urlConfig from "@/utils/config.js"
  17. export default {
  18. data() {
  19. return {
  20. submitFrom: {
  21. activityCode: null, //activityCode
  22. experience: null, //心得体会
  23. coursewares: null //上传文档
  24. },
  25. fileUrl: [],
  26. dataDetails: {},
  27. detalistFile: [],
  28. showDetalistFile: []
  29. }
  30. },
  31. async mounted() {
  32. await this.get_details()
  33. },
  34. components: {
  35. uniFilePicker
  36. },
  37. methods: {
  38. get_details() { //获取详情数据
  39. courseActivityTeacherDetail(this.code).then(res => {
  40. if (res.data.courseActivityTeacher) {
  41. this.dataDetails = res.data.courseActivityTeacher
  42. this.submitFrom.experience = this.dataDetails.experience
  43. }
  44. if (res.data.fileinfos) {
  45. this.detalistFile = res.data.fileinfos
  46. for (var i = 0; i < this.detalistFile.length; i++) {
  47. var mydata = {
  48. "name": this.detalistFile[i].fileOriginName,
  49. "extname": this.detalistFile[i].fileSuffix,
  50. "url": "",
  51. "fileId": this.detalistFile[i].fileId,
  52. }
  53. this.showDetalistFile.push(mydata);
  54. }
  55. }
  56. if (res.data.courseActivityTeacher) {
  57. this.stateFlag = res.data.courseActivityTeacher.statusFlag
  58. } else {
  59. this.stateFlag = null
  60. }
  61. })
  62. },
  63. submit() { //点击提交
  64. var coursewares = [];
  65. for (var i = 0; i < this.detalistFile.length; i++) {
  66. coursewares.push(this.detalistFile[i].fileId)
  67. }
  68. this.submitFrom.coursewares = coursewares.join(',');
  69. courseActivityTeacheraddExperience(this.submitFrom).then(res => {
  70. if (res.code == "00000") {
  71. this.submitFrom = null
  72. uni.redirectTo({
  73. url: "/pages/course_activity/course_activity_manager/activity-list"
  74. })
  75. uni.showToast({
  76. title: '提交成功',
  77. duration: 2000
  78. })
  79. }
  80. })
  81. },
  82. select(e) {
  83. let that = this
  84. uni.showLoading({
  85. title: "上传中"
  86. });
  87. const tempFilePaths = e.tempFilePaths;
  88. for (var i = 0; i < tempFilePaths.length; i++) {
  89. const tempFile = e.tempFiles[i];
  90. uni.uploadFile({
  91. url: urlConfig + '/sysFileInfo/upload',
  92. header: {
  93. 'Authorization': uni.getStorageSync('Admin-Token')
  94. },
  95. formData: {
  96. secretFlag: 'N',
  97. fileLocation: 5
  98. },
  99. filePath: tempFilePaths[i],
  100. name: 'file',
  101. success: (uploadFileRes) => {
  102. uni.hideLoading();
  103. const back = JSON.parse(uploadFileRes.data);
  104. if (uploadFileRes.statusCode == 200) {
  105. that.$set(back.data, "uuid", tempFile.uuid)
  106. that.detalistFile.push(back.data);
  107. }
  108. },
  109. fail: () => {
  110. uni.hideLoading();
  111. uni.showToast("上传失败,请联系开发!")
  112. },
  113. complete: function() {
  114. uni.hideLoading();
  115. }
  116. });
  117. }
  118. },
  119. del(e) { //删除
  120. this.detalistFile.map((item, index) => {
  121. if (item.uuid) {
  122. if (item.uuid == e.tempFile.uuid) {
  123. this.detalistFile.splice(index, 1)
  124. }
  125. } else {
  126. if (item.fileId == e.tempFile.fileId) {
  127. this.detalistFile.splice(index, 1)
  128. }
  129. }
  130. })
  131. }
  132. }
  133. }
  134. </script>
  1. <template>
  2. <view class="content">
  3. <view class="wrap">
  4. <!-- 活动通知开始 -->
  5. <view class="activity_inform">
  6. <view class="list">
  7. <text>教研活动主题:</text>
  8. <text>{{details.name}}</text>
  9. </view>
  10. <view class="list">
  11. <text>教研活动时间:</text>
  12. <text>{{details.updateTime}} 至 {{details.endTime}}</text>
  13. </view>
  14. <view class="list">
  15. <text>教研活动地点:</text>
  16. <text>{{details.place}}</text>
  17. </view>
  18. <view class="list">
  19. <text>参加活动成员:</text>
  20. <text>{{details.teacherGrades}}</text>
  21. </view>
  22. </view>
  23. <!-- 活动通知结束 -->
  24. <!-- 心得体会开始 -->
  25. <view class="activity_experience" v-if="stateFlag == 1">
  26. <view class="textarea">
  27. <textarea placeholder-style="color:#999999" placeholder="请填写心得体会" v-model="submitFrom.experience" />
  28. </view>
  29. <view class="file">
  30. <uni-file-picker file-mediatype="all" @select="select" @delete='del' v-model="showDetalistFile">
  31. <view class="text_img">
  32. <image src="@/static/images/upload.png" mode=""></image>
  33. <text>添加附件</text>
  34. </view>
  35. </uni-file-picker>
  36. </view>
  37. </view>
  38. <!-- 心得体会结束 -->
  39. <!-- 按钮开始 -->
  40. <view class="btn" v-if="stateFlag == null">
  41. <button type="primary" @click="join_activities">参加活动</button>
  42. <button type="default" @click="go_back">返回</button>
  43. </view>
  44. <view class="btn" v-if="stateFlag == 0">
  45. <button type="primary" @click="sign_in">签到</button>
  46. </view>
  47. <view class="btn" v-if="stateFlag == 1">
  48. <button type="default">签到成功</button>
  49. <button type="primary" @click="submit">提交</button>
  50. </view>
  51. <!-- 按钮结束 -->
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
  57. import {
  58. courseActivityTeacherDetail,
  59. courseActivityTeacherAdd,
  60. courseActivityTeacheraddExperience,
  61. courseActivityTeacheractivityCode
  62. } from "@/api/course_activity.js"
  63. import upload from "@/api/upload.js"
  64. export default {
  65. data() {
  66. return {
  67. details: null, //详情
  68. stateFlag: null, //状态
  69. code: null,
  70. dataFrom: {
  71. activityCode: null //活动code
  72. },
  73. submitFrom: {
  74. activityCode: null, //activityCode
  75. experience: null, //心得体会
  76. coursewares: null //上传文档
  77. },
  78. fileUrl: [],
  79. dataDetails: {},
  80. detalistFile: [],
  81. showDetalistFile: []
  82. }
  83. },
  84. onLoad(option) {
  85. this.details = JSON.parse(decodeURIComponent(option.item))
  86. this.code = this.details.code
  87. this.dataFrom.activityCode = this.details.code
  88. this.submitFrom.activityCode = this.details.code
  89. },
  90. async mounted() {
  91. await this.get_details()
  92. },
  93. components: {
  94. uniFilePicker
  95. },
  96. methods: {
  97. get_details() { //获取详情数据
  98. courseActivityTeacherDetail(this.code).then(res => {
  99. if (res.data.courseActivityTeacher) {
  100. this.dataDetails = res.data.courseActivityTeacher
  101. this.submitFrom.experience = this.dataDetails.experience
  102. }
  103. if (res.data.fileinfos) {
  104. this.detalistFile = res.data.fileinfos
  105. for (var i = 0; i < this.detalistFile.length; i++) {
  106. var mydata = {
  107. "name": this.detalistFile[i].fileOriginName,
  108. "extname": this.detalistFile[i].fileSuffix,
  109. "url": this.detalistFile[i].fileId,
  110. "fileId": this.detalistFile[i].fileId,
  111. }
  112. this.showDetalistFile.push(mydata);
  113. }
  114. }
  115. if (res.data.courseActivityTeacher) {
  116. this.stateFlag = res.data.courseActivityTeacher.statusFlag
  117. } else {
  118. this.stateFlag = null
  119. }
  120. })
  121. },
  122. join_activities() { //点击参加活动
  123. courseActivityTeacherAdd(this.dataFrom).then(res => {
  124. this.get_details()
  125. })
  126. },
  127. go_back() { //点击返回
  128. uni.navigateTo({
  129. url: "/pages/course_activity/course_activity_manager/activity-list"
  130. })
  131. },
  132. sign_in() { //点击签到
  133. courseActivityTeacheractivityCode(this.dataFrom).then(res => {
  134. this.get_details()
  135. })
  136. },
  137. submit() { //点击提交
  138. if (this.submitFrom.experience == null) {
  139. uni.showToast({
  140. icon: 'none',
  141. title: '请填写心得体会',
  142. duration: 2000
  143. })
  144. } else {
  145. var coursewares = [];
  146. for (var i = 0; i < this.detalistFile.length; i++) {
  147. coursewares.push(this.detalistFile[i].fileId)
  148. }
  149. this.submitFrom.coursewares = coursewares.join(',');
  150. courseActivityTeacheraddExperience(this.submitFrom).then(res => {
  151. if (res.code == "00000") {
  152. this.submitFrom = null
  153. uni.redirectTo({
  154. url: "/pages/course_activity/course_activity_manager/activity-list"
  155. })
  156. uni.showToast({
  157. title: '提交成功',
  158. duration: 2000
  159. })
  160. }
  161. })
  162. }
  163. },
  164. select(e) {
  165. let that = this
  166. uni.showLoading({
  167. title: "上传中"
  168. });
  169. const tempFilePaths = e.tempFilePaths;
  170. for (var i = 0; i < tempFilePaths.length; i++) {
  171. const tempFile = e.tempFiles[i];
  172. uni.uploadFile({
  173. url: upload,
  174. header: {
  175. 'Authorization': uni.getStorageSync('Admin-Token')
  176. },
  177. filePath: tempFilePaths[i],
  178. name: 'file',
  179. success: (uploadFileRes) => {
  180. uni.hideLoading();
  181. const back = JSON.parse(uploadFileRes.data);
  182. if (uploadFileRes.statusCode == 200) {
  183. that.$set(back.data, "uuid", tempFile.uuid)
  184. that.$set(back.data, "path", tempFile.path)
  185. that.$set(back.data, "url", tempFile.url)
  186. that.detalistFile.push(back.data);
  187. }
  188. },
  189. fail: () => {
  190. uni.hideLoading();
  191. uni.showToast("上传失败,请联系开发!")
  192. },
  193. complete: function() {
  194. uni.hideLoading();
  195. }
  196. });
  197. }
  198. },
  199. del(e) { //删除
  200. this.detalistFile.map((item, index) => {
  201. if (e.tempFile.uuid) {
  202. if (item.uuid == e.tempFile.uuid) {
  203. this.detalistFile.splice(index, 1)
  204. }
  205. } else {
  206. if (item.url == e.tempFile.fileId || item.fileId == e.tempFile.fileId) {
  207. this.detalistFile.splice(index, 1)
  208. }
  209. }
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .content {
  217. .wrap {
  218. width: 95%;
  219. margin: 0 auto;
  220. }
  221. .activity_inform {
  222. .list {
  223. margin-top: 24rpx;
  224. background-color: #F5F5F5;
  225. padding: 20rpx;
  226. border-radius: 8rpx;
  227. box-sizing: border-box;
  228. display: flex;
  229. align-items: center;
  230. &:nth-child(2) {
  231. display: block;
  232. text:last-child {
  233. display: block;
  234. padding-top: 10rpx;
  235. }
  236. }
  237. text {
  238. color: #333333;
  239. &:last-child {
  240. color: #999999;
  241. flex: 3;
  242. }
  243. }
  244. }
  245. }
  246. .activity_experience {
  247. .textarea {
  248. padding-top: 24rpx;
  249. }
  250. .file {
  251. padding-top: 24rpx;
  252. text {
  253. display: block;
  254. }
  255. .text_img {
  256. display: flex;
  257. align-items: center;
  258. image {
  259. width: 40rpx;
  260. height: 40rpx;
  261. padding-right: 10rpx;
  262. }
  263. }
  264. }
  265. }
  266. .btn {
  267. padding-top: 24rpx;
  268. }
  269. }
  270. </style>

手写图片上传

  1. <template>
  2. <view class="center">
  3. <!-- 上传图片 -->
  4. <view class="uploadcontainer">
  5. <view class="uploadBox" v-for="(item, i) in imgList" :key="i.id">
  6. <view class="uploadCenter">
  7. <image :src="item.url" width='aspectFill' @click="viewImage(i)">
  8. </image>
  9. <uni-icons color='#fff' type="closeempty" class="closeClass" size="20" @click="delImg(i)">
  10. </uni-icons>
  11. </view>
  12. </view>
  13. <view class="uploadAdd" @tap="upload" v-if="imgList.length < 9">
  14. <view class="uploadAddImg">
  15. <image src="../../static/imgAdd.png" mode="aspectFill"></image>
  16. </view>
  17. </view>
  18. </view>
  19. <button type="default" @click="submit" :disabled="cannotFlag">提交</button>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. imgList: [],
  27. imgUrl: '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=',
  28. urlConfig: "http://192.168.10.109:8080",
  29. cannotFlag: false
  30. }
  31. },
  32. methods: {
  33. submit() {
  34. var arrList = []
  35. arrList = (this.imgList.map(item => item.id)).join(',')
  36. console.log(arrList)
  37. },
  38. upload() {
  39. var that = this;
  40. uni.chooseImage({
  41. count: 10,
  42. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  43. sourceType: ['album', 'camera'], //从相册、相机选择
  44. success: function(res) {
  45. that.cannotFlag = true
  46. var countupload = 0;
  47. for (var i = 0; i < res.tempFiles.length; i++) {
  48. if (res.tempFiles[i].size / 1024 / 1024 > 5) {
  49. uni.showToast({
  50. icon: 'none',
  51. title: '图片过大,请重新上传',
  52. duration: 3000
  53. })
  54. return
  55. }
  56. var imageType = res.tempFiles[i].type == "image/jpeg" || res.tempFiles[i].type ==
  57. "image/jpg" || res.tempFiles[i].type == "image/png" || res.tempFiles[i].type ==
  58. "image/gif"
  59. if (!imageType) {
  60. uni.showToast({
  61. icon: 'none',
  62. title: '图片类型不正确,请重新上传',
  63. duration: 3000
  64. })
  65. return
  66. }
  67. if (res.tempFiles.length > 9) {
  68. uni.showToast({
  69. icon: 'none',
  70. title: '一次最多只能添加9张图片',
  71. duration: 3000
  72. })
  73. that.cannotFlag = false;
  74. return
  75. }
  76. if (that.imgList.length + res.tempFiles.length > 10) {
  77. uni.showToast({
  78. icon: 'none',
  79. title: '最多只能上传10张',
  80. duration: 3000
  81. })
  82. that.cannotFlag = false;
  83. return
  84. }
  85. const tempFilePaths = res.tempFiles[i].path;
  86. // 图片传
  87. uni.showLoading({
  88. title: "上传中"
  89. });
  90. const uploadTask = uni.uploadFile({
  91. url: 'http://192.168.10.109:8080/sysFileInfo/upload?secretFlag=N', // post请求地址
  92. filePath: tempFilePaths,
  93. name: 'file', // 待确认
  94. header: {
  95. 'Authorization': 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjE1NTQwMzAxMjU2MTEzMjMzOTQsImFjY291bnQiOiJ6Y3dsIiwidXVpZCI6ImY1NDRkYTBjLWE2ZmEtNGJmMy1hNjAzLTY0M2JmNTAwZWZlNCIsInJlbWVtYmVyTWUiOmZhbHNlLCJleHBpcmF0aW9uRGF0ZSI6MTY2MjAwMTg2NDA4MiwiY2FUb2tlbiI6ImVlNzY1Yzk5NGM0NzZhNjYxODlkNzNkODJjYjQyNTNiIiwib3RoZXJzIjpudWxsLCJzdWIiOiIxNTU0MDMwMTI1NjExMzIzMzk0IiwiaWF0IjoxNjYxMzk3MDY0LCJleHAiOjE2NjIwMDE4NjR9.lIgZSZeuMZBiCZcgnJ-CfEdWHsXUo9v3997ZNU-lzR6YHhjnYgry8E-dK0zt-qAaGL3w6khA_9-033wKqMe8Xw'
  96. },
  97. success: function(uploadFileRes) {
  98. var arrList = []
  99. arrList.push(JSON.parse(uploadFileRes.data).data);
  100. arrList.forEach(item => {
  101. that.imgList.push({
  102. url: `${that.urlConfig}${that.imgUrl}${item.fileObjectName}`,
  103. id: item.fileObjectName
  104. })
  105. })
  106. uni.hideLoading();
  107. },
  108. fail: function(uploadFileFail) {
  109. uni.hideLoading();
  110. },
  111. complete: (e) => {
  112. countupload++;
  113. if (countupload == res.tempFiles.length) {
  114. that.cannotFlag = false;
  115. }
  116. uni.hideLoading();
  117. }
  118. });
  119. }
  120. },
  121. error: function(e) {
  122. console.log(e);
  123. }
  124. });
  125. },
  126. delImg(i) {
  127. this.imgList.splice(i, 1);
  128. },
  129. viewImage(i) {
  130. var arrList = []
  131. arrList = this.imgList.map(item => item.url)
  132. uni.previewImage({
  133. current: i,
  134. urls: arrList
  135. });
  136. }
  137. }
  138. }
  139. </script>
  140. <style>
  141. .center {
  142. margin: 20rpx;
  143. }
  144. .uploadcontainer {
  145. display: flex;
  146. box-sizing: border-box;
  147. flex-wrap: wrap;
  148. margin: -10rpx
  149. }
  150. .uploadBox {
  151. width: 33.3%;
  152. padding-top: 33.33%;
  153. height: 0%;
  154. position: relative;
  155. }
  156. .uploadAdd {
  157. width: 33.3%;
  158. padding-top: 33.3%;
  159. height: 0%;
  160. position: relative;
  161. }
  162. .closeClass {
  163. position: absolute;
  164. top: 3px;
  165. right: 3px;
  166. height: 26px;
  167. line-height: 26px;
  168. width: 26px;
  169. border-radius: 50%;
  170. background-color: rgba(0, 0, 0, 0.5);
  171. }
  172. .uploadCenter {
  173. position: absolute;
  174. top: 0;
  175. right: 0;
  176. bottom: 0;
  177. left: 0;
  178. margin: 5px;
  179. border: 1px #eee solid;
  180. border-radius: 5px;
  181. overflow: hidden;
  182. }
  183. .uploadCenter image {
  184. width: 100%;
  185. height: 100%;
  186. }
  187. .uploadAddImg {
  188. position: absolute;
  189. top: 0;
  190. right: 0;
  191. bottom: 0;
  192. left: 0;
  193. margin: 5px;
  194. border: 1px #ccc solid;
  195. border-radius: 5px;
  196. overflow: hidden;
  197. }
  198. .uploadAddImg image {
  199. width: 100%;
  200. height: 100%;
  201. padding: 25px;
  202. box-sizing: border-box;
  203. }
  204. </style>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/183470?site
推荐阅读
相关标签
  

闽ICP备14008679号