微信小程序开发上传流程

news/2024/7/20 1:56:26 标签: 微信小程序, 小程序, javascript

一、注册小程序appID

小程序>微信小程序开发工具中"新建项目",得到如下界面:

在"注册"环节得到AppID

二、开发一个简单的天气查询小程序

目录如下:

1、app.json

{
  "pages":[
    "pages/weather/weather"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "Weixin",
    "navigationBarTextStyle":"black"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json",
  "requiredPrivateInfos": ["getLocation", "chooseLocation"],
  "lazyCodeLoading": "requiredComponents"
}

 2、weather.js

javascript">// pages/weather/weather.ts
import {formatTime} from "../../utils/util"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    today: '20230314',
    city: '杭州',
    inputCity: '',
    wendu: 22,
    weather_pic: 'https://img.jumdata.com/weather-icon/d00.png',
    forecast:[
      {
        daytime: '0314',
        day_weather: '晴',
        day_high_temperature: '23',
        night_low_temperature: '9',
        day_wind_direction: '南风',
        day_wind_power: '3-4级'
      },{
        daytime: '0315',
        day_weather: '阴',
        day_high_temperature: '25',
        night_low_temperature: '10',
        day_wind_direction: '北风',
        day_wind_power: '3-4级'
      },{
        daytime: '0316',
        day_weather: '阴',
        day_high_temperature: '25',
        night_low_temperature: '10',
        day_wind_direction: '北风',
        day_wind_power: '3-4级'
      },{
        daytime: '0317',
        day_weather: '阴',
        day_high_temperature: '25',
        night_low_temperature: '10',
        day_wind_direction: '北风',
        day_wind_power: '3-4级'
      },{
        daytime: '0318',
        day_weather: '阴',
        day_high_temperature: '25',
        night_low_temperature: '10',
        day_wind_direction: '北风',
        day_wind_power: '3-4级'
      }   
    ],
  },

  inputing: function(e){
    this.setData({
      inputCity: e.detail.value
    })
  },

  bindSearch: function(e){
    this.searchWeather(this.data.inputCity);
  },

  searchWeather: function(e){
    var self = this;
    wx.request({
      url: 'https://weatherquery.api.bdymkt.com/weather/query/by-area?area=' + self.data.inputCity,
      method: 'POST',
      data: {},
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
        'X-Bce-Signature': 'AppCode/<自己的appcode> '
      },
      success: function(res){
        console.info(res);

        var weathers = res.data.data.dayWeathers.slice(1, -1);
        for(var i=0; i < 5; i++){
          var d = weathers[i].daytime;
          weathers[i].daytime = d.slice(-4);
        }

        self.setData({
          wendu: res.data.data.now.temperature,
          city: self.data.inputCity,
          weather_pic: res.data.data.now.weather_pic,
          forecast: weathers,
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    var self = this;
    var today_time = formatTime(new Date());
    this.setData({
      today: today_time
    });

    wx.request({
      url: 'https://weatherquery.api.bdymkt.com/weather/query/by-area?area=杭州',
      method: 'POST',
      data: {},
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
        'X-Bce-Signature': 'AppCode/<自己的appcode> '
      },
      success: function(res){
        var weathers = res.data.data.dayWeathers.slice(1, -1);
        for(var i=0; i < 5; i++){
          var d = weathers[i].daytime;
          weathers[i].daytime = d.slice(-4);
        }

        self.setData({
          wendu: res.data.data.now.temperature,
          weather_pic: res.data.data.now.weather_pic,
          forecast: weathers,
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

 3、weather.wxml

<view class="content">
  <!--显示当天的天气信息-->
  <view class="info">
    <!--城市名称,当前日期-->
    <view class="city">{{city}}({{today}})</view>
    <!--当天温度-->
    <view class="temp">{{wendu}}度</view>
    <!--当天天气图片-->
    <view style="text-align: center;">
      <image class="today-pic" src="{{weather_pic}}"/>
    </view>
  </view>

  <!--最近7天天气信息-->
  <view class="forecast">
    <view class="next-day" wx:key="{{index}}" wx:for="{{forecast}}">
      <!--日期-->
      <view class="detail date">{{item.daytime}}</view>
      <!--天气类型-->
      <view class="detail">{{item.day_weather}}</view>
      <!--最高温度-->
      <view class="detail" style="font-size: 10px;">最高{{item.day_high_temperature}}度</view>
      <!--最低温度-->
      <view class="detail" style="font-size: 10px;">最低{{item.night_low_temperature}}度</view>
      <!--风向-->
      <view class="detail" style="font-size: 10px;">{{item.day_wind_direction}}</view>
      <!--风力-->
      <view class="detail">{{item.day_wind_power}}</view>
    </view>
  </view>

  <!--搜索-->
  <view class="search-area">
    <input bindinput="inputing" placeholder="请输入城市名称" value="{{inputCity}}" />
    <button type="primary" size="mini" bindtap="bindSearch">查询</button>
  </view>
</view>

4、weather.wxss

/* pages/weather/weather.wxss */
.content{
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  font-family: 微软雅黑, 宋体;
  box-sizing: border-box;
  padding: 20rpx 10rpx;
  color: #252525;
  font-size: 16px;
  background-color: #F2F2F8;
}

.info{
  margin-top: 50rpx;
  width: 100%;
  height: 140px;
}

.today-pic{
  width: 100rpx;
  height: 100rpx;
  
}

.city{
  margin: 20rpx;
  border-bottom: 1px solid #043567;
}

.temp{
  font-size: 60rpx;
  line-height: 130rpx;
  text-align: center;
  padding-top: 20rpx;
  color: #043567;
}

.forecast{
  width: 100%;
  display: flex;
  margin-top: 50rpx;
  align-self: flex-end;
}

.next-day{
  width: 20%;
  height: 500rpx;
  text-align: center;
  line-height: 30px;
  font-size: 14px;
  margin: 0 3rpx;
  border:1px solid #043567;
  border-radius: 10rpx;
}

.date{
  margin-bottom: 20rpx;
  border-bottom: 1px solid #043567;
  color: #F29F39;
}

.search-area{
  display: flex;
  background: #f4f4f4;
  padding: 1rem 0.5rem;
}

.search-area input{
  width: 70%;
  height: 30px;
  line-height: 38px;
  border:1px solid #ccc;
  color: #000;
  background-color: #fff;
  border-radius: 5px;
}

.search-area button{
  width: 30%;
  height: 35px;
  line-height: 40px;
  margin-left: 5px;
}

三、上传代码

点击“上传”代码,确保没有问题。

 在小程序>微信小程序的“版本管理”中进行提交审核。

 “开发版本” -》 “审核版本” -》 “线上版本”。

如果小程序比较简单,2分钟即可审核完毕。

发布到线上之后,小程序并不能马上搜出来,官方解释为:

 


http://www.niftyadmin.cn/n/154102.html

相关文章

hadoop理论基础(一)

1.hadoop的组成2 HDFS概述HDFS&#xff08;Hadoop Distributed File System&#xff09;是一个分布式文件系统&#xff08;1&#xff09;NameNode:存储文件的元数据;如文件名、文件目录结构、文件属性&#xff0c;以及每个文件的块列表和块所在的DataNode等。(2)DataNode:在本地…

java基础:java中的static关键字解析

1.static代表着什么 在Java中并不存在全局变量的概念&#xff0c;但是我们可以通过static来实现一个“伪全局”的概念&#xff0c;在Java中static表示“全局”或者“静态”的意思&#xff0c;用来修饰成员变量和成员方法&#xff0c;当然也可以修饰代码块。 Java把内存分为栈内…

visual chatgpt:talking,drawing and editing with visual foundation models

微软-多模态ChatGPT来了&#xff1a;Visual ChatGPT: Talking, Drawing and Editing with Visual Foundation Models - 知乎摘要ChatGPT吸引了各个领域的兴趣&#xff0c;因其提供了一个跨领域的具有卓越会话能力和推理能力的语言界面。然而&#xff0c;由于ChatGPT是一个语言模…

高通与HIFI音频-PCBA

一&#xff0e;HIFI-PCBA总概述 RISCV-DSP芯片高通QCC3x/5x系列蓝牙&#xff0c;配套蓝牙协议APTX&#xff0c;APTX-HD&#xff0c;APTX-LL&#xff0c;APTX-AD&#xff0c;LDAC&#xff0c;LHDC;外设功能支持U盘&#xff0c;SPDIF&#xff0c;K歌宝&#xff0c;SD卡&#xff0…

微机原理 || MOV 指令使用规则(详细+例题)

MOV 目标&#xff0c; 源 DST目标操作数&#xff1a;通用寄存器、段寄存器、存储单元、立即数 SRC源操作数&#xff1a;通用寄存器、段寄存器、存储单元 MOV指令使用规则:(1) 目标操作数无立即方式 例如&#xff0c;MOV 03H&#xff0c;AL; 为错误指令(2)数据传送应注意数据…

计算机网络笔记——传输层

传输层 从通信和信息处理的角度看&#xff0c;传输层是 5 层参考模型中的第 4 层&#xff0c;它向上面的应用层提供通信服务。它属于面向通信部分的最高层&#xff0c;同时也是用户功能中的最低层。 5.1 传输层提供的服务 5.1.1 传输层的功能 传输层为两台主机提供了应用进程…

Input系统之InputReader

InputReader的执行流程图 1宏观分析InputReader InputReaderThread的启动 status_t InputManager::start() {status_t result mDispatcherThread->run("InputDispatcher", PRIORITY_URGENT_DISPLAY);//...result mReaderThread->run("InputReader&quo…

maven私服搭建与使用

概述 在使用maven进行Java项目的开发过程中&#xff0c;难免会有些公共的私有库&#xff0c;这些库是不太方便放到中央仓库的&#xff0c;可以通过Nexus搭建一个私有仓库。 Nexus部署 下载安装包 通过下载安装包nexus-3.47.1-01-unix.tar.gz。 安装 解压安装包 Nexus安装…