微信小程序开发-IP地址查询-例子

简介:

微信小程序开发  小程序搜索框  IP地址查询  搜索查询  样例

 

微信小程序 开发 参考   https://mp.weixin.qq.com/debug/wxadoc/dev/component/


search.wxml

复制代码
<view class="container">
  <view class="page-body">
    <view class="weui-search-bar {{searchFocusCss}}" id="searchBar">
      <view class="weui-search-bar__form">
        <view class="weui-search-bar__box">
          <icon class="weui-icon-search"></icon>
          <input type="text" class="weui-search-bar__input" id="searchInput" placeholder="输入IP" confirm-type="search" bindinput="bindKeyInput" bindconfirm="searchSubmit" value="{{searchValue}}" focus="{{focus}}" />
          <a href="javascript:" class="weui-icon-clear" id="searchClear" bindtap="searchClearClick"></a> 
        </view>
        <view class="weui-search-bar__label" id="searchText" bindtap="searchTextClick">
          <icon class="weui-icon-search"></icon>
          <view class="weui-search-bar__label_span">搜索(8.8.8.8)</view>
        </view>
      </view>
      <view class="weui-search-bar__cancel-btn" id="searchCancel" bindtap="searchCancelClick">取消</view>
    </view>
  </view>
  <view class="page-section">
    <view class="page-section-title">
      <text>查询结果</text>
    </view>
    <view class="page-section-spacing">
      <scroll-view scroll-y="true" class="ip-scroll" bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
        <view class="scroll-view-item">
          <view class="view-item-ip"> {{r.ip}}</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.continent}}</text>
          </view>
          <view class="weui-cell__ft">大洲</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.country}}</text>
          </view>
          <view class="weui-cell__ft">国家</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.province}}</text>
          </view>
          <view class="weui-cell__ft">省份</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.city}}</text>
          </view>
          <view class="weui-cell__ft">城市</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.district}}</text>
          </view>
          <view class="weui-cell__ft">县区</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.isp}}</text>
          </view>
          <view class="weui-cell__ft">运营商</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.areacode}}</text>
          </view>
          <view class="weui-cell__ft">行政区划</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.en}}</text>
          </view>
          <view class="weui-cell__ft">国家英文</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.cc}}</text>
          </view>
          <view class="weui-cell__ft">国家缩写</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.lng}}</text>
          </view>
          <view class="weui-cell__ft">经度</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.lat}}</text>
          </view>
          <view class="weui-cell__ft">纬度</view>
        </view>
        <view class="weui-cell">
          <view class="weui-cell__bd">
            <text>{{r.version}}</text>
          </view>
          <view class="weui-cell__ft">版本</view>
        </view>
      </scroll-view>
      <view class="ip-tip">滚动查看内容</view>
    </view>
  </view>
</view>
复制代码

 

search.js

复制代码
Page({
  data: {
    inputValue: '',
    focus: false,
    searchFocusCss: '',
    r: []
  },
  onReady: function () {
    var that = this;
    wx.request({
      url: 'https://www.qqzeng.com/ip',
      method: 'POST',
      data: {
        ip: 'qqzengip'
      },
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        that.setData({
          r: res.data.data
        })
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete

      }
    })
  },
  searchTextClick: function () {
    this.setData({ searchFocusCss: 'weui-search-bar_focusing', focus: true })
  },
  searchCancelClick: function () {
    this.setData({ searchFocusCss: '', focus: false })
  },
  searchClearClick: function () {
    this.setData({ searchValue: '', focus: true })
  },
  bindKeyInput: function (e) {
    this.setData({ inputValue: e.detail.value })
  },

  //搜索提交
  searchSubmit: function () {
    var that = this;
    var ip = this.data.inputValue;
    if (ip) {
      var isIP = ip.match(/^([1-9]\d*|0[0-7]*|0x[\da-f]+)(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))$/i);
      if (!isIP) {
        wx.showToast({ title: 'ip格式不正确', image: '/images/tip.png' });
        return false;
      }

      wx.showToast({
        title: '搜索中',
        icon: 'loading'
      });
      wx.request({
        url: 'https://www.qqzeng.com/ip',
        method: 'POST',
        data: {
          ip: ip
        },
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success: function (res) {
          that.setData({
            r: res.data.data
          })
        },
        fail: function () {
          // fail
        },
        complete: function () {
          // complete
          wx.hideToast();
        }
      })
    }
  },
  onShareAppMessage: function () {
    return {
      title: 'IP地址查询-qqzeng-ip',
      path: '/pages/ip/search',
      success: function (res) {
        // 分享成功
      },
      fail: function (res) {
        // 分享失败
      }
    }
  }


})
复制代码

 


