記一次微信小程式的開發

来源:https://www.cnblogs.com/lovejunjuan/archive/2019/07/18/11204961.html
-Advertisement-
Play Games

使用工具: 1.微信Web開發者工具 2.Visual Studio 2019 前端採用color UI,後端採用c# .net 過程中的幾個重點點記錄 1.color UI使用 下載colorUI以後 將icon.wxss、colorui.wxss拷貝至項目根目錄 在app.wxss中導入文件 @ ...


使用工具:

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前端代碼
<view class="cu-form-group">
  <view class="picture_list">
  <view wx:for="{{upload_picture_list}}" class="picture_item" wx:key="{{index}}">
    <image wx:if="{{item.upload_percent < 100}}" src="{{item.path}}" mode="aspectFill"></image>
    <image wx:if="{{item.upload_percent == 100}}" src="{{item.path_server}}" mode="aspectFill"></image>
    <view class="upload_progress" wx:if="{{item.upload_percent < 100}}" data-index="{{index}}" bindtap="previewImg">{{item.upload_percent}}%</view>
    <text class='del' bindtap='deleteImg' data-src='{{image}}' style='display:{{isDel}}' data-index="{{index}}">×</text>
  </view>

  <view class='picture_item'>
    <view class="add-image" bindtap='uploadpic'>
      <text>+</text>
    </view>
  </view>
</view>
</view>
<view class="cu-form-group">
<button bindtap='uploadimage' class='yes-upload'>上傳圖片</button>
</view>

 js代碼

  //選擇圖片方法
  uploadpic: function (e) {
    let that = this //獲取上下文
    let upload_picture_list = that.data.upload_picture_list
    //選擇圖片
    wx.chooseImage({
      count: 8, // 預設9,這裡顯示一次選擇相冊的圖片數量 
      sizeType: ['compressed'], // 可以指定是原圖還是壓縮圖,預設二者都有  
      sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,預設二者都有
      success: function (res) { // 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標簽的src屬性顯示圖片 
        let tempFiles = res.tempFiles
        //把選擇的圖片 添加到集合里
        //console.log(tempFiles);
        for (let i in tempFiles) {
          tempFiles[i]['upload_percent'] = 0
          tempFiles[i]['path_server'] = ''
          upload_picture_list.push(tempFiles[i])
        }
        //顯示
        that.setData({
          upload_picture_list: upload_picture_list,
        });
      }
    })
  },
  //點擊上傳圖片
  uploadimage() {
    let page = this
    let upload_picture_list = page.data.upload_picture_list
    //迴圈把圖片上傳到伺服器 並顯示進度       
    for (let j in upload_picture_list) {
      if (upload_picture_list[j]['upload_percent'] == 0) {
        //console.log("進入上傳if");
        //上傳圖片後端地址
        //upload_file_server('https://www.x..fds.af..a.fd.sa', page, upload_picture_list, j)
        //console.log(this.data.problemAttach);
        wx.uploadFile({
          url: this.data.domain+'api/FirstAPI/uploadPicture?problemAttach=' + this.data.problemAttach, //上傳的介面地址 
          filePath: upload_picture_list[j].path,
          name: 'file',
          formData: {
            problemAttach: this.data.problemAttach,
          },
          success: function (res) {
            console.log(res);
            upload_picture_list[j]['upload_percent'] = 100
            upload_picture_list[j]['path_server'] = '介面地址' + JSON.parse(res.data).data;
            page.setData({
                upload_picture_list: upload_picture_list,
                problemAttach: JSON.parse(res.data).msg 
            });
          }
        })
      }
    }
    let imgs = wx.setStorageSync('imgs', upload_picture_list);
  },
  // 點擊刪除圖片
  deleteImg(e) {
    let upload_picture_list = this.data.upload_picture_list;
    let index = e.currentTarget.dataset.index;
    if (upload_picture_list[index].upload_percent == 100) {
      //去伺服器把對應的記錄del
      this.data.delIndex = index;
      this.ajaxfunc(1);
    }
    upload_picture_list.splice(index, 1);
    this.setData({
      upload_picture_list: upload_picture_list
    });
  },
  // 預覽圖片
  previewImg(e) {
    //獲取當前圖片的下標
    let index = e.currentTarget.dataset.index;
    //所有圖片
    let imgs = this.data.imgs;
    wx.previewImage({
      //當前顯示圖片
      current: imgs[index],
      //所有圖片
      urls: imgs
    })
  },

