使用工具:

1.微信Web开发者工具

2.Visual Studio 2019

前端采用color UI,后端采用c# .net

过程中的几个重点点记录

1.color UI使用

下载colorUI以后

将icon.wxss、colorui.wxss拷贝至项目根目录

在app.wxss中导入文件

@import "icon.wxss";
@import "colorui.wxss";
 
2.图片上传功能

wxml前端代码
  1. <view class="cu-form-group">
  2. <view class="picture_list">
  3. <view wx:for="{{upload_picture_list}}" class="picture_item" wx:key="{{index}}">
  4. <image wx:if="{{item.upload_percent < 100}}" src="{{item.path}}" mode="aspectFill"></image>
  5. <image wx:if="{{item.upload_percent == 100}}" src="{{item.path_server}}" mode="aspectFill"></image>
  6. <view class="upload_progress" wx:if="{{item.upload_percent < 100}}" data-index="{{index}}" bindtap="previewImg">{{item.upload_percent}}%</view>
  7. <text class='del' bindtap='deleteImg' data-src='{{image}}' style='display:{{isDel}}' data-index="{{index}}">×</text>
  8. </view>
  9.  
  10. <view class='picture_item'>
  11. <view class="add-image" bindtap='uploadpic'>
  12. <text>+</text>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="cu-form-group">
  18. <button bindtap='uploadimage' class='yes-upload'>上传图片</button>
  19. </view>

js代码

  1. //选择图片方法
  2. uploadpic: function (e) {
  3. let that = this //获取上下文
  4. let upload_picture_list = that.data.upload_picture_list
  5. //选择图片
  6. wx.chooseImage({
  7. count: 8, // 默认9,这里显示一次选择相册的图片数量
  8. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  9. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  10. success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  11. let tempFiles = res.tempFiles
  12. //把选择的图片 添加到集合里
  13. //console.log(tempFiles);
  14. for (let i in tempFiles) {
  15. tempFiles[i]['upload_percent'] = 0
  16. tempFiles[i]['path_server'] = ''
  17. upload_picture_list.push(tempFiles[i])
  18. }
  19. //显示
  20. that.setData({
  21. upload_picture_list: upload_picture_list,
  22. });
  23. }
  24. })
  25. },
  26. //点击上传图片
  27. uploadimage() {
  28. let page = this
  29. let upload_picture_list = page.data.upload_picture_list
  30. //循环把图片上传到服务器 并显示进度
  31. for (let j in upload_picture_list) {
  32. if (upload_picture_list[j]['upload_percent'] == 0) {
  33. //console.log("进入上传if");
  34. //上传图片后端地址
  35. //upload_file_server('https://www.x..fds.af..a.fd.sa', page, upload_picture_list, j)
  36. //console.log(this.data.problemAttach);
  37. wx.uploadFile({
  38. url: this.data.domain+'api/FirstAPI/uploadPicture?problemAttach=' + this.data.problemAttach, //上传的接口地址
  39. filePath: upload_picture_list[j].path,
  40. name: 'file',
  41. formData: {
  42. problemAttach: this.data.problemAttach,
  43. },
  44. success: function (res) {
  45. console.log(res);
  46. upload_picture_list[j]['upload_percent'] = 100
  47. upload_picture_list[j]['path_server'] = '接口地址' + JSON.parse(res.data).data;
  48. page.setData({
  49. upload_picture_list: upload_picture_list,
  50. problemAttach: JSON.parse(res.data).msg
  51. });
  52. }
  53. })
  54. }
  55. }
  56. let imgs = wx.setStorageSync('imgs', upload_picture_list);
  57. },
  58. // 点击删除图片
  59. deleteImg(e) {
  60. let upload_picture_list = this.data.upload_picture_list;
  61. let index = e.currentTarget.dataset.index;
  62. if (upload_picture_list[index].upload_percent == 100) {
  63. //去服务器把对应的记录del
  64. this.data.delIndex = index;
  65. this.ajaxfunc(1);
  66. }
  67. upload_picture_list.splice(index, 1);
  68. this.setData({
  69. upload_picture_list: upload_picture_list
  70. });
  71. },
  72. // 预览图片
  73. previewImg(e) {
  74. //获取当前图片的下标
  75. let index = e.currentTarget.dataset.index;
  76. //所有图片
  77. let imgs = this.data.imgs;
  78. wx.previewImage({
  79. //当前显示图片
  80. current: imgs[index],
  81. //所有图片
  82. urls: imgs
  83. })
  84. },