search.wxss

 

复制代码
@import "../common/weui.wxss";

.page-section-spacing {
  margin-top: 0rpx;
}

.page-section-title {
  text-align: center;
  padding: 40rpx 0rpx 0rpx 0rpx;
  color: #9b9b9b;
  font-size: 36rpx;
}

@media (min-width: 320px) {
  .ip-scroll {
    height: 640rpx;
  }
}

@media (min-width: 360px) {
  .ip-scroll {
    height: 816rpx;
  }
}

@media (min-width: 375px) {
  .ip-scroll {
    height: 836rpx;
  }
}

@media (min-width: 384px) {
  .ip-scroll {
    height: 826rpx;
  }
}

@media (min-width: 414px) {
  .ip-scroll {
    height: 868rpx;
  }
}

.scroll-view-item {
  height: 90rpx;
  line-height: 90rpx;
  color: #000;
  border-bottom: 1px solid #eee;
  text-align: center;
  vertical-align: middle;
  margin: 0px 20px;
}

.view-item-ip {
  line-height: 90rpx;
  color: #2ab059;
  display: inline-block;
  font-size: 36rpx;
}

.weui-cell__bd {
  color: #2ab059;
}

.ip-tip {
  color: #eee;
  font-size: 20rpx;
  text-align: center;
  padding-top: 20rpx;
}
复制代码

 

app.json

 

复制代码
{
  "pages": [
    "pages/ip/search",
    "pages/about/info"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#2ab059",
    "navigationBarTitleText": "IP地址查询",
    "navigationBarTextStyle": "#ffffff"
  },
  "tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#2ab059",
    "borderStyle": "#2ab059",
    "backgroundColor": "#ffffff",
    "list": [
      {
        "pagePath": "pages/ip/search",
        "iconPath": "images/location.png",
        "selectedIconPath": "images/location_hl.png",
        "text": "IP查询"
      },
      {
        "pagePath": "pages/about/info",
        "iconPath": "images/about.png",
        "selectedIconPath": "images/about_hl.png",
        "text": "关于"
      }
    ]
  }
}
复制代码

 

SSL证书

HTTPS 请求

tls 仅支持 1.2 及以上版本

 

 

 

官网:https://www.qqzeng.com
演示:https://www.qqzeng.com/ip
开发:https://github.com/zengzhan/qqzeng-ip



    本文转自曾祥展博客园博客,原文链接:http://www.cnblogs.com/zengxiangzhan/p/6799877.html,如需转载请自行联系原作者


相关文章
|
1月前
|
JSON 小程序 API
【微信小程序】-- 案例 - 本地生活(列表页面)(三十)
【微信小程序】-- 案例 - 本地生活(列表页面)(三十)
|
8月前
|
小程序
微信小程序5种路由跳转的区别
微信小程序5种路由跳转的区别
|
4月前
|
小程序 开发者
微信小程序如何跳转到外部小程序
微信小程序如何跳转到外部小程序
66 0
|
4月前
|
小程序 API
微信小程序跳转到外部小程序
微信小程序跳转到外部小程序
50 0
|
4月前
|
小程序 JavaScript 前端开发
微信小程序(二十)小程序转发
<button data-name="shareBtn" open-type="share">转发</button>
22 0
|
4月前
|
小程序 JavaScript 前端开发
微信小程序(十一)小程序bindtap传参
文章列表页跳文章详情页的时候,我发现了一个问题,bindtap绑定的事件不能直接写:bindtap=jumpToArticle(item.id); 这样写不行,会报错:
42 0
|
8月前
|
小程序
微信小程序路由跳转的方法和区别
微信小程序路由跳转的方法和区别
195 0
|
8月前
|
JavaScript 小程序
微信小程序-页面访问组件数据和方法
好了,结构搭建的差不多了,接下来就是来看关键的内容了,首先我们来看一下如何拿到一个自定义组件的实例,有两种方式,这两种方式的前提条件是,给这个组件设置一个标识,设置标识的方式可以是通过类名或者ID进行设置,然后通过这个标识得到组件实例。
182 0
|
9月前
|
API 定位技术
百度地图web服务API接口实现IP到简要地址的转化
百度地图web服务API接口实现IP到简要地址的转化
120 0
|
9月前
|
存储 缓存 小程序
微信小程序的跨页面传参以及data-方法的相关细节
微信小程序的跨页面传参以及data-方法的相关细节
163 0

热门文章

最新文章