瀏覽代碼

小程序基础代码

guessPrice
sui 5 年之前
父節點
當前提交
a5dedb57ee
共有 14 個檔案被更改,包括 331 行新增0 行删除
  1. +171
    -0
      496_dongfengqichen/app.js
  2. +14
    -0
      496_dongfengqichen/app.json
  3. +10
    -0
      496_dongfengqichen/app.wxss
  4. +16
    -0
      496_dongfengqichen/pages/index/index.js
  5. +3
    -0
      496_dongfengqichen/pages/index/index.json
  6. +4
    -0
      496_dongfengqichen/pages/index/index.wxml
  7. +1
    -0
      496_dongfengqichen/pages/index/index.wxss
  8. +15
    -0
      496_dongfengqichen/pages/logs/logs.js
  9. +4
    -0
      496_dongfengqichen/pages/logs/logs.json
  10. +6
    -0
      496_dongfengqichen/pages/logs/logs.wxml
  11. +8
    -0
      496_dongfengqichen/pages/logs/logs.wxss
  12. +53
    -0
      496_dongfengqichen/project.config.json
  13. +7
    -0
      496_dongfengqichen/sitemap.json
  14. +19
    -0
      496_dongfengqichen/utils/util.js

+ 171
- 0
496_dongfengqichen/app.js 查看文件

@@ -0,0 +1,171 @@
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
// var openid = wx.getStorageSync('openid') || "";
// if (!openid) {
// // 登录
// this.wxLogin();
// } else {
// this.globalData.openid = openid;
// this.getRegionList();
// }
},
wxLogin() {
wx.login({
success: res => {
if (res.code) {
this.getOpenid(res.code);
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
globalData: {
urlRoot: "",//测试接口根目录
// urlRoot: "",//接口根目录
urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录
openid: "",//OPENID
userInfo: null,//用户信息
openidSuccessFuc: null,//方法回调
},
// 获取openId
getOpenid: function (code) {
wx.showLoading({
title: '加载中',
mask: true,
})
this.wxRequest(this.globalData.urlRoot + "/login/getOpenid", { code: code }, res => {
wx.hideLoading();
if (res.code == 200) {
wx.setStorageSync("openid", res.openid);
this.globalData.openid = res.openid;
this.getRegionList();
if (this.globalData.openidSuccessFuc) {
this.globalData.openidSuccessFuc();
}
} else {
wx.showToast({
title: res.msg,
icon: "none"
})
}
}, this);
},
/**
* wx.request
*/
wxRequest: function (url, params, callback, thisArg, methods, openid) {
let that = this;

var httpUrl = url;
var str = "";
var count = 0;
for (let key in params) {
if (count) {
str += "&" + key + "=" + params[key];
} else {
str += key + "=" + params[key];
}
count++;
}
if (str) {
httpUrl += "?" + str;
}
if (!methods) {
methods = "GET";
}
if (methods == "POST") {
wx.request({
url: url,
data: params,
method: methods,
header: {
"content-type": "application/x-www-form-urlencoded",
"OPENID": this.globalData.openid
},
success: function (re) {
if (re.data.code == -1002) {
wx.removeStorageSync('openid');
that.wxLogin();
// that.wxRequest(url, params, callback, thisArg, methods, openid);
}
if (callback && thisArg) {
callback.call(thisArg, re.data);
}
},
fail: function (re) {
wx.hideLoading();
}
})
} else {
wx.request({
url: httpUrl,
method: methods,
header: {
"OPENID": this.globalData.openid,
},
success: function (re) {
if (re.data.code == -1002) {
wx.removeStorageSync('openid');
that.wxLogin();
// that.wxRequest(url, params, callback, thisArg, methods, openid);
}
if (callback && thisArg) {
callback.call(thisArg, re.data);
}
},
fail: function (res) {
wx.hideLoading();
}
})
}
},
submitUserMsg: function (data) {//提交用户信息
this.wxRequest(this.globalData.urlRoot + "/login/submitWxInfo", { userInfo: data }, res => {
}, this, "POST");
},
codeVerify: function (card) {//身份证号码验证
let rule = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
return rule.test(card);
},
mobileVerify: function (mobile) {//手机号验证
let rule = /^1\d{10}$/;
return rule.test(mobile);
},
callMobile: function (e) {//拨打电话
wx.makePhoneCall({
phoneNumber: e //仅为示例,并非真实的电话号码
})
},
sharePack: function () {//分享
return {
title: '',
imageUrl: "",
path: "/pages/index/index"
}
},
addformId: function (e) {//添加formid
console.log("下面是formid");
console.log(e);
this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
// if(res.code==200){
// console.log(res.msg);
// }else{
// console.log(res.msg);
// }
console.log(res.msg);
}, this, "POST");
},
getRegionList: function () {//获取可选区域列表
this.wxRequest(this.globalData.urlRoot + "/user/getAreaList", {}, res => {
if (res.code == 200) {
this.globalData.cityAllData = res.data;
console.log(this.globalData.cityAllData);
} else {
console.log(res.msg)
}
}, this);
}
})

+ 14
- 0
496_dongfengqichen/app.json 查看文件

@@ -0,0 +1,14 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}

+ 10
- 0
496_dongfengqichen/app.wxss 查看文件

@@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}

+ 16
- 0
496_dongfengqichen/pages/index/index.js 查看文件

@@ -0,0 +1,16 @@
//index.js
//获取应用实例
const app = getApp()

Page({
data: {

},
//事件处理函数
bindViewTap: function() {
},
onLoad: function () {
}
})

+ 3
- 0
496_dongfengqichen/pages/index/index.json 查看文件

@@ -0,0 +1,3 @@
{
"usingComponents": {}
}

+ 4
- 0
496_dongfengqichen/pages/index/index.wxml 查看文件

@@ -0,0 +1,4 @@
<!--index.wxml-->
<view class="container">
首页
</view>

+ 1
- 0
496_dongfengqichen/pages/index/index.wxss 查看文件

@@ -0,0 +1 @@
/**index.wxss**/

+ 15
- 0
496_dongfengqichen/pages/logs/logs.js 查看文件

@@ -0,0 +1,15 @@
//logs.js
const util = require('../../utils/util.js')

Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})

+ 4
- 0
496_dongfengqichen/pages/logs/logs.json 查看文件

@@ -0,0 +1,4 @@
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}

+ 6
- 0
496_dongfengqichen/pages/logs/logs.wxml 查看文件

@@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>

+ 8
- 0
496_dongfengqichen/pages/logs/logs.wxss 查看文件

@@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}

+ 53
- 0
496_dongfengqichen/project.config.json 查看文件

@@ -0,0 +1,53 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"coverView": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "miniprogram",
"libVersion": "2.10.1",
"appid": "wx5c64e733d849c3ef",
"projectname": "496_dongfengqichen",
"debugOptions": {
"hidedInDevtools": []
},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}

+ 7
- 0
496_dongfengqichen/sitemap.json 查看文件

@@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}

+ 19
- 0
496_dongfengqichen/utils/util.js 查看文件

@@ -0,0 +1,19 @@
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()

return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}

module.exports = {
formatTime: formatTime
}

Loading…
取消
儲存