c#后端api接口

  1. public IHttpActionResult uploadPicture(string problemAttach)
  2. {
  3. string mesg = problemAttach;
  4. if (problemAttach==null||problemAttach==""||problemAttach=="undefined" || problemAttach == "null")
  5. {
  6. problemAttach = CommonHelper.GetGuid;
  7. mesg = problemAttach;
  8. }
  9. Repository<MK_Base_AnnexesFile> re = new Repository<MK_Base_AnnexesFile>();
  10.  
  11. HttpFileCollection files = HttpContext.Current.Request.Files;
  12. List<string> serversrc = new List<string>();
  13. foreach (string key in files.AllKeys)
  14. {
  15. MK_Base_AnnexesFile fileAnnexesEntity = new MK_Base_AnnexesFile();
  16. HttpPostedFile file = files[key];//file.ContentLength文件长度
  17. string src = HttpContext.Current.Server.MapPath("~/imgcoll/") + file.FileName;
  18. src=src.Replace("\\","/");
  19. if (string.IsNullOrEmpty(file.FileName) == false)
  20. {
  21. file.SaveAs(src);
  22. serversrc.Add("/imgcoll/"+file.FileName);
  23. }
  24. //str = str.Substring(0, str.LastIndexOf("/"));
  25. fileAnnexesEntity.F_Id = file.FileName.Substring(, file.FileName.LastIndexOf("."));
  26. fileAnnexesEntity.F_FileName = file.FileName;
  27. fileAnnexesEntity.F_FilePath = src;
  28. fileAnnexesEntity.F_FileSize = "未知";
  29. fileAnnexesEntity.F_FileExtensions = file.FileName.Substring(file.FileName.LastIndexOf("."));
  30. fileAnnexesEntity.F_FileType = file.FileName.Substring(file.FileName.LastIndexOf(".")+);
  31. fileAnnexesEntity.F_CreateUserId = "微信端上传";
  32. fileAnnexesEntity.F_CreateUserName = "微信端上传";
  33. fileAnnexesEntity.F_FolderId = problemAttach;
  34. re.Insert(fileAnnexesEntity);
  35.  
  36. }
  37.  
  38. return JsonData(true, serversrc[], mesg);
  39. }