c#後端api介面

public IHttpActionResult uploadPicture(string problemAttach)
        {
            string mesg = problemAttach;
            if (problemAttach==null||problemAttach==""||problemAttach=="undefined" || problemAttach == "null")
            {
                problemAttach = CommonHelper.GetGuid;
                mesg = problemAttach;
            }
            Repository<MK_Base_AnnexesFile> re = new Repository<MK_Base_AnnexesFile>();
            
            HttpFileCollection files = HttpContext.Current.Request.Files;
            List<string> serversrc = new List<string>();
            foreach (string key in files.AllKeys)
            {
                MK_Base_AnnexesFile fileAnnexesEntity = new MK_Base_AnnexesFile();
                HttpPostedFile file = files[key];//file.ContentLength文件長度
                string src = HttpContext.Current.Server.MapPath("~/imgcoll/") + file.FileName;
                src=src.Replace("\\","/");
                if (string.IsNullOrEmpty(file.FileName) == false)
                {
                    file.SaveAs(src);
                    serversrc.Add("/imgcoll/"+file.FileName);
                }
                //str = str.Substring(0, str.LastIndexOf("/"));
                fileAnnexesEntity.F_Id = file.FileName.Substring(0, file.FileName.LastIndexOf(".")); 
                fileAnnexesEntity.F_FileName = file.FileName;
                fileAnnexesEntity.F_FilePath = src;
                fileAnnexesEntity.F_FileSize = "未知";
                fileAnnexesEntity.F_FileExtensions = file.FileName.Substring(file.FileName.LastIndexOf("."));
                fileAnnexesEntity.F_FileType = file.FileName.Substring(file.FileName.LastIndexOf(".")+1);
                fileAnnexesEntity.F_CreateUserId = "微信端上傳";
                fileAnnexesEntity.F_CreateUserName = "微信端上傳";
                fileAnnexesEntity.F_FolderId = problemAttach;
                re.Insert(fileAnnexesEntity);


            }

            return JsonData(true, serversrc[0], mesg);
        }

 

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 初識事務隔離 事務隔離級別的出現都是針對資料庫的具體問題的, SQL 92標準對事務併發處理會存在的異常情況進行了分級, 分別為臟讀(Dirty Read)、不可重覆讀(Unrepeatable Read)和幻讀(Phantom Read). 三種異常 舉個例子, 有個heros_temp表, 中有 ...
  • 一、基於詞項與全文的搜索 1、詞項 Term(詞項)是表達語意的最小單位,搜索和利用統計語言模型進行自然語言處理都需要處理Term。 Term的使用說明: 1)Term Level Query:Term Query、Range Query、Exists Query、Prefix Query、Wild ...
  • 轉自:https://blog.csdn.net/weixin_33979203/article/details/87621768 改進,再找不到key,返回''值,之前的是在找不到的情況下,查找到第一的值。 ...
  • 在使用eclipse連接mysql資料庫時報異常: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLE ...
  • Dart作為高級語言,支持面向對象的很多特性,並且支持基於mixin的繼承方式,基於mixin的繼承方式是指:一個類可以繼承自多個父類,相當於其他語言里的多繼承。所有的類都有同一個基類Object,這和特性類似於Java語言,Java所有的類也都是繼承自Object,也就是說一切皆對象。 ...
  • 剛招來個Android,幹了半個月辭職了,他走之後,成堆的bug被測了出來,都是這個新人代碼都沒看懂就開始改的一塌糊塗,還給提交了。實在是讓人頭疼,清理了一個月多月才把他半個月寫的bug清理個差不多。實在是得不償失。有了這個前車之鑒,不得不重視新人的崗前培訓,畢竟面試找個來了就能上手的實在是太難了。 ...
  • 1. 出現錯誤提示:Intel HAXM is required to run this AVD,VT-x is disabled in BIOS的解決辦法。 點擊SDK圖標,安裝Intel x86 Emulator Accelerator (HAXM installer)。 在sdk路徑下,找到e ...
  • 拿到題目, 首先要先瞭解鏈表數據結構, 如下圖: 常規思路: 利用數組, 遍歷整個單鏈表, 將每個節點裝入數組中, 最終拿到數組根據索引(數組長度-1-n)就得到了倒數第n個元素. 簡單思路: 假設總長度為n, 倒數第k個對應正數第n-k-1, 那麼第一個指針移動k-1次, 第二個指針保持在head ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...