记一次微信小程序的开发的更多相关文章

  1. 小程序语音红包开发中 汉字转拼音的问题 微信小程序红包开发遇到的坑

    公司最近在开发微信小程序的红包功能,语音红包需要用到文字转拼音的功能. 之前介绍过怎么将中文的汉字转为拼音的,具体看下面这篇文章. 微信语音红包小程序开发如何提高精准度 红包小程序语音识别精准度 微信 ...

  2. 微信小程序如何开发制作

    微信小程序如何开发制作 微容SMO是一款微信小程序的免费在线制作工具,用户在微容平台上无需编辑代码,可通过拖拽式操作即可完成小程序的制作,真正意义上实现了小程序零代码免费制作! 消除技术门槛:无需代码 ...

  3. 【推荐】开源项目minapp-重新定义微信小程序的开发

    minapp 重新定义微信小程序的开发 官网:https://qiu8310.github.io/minapp/ 作者:Mora minapp 重新定义微信小程序的开发 使用 用 npm 安装命令行工 ...

  4. 微信小程序快速开发上手

    微信小程序快速开发上手 介绍: 从实战开发角度,完整系统地介绍了小程序的开发环境.小程序的结构.小程序的组件与小程序的API,并提供了多个开发实例帮助读者快速掌握小程序的开发技能,并能自己动手开发出小 ...

  5. 微信小程序wepy开发循环wx:for需要注意

    微信小程序wepy开发循环wx:for需要注意 item index值必须在wx:for之后使用 <view wx:for="{{tablist}}" class=" ...

  6. Mac上微信小程序官方开发工具卡死的问题

    Mac上微信小程序官方开发工具打开后卡死,无法操作,也关不掉,解决方案: 三步: 1.在应用中删除“微信web开发者工具” 2.删除一下几个配置和缓存文件: 1.-/Library/Applicati ...

  7. 技本功丨收藏!斜杠青年与你共探微信小程序云开发(下篇)

    2019年2月26日,人们为了一个杯子疯了一天. 星巴克猫爪杯,一场已经与猫无关了的“圣杯战争“.网上的倒卖价格,已炒至近千元! 求而不得,舍而不能,得而不惜.这是人最大的悲哀... 所以,请珍惜以下 ...

  8. 微信小程序-云开发(手记)

    微信小程序-云开发(手记) 1.创建data.json文件 注意以下几点要求: 入门示例: init方法的env:默认环境配置,传入字符串形式的环境 ID(理解为数据库)可以指定所有服务的默认环境(意 ...

  9. 微信小程序快速开发

    微信小程序快速开发 一.注册小程序账号,下载IDE 1.官网注册https://mp.weixin.qq.com/,并下载IDE. 2.官方文档一向都是最好的学习资料. 注意:1)注册账号之后会有一个 ...

随机推荐

  1. 如何快速将百度大脑AI技术内置智能小程序中

    实现效果: 该AI智能小程序目前集成了百度AI开放平台数十个AI服务产品功能,包括人脸识别.文字识别.表格识别.红酒识别.货币识别.地标识别.手势识别.商标识别.果蔬识别.菜品识别等图片识别功能,以及 ...

  2. Linux7 64安装 oracle 11g Error in invoking target 'agent nmhs' of makefile

    在makefile中添加链接libnnz11库的参数修改$ORACLE_HOME/sysman/lib/ins_emagent.mk,将$(MK_EMAGENT_NMECTL)修改为:$(MK_EMA ...

  3. weed3-2.1.开始纯java使用

    Weed3 一个微型ORM框架(只有0.1Mb哦) 源码:https://github.com/noear/weed3 源码:https://gitee.com/noear/weed3 纯java使用 ...

  4. springboot传值踩坑

    由于我现在写的项目都是前后端分离的,前端用的是vue,后端springboot,于是前后端传值的问题就是一个比较重要的问题,为此我还特意去学了一下vue的传值,其实就是用一个axios组件,其实就是基 ...

  5. JDK环境变量配置遇见的错误以及解决办法

    cmd中输入java -version错误信息: An error has occurred while processing the shared archive file.Unable to un ...

  6. SpringCloud之Zuul:服务网关

    Zuul在Web项目中的使用见上文<SpringBoot中使用Zuul>,下面例子为Zuul在Spring Cloud的使用. 开发工具:IntelliJ IDEA 2019.2.3 一. ...

  7. windows下安装mysql教程

    1.下载安装包-根据自己电脑系统选择合适的版本: https://dev.mysql.com/downloads/mysql/ 2.配置环境变量 2.1 解压所下载的压缩包 2.2 环境变量 win ...

  8. Abp zero 登录 添加腾讯云验证码

    腾讯云验证码是为网页.App.小程序开发者提供的安全验证服务,基于腾讯多年的大数据积累和人工智能决策引擎,构建智能分级验证模型,最大程度保护业务安全的同时,提供更精细化的用户体验. 腾讯云--> ...

  9. 分享一个酷炫动态登录页面html

    话不多说,如下图: 代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <H ...

  10. sqlplus命令窗口执行sql脚本文件

    SQL>@file_name 例如 SQL>@monitor.sql      文件须得在当前窗口所在的目录下或者指定某个路径. SQL>@D:\monitor.sql 转载示例-- ...