wsq 2 years ago
parent fbdc88616e
commit 7396351fc5

@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

589
app.js

@ -0,0 +1,589 @@
// app.js
App({
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力');
} else {
wx.cloud.init({
// env 参数说明:
// env 参数决定接下来小程序发起的云开发调用wx.cloud.xxx会默认请求到哪个云环境的资源
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// 如不填则使用默认环境(第一个创建的环境)
// env: 'my-env-id',
env: 'cloud1-5ggzbo3kcd4ea4e2',
traceUser: true,
});
}
},
//全局变量
globalData: {
    url: null
  },
//wx.cloud.callFunction({
//name:'get',
// data:{
// name:"",
// pattern:"",
// kind:"",
// style:"",
// colour:"",
// T:"",
// thickness:"",
// season:""
// },
// success:res=>{
// this.globalData.openid=res.result.openid
// },
// fail:err=>{
// console.error('[云函数] [login] 调用失败',err)
// }
//})
globalData:{
clothes:[{
name:"t-shirt1",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"white",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt2",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"red",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt3",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"orange",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt4",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"black",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt5",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"red",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt6",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"purple",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt7",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"green",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt8",
pattern:"up",
kind:"t-shirt",
style:"sports",
colour:"white",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"t-shirt9",
pattern:"up",
kind:"t-shirt",
style:"sports",
colour:"black",
T:-4,
thickness:"thin",
season:"summer"
},{
name:"t-shirt10",
pattern:"up",
kind:"t-shirt",
style:"leisure",
colour:"blue",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"hoodie1",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"white",
T:2,
thickness:"thin",
season:"spring"
},{
name:"hoodie2",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"brown",
T:5,
thickness:"thin",
season:"winter"
},{
name:"hoodie3",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"white",
T:5,
thickness:"thin",
season:"winter"
},{
name:"hoodie4",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"black",
T:3,
thickness:"proper",
season:"autumn"
},{
name:"hoodie5",
pattern:"up",
kind:"hoodie",
style:"sports",
colour:"yellow",
T:3,
thickness:"proper",
season:"spring"
},{
name:"hoodie6",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"black",
T:4,
thickness:"proper",
season:"spring"
},{
name:"hoodie7",
pattern:"up",
kind:"hoodie",
style:"leisure",
colour:"white",
T:3,
thickness:"proper",
season:"autumn"
},{
name:"hoodie8",
pattern:"up",
kind:"hoodie",
style:"sports",
colour:"white",
T:3,
thickness:"proper",
season:"autumn"
},{
name:"hoodie9",
pattern:"up",
kind:"hoodie",
style:"sports",
colour:"pink",
T:5,
thickness:"thick",
season:"winter"
},{
name:"hoodie10",
pattern:"up",
kind:"hoodie",
style:"sports",
colour:"green",
T:4,
thickness:"proper",
season:"spring"
},{
name:"skirt1",
pattern:"down",
kind:"skirt",
style:"leisure",
colour:"blue",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"skirt2",
pattern:"down",
kind:"skirt",
style:"business",
colour:"brown",
T:3,
thickness:"thin",
season:"winter"
},{
name:"skirt3",
pattern:"down",
kind:"skirt",
style:"sport",
colour:"white",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"skirt4",
pattern:"down",
kind:"skirt",
style:"leisure",
colour:"brown",
T:2,
thickness:"proper",
season:"autumn"
},{
name:"skirt5",
pattern:"all",
kind:"skirt",
style:"leisure",
colour:"red",
T:-10,
thickness:"thin",
season:"summer"
},{
name:"skirt6",
pattern:"all",
kind:"skirt",
style:"business",
colour:"white",
T:-10,
thickness:"thin",
season:"summer"
},{
name:"skirt7",
pattern:"all",
kind:"skirt",
style:"leisure",
colour:"black",
T:5,
thickness:"proper",
season:"autumn"
},{
name:"skirt8",
pattern:"down",
kind:"skirt",
style:"business",
colour:"black",
T:-5,
thickness:"thin",
season:"autumn"
},{
name:"skirt9",
pattern:"down",
kind:"skirt",
style:"leisure",
colour:"pink",
T:1,
thickness:"proper",
season:"spring"
},{
name:"skirt10",
pattern:"all",
kind:"skirt",
style:"leisure",
colour:"white",
T:-10,
thickness:"thin",
season:"summer"
},{
name:"coat1",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"black",
T:5,
thickness:"proper",
season:"autumn"
},{
name:"coat2",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"white",
T:4,
thickness:"proper",
season:"autumn"
},{
name:"coat3",
pattern:"up",
kind:"coat",
style:"business",
colour:"white",
T:2,
thickness:"thin",
season:"spring"
},{
name:"coat4",
pattern:"up",
kind:"coat",
style:"business",
colour:"red",
T:5,
thickness:"thick",
season:"winter"
},{
name:"coat5",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"white",
T:1,
thickness:"thin",
season:"summer"
},{
name:"coat6",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"black",
T:9,
thickness:"thick",
season:"winter"
},{
name:"coat7",
pattern:"up",
kind:"coat",
style:"sports",
colour:"black",
T:3,
thickness:"thin",
season:"spring"
},{
name:"coat8",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"pink",
T:5,
thickness:"proper",
season:"autumn"
},{
name:"coat9",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"white",
T:10,
thickness:"thick",
season:"winter"
},{
name:"coat10",
pattern:"up",
kind:"coat",
style:"leisure",
colour:"khaki",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"sweater1",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"white",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"sweater2",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"black",
T:4,
thickness:"thick",
season:"winter"
},{
name:"sweater3",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"blue",
T:4,
thickness:"thick",
season:"winter"
},{
name:"sweater4",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"blue",
T:4,
thickness:"thick",
season:"winter"
},{
name:"sweater5",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"gray",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"sweater6",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"yellow",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"sweater7",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"yellow",
T:4,
thickness:"thick",
season:"winter"
},{
name:"sweater8",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"brown",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"sweater9",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"white",
T:4,
thickness:"thick",
season:"winter"
},{
name:"sweater10",
pattern:"up",
kind:"sweater",
style:"leisure",
colour:"yellow",
T:3,
thickness:"thin",
season:"autumn"
},{
name:"pants1",
pattern:"down",
kind:"long",
style:"leisure",
colour:"black",
T:1,
thickness:"thin",
season:"spring"
},{
name:"pants2",
pattern:"down",
kind:"long",
style:"sports",
colour:"white",
T:3,
thickness:"proper",
season:"autumn"
},{
name:"pants3",
pattern:"down",
kind:"long",
style:"sports",
colour:"purple",
T:1,
thickness:"thin",
season:"summer"
},{
name:"pants4",
pattern:"down",
kind:"long",
style:"leisure",
colour:"blue",
T:5,
thickness:"thick",
season:"winter"
},{
name:"pants5",
pattern:"down",
kind:"long",
style:"business",
colour:"gray",
T:3,
thickness:"proper",
season:"autumn"
},{
name:"pants6",
pattern:"down",
kind:"short",
style:"leisure",
colour:"black",
T:3,
thickness:"proper",
season:"winter"
},{
name:"pants7",
pattern:"down",
kind:"short",
style:"leisure",
colour:"black",
T:3,
thickness:"proper",
season:"winter"
},{
name:"pants8",
pattern:"down",
kind:"short",
style:"sports",
colour:"white",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"pants9",
pattern:"down",
kind:"short",
style:"leisure",
colour:"black",
T:-5,
thickness:"thin",
season:"summer"
},{
name:"pants10",
pattern:"down",
kind:"short",
style:"business",
colour:"brown",
T:-5,
thickness:"thin",
season:"summer"
}
]
},
})

@ -0,0 +1,53 @@
{
"cloud": true,
"pages": [
"pages/index/index",
"pages/navigation/index/index",
"pages/navigation/index/show_clothes/show_clothes",
"pages/navigation/index/add/add",
"pages/navigation/index/delete/delete",
"pages/navigation/self/self",
"pages/navigation/userinform/userinform",
"pages/navigation/safety/safety",
"pages/navigation/shezhi/shezhi",
"pages/navigation/index/recommand/recommand",
"pages/navigation/index/add/camera/camera"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
"usingComponents": {
"van-button": "pages/miniprogram_npm/@vant/weapp/button/index",
"van-tabbar": "pages/miniprogram_npm/@vant/weapp/tabbar/index",
"van-tabbar-item": "pages/miniprogram_npm/@vant/weapp/tabbar-item/index",
"van-image": "pages/miniprogram_npm/@vant/weapp/image/index",
"van-icon": "pages/miniprogram_npm/@vant/weapp/icon/index",
"van-divider": "pages/miniprogram_npm/@vant/weapp/divider/index",
"van-rate": "pages/miniprogram_npm/@vant/weapp/rate/index",
"van-field": "pages/miniprogram_npm/@vant/weapp/field/index",
"van-toast": "pages/miniprogram_npm/@vant/weapp/toast/index"
},
"sitemapLocation": "sitemap.json",
"tabBar": {
"selectedColor": "#5001",
"backgroundColor": "white",
"borderStyle": "white",
"list": [
{
"text": "首页",
"pagePath": "pages/navigation/index/index",
"iconPath": "pages/img/首页.png",
"selectedIconPath": "pages/img/首页.png"
},
{
"text": "我的",
"pagePath": "pages/navigation/self/self",
"iconPath": "pages/img/我的.png",
"selectedIconPath": "pages/img/我的.png"
}
]
}
}

@ -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;
}

@ -0,0 +1,6 @@
{
"permissions": {
"openapi": [
]
}
}

@ -0,0 +1,32 @@
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init() // 使用当前云环境
const db=cloud.database()
const MAX_LIMIT=100
// 云函数入口函数
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
//先取出集合记录总数
const countResult=await db.collection('cloth').count()
const total=countResult.total
//计算分几次取
const batchTimes = Math.ceil(total / 100)
// 承载所有读操作的 promise 的数组
const tasks = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('cloth').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
tasks.push(promise)
}
// 等待所有
return (await Promise.all(tasks)).reduce((acc, cur) => {
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
data: acc.data.concat(cur.data),
errMsg: acc.errMsg,
}
})
}

@ -0,0 +1,14 @@
{
"name": "get",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.6.3"
}
}

@ -0,0 +1,7 @@
{
"permissions": {
"openapi": [
"wxacode.get"
]
}
}

@ -0,0 +1,56 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 创建集合云函数入口函数
exports.main = async (event, context) => {
try {
// 创建集合
await db.createCollection('sales');
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华东',
city: '上海',
sales: 11
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华东',
city: '南京',
sales: 11
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华南',
city: '广州',
sales: 22
}
});
await db.collection('sales').add({
// data 字段表示需新增的 JSON 数据
data: {
region: '华南',
city: '深圳',
sales: 22
}
});
return {
success: true
};
} catch (e) {
// 这里catch到的是该collection已经存在从业务逻辑上来说是运行成功的所以catch返回success给前端避免工具在前端抛出异常
return {
success: true,
data: 'create collection success'
};
}
};

@ -0,0 +1,20 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
// 获取小程序二维码云函数入口函数
exports.main = async (event, context) => {
// 获取小程序二维码的buffer
const resp = await cloud.openapi.wxacode.get({
path: 'pages/index/index'
});
const { buffer } = resp;
// 将图片上传云存储空间
const upload = await cloud.uploadFile({
cloudPath: 'code.png',
fileContent: buffer
});
return upload.fileID;
};

@ -0,0 +1,17 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
// 获取openId云函数入口函数
exports.main = async (event, context) => {
// 获取基础信息
const wxContext = cloud.getWXContext();
return {
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
};
};

@ -0,0 +1,25 @@
const getOpenId = require('./getOpenId/index');
const getMiniProgramCode = require('./getMiniProgramCode/index');
const createCollection = require('./createCollection/index');
const selectRecord = require('./selectRecord/index');
const updateRecord = require('./updateRecord/index');
const sumRecord = require('./sumRecord/index');
// 云函数入口函数
exports.main = async (event, context) => {
switch (event.type) {
case 'getOpenId':
return await getOpenId.main(event, context);
case 'getMiniProgramCode':
return await getMiniProgramCode.main(event, context);
case 'createCollection':
return await createCollection.main(event, context);
case 'selectRecord':
return await selectRecord.main(event, context);
case 'updateRecord':
return await updateRecord.main(event, context);
case 'sumRecord':
return await sumRecord.main(event, context);
}
};

@ -0,0 +1,14 @@
{
"name": "quickstartFunctions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.4.0"
}
}

@ -0,0 +1,12 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 查询数据库集合云函数入口函数
exports.main = async (event, context) => {
// 返回数据库查询结果
return await db.collection('sales').get();
};

@ -0,0 +1,18 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const $ = db.command.aggregate;
// 聚合记录云函数入口函数
exports.main = async (event, context) => {
// 返回数据库聚合结果
return db.collection('sales').aggregate()
.group({
_id: '$region',
sum: $.sum('$sales')
})
.end();
};

@ -0,0 +1,32 @@
const cloud = require('wx-server-sdk');
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
// 修改数据库信息云函数入口函数
exports.main = async (event, context) => {
try {
// 遍历修改数据库信息
for (let i = 0; i < event.data.length; i++) {
await db.collection('sales').where({
_id: event.data[i]._id
})
.update({
data: {
sales: event.data[i].sales
},
});
}
return {
success: true,
data: event.data
};
} catch (e) {
return {
success: false,
errMsg: e
};
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

@ -1,180 +1,327 @@
// pages/index/index.js // pages/index/index.js
import Toast from './@vant/weapp/toast/toast';
var app=getApp();
Page({ Page({
data: {
ip:'82.157.11.188' ,
port:8080,
password:'',
islogin:1,
inputipone:'',//登录注册时时输入的手机号
compassiphone:'',//找回密码时输入的手机号
loginbtnstate:true,
strloginUser:'',//登录用户名
strloginpassword:'',//用户密码
switchChecked:'',//选中按钮
},
onLoad() {
var _this = this;
_this.setData({
strloginUser: wx.getStorageSync("iphone"),
strloginpassword: wx.getStorageSync("password"),
switchChecked:wx.getStorageSync('checkedValue'),
loginbtnstate:wx.getStorageSync('wxlogin'),
})
console.log(_this.data.strloginUser+_this.data.strloginpassword+_this.data.switchChecked)
},
//判断是否要记住密码
bindswitchchange: function (event) {
//得到值
var checkedValue = event.detail.value;
console.log("开关状态"+checkedValue);
var _this = this;
if (checkedValue == true){
_this.setData({
switchChecked:true,
})
// wx.setStorageSync("iphone",_this.data.strloginUser);
// wx.setStorageSync("password",_this.data.strloginpassword);
//wx.setStorageSync("checkedValue", _this.data.switchChecked);
/** console.log(checkedValue);
* 页面的初始数据 } else if (checkedValue == false) {
*/ _this.setData({
switchChecked: false
})
// wx.setStorageSync("iphone","");
// wx.setStorageSync("password","");
}
},
//输入密码(登录界面判断有无)
password1:function(event){
var that = this
var m=event.detail.value
console.log(event.detail.value)
onload: function (){ if(m!=''){
this.setData({
strloginpassword:m
})
if(this.data.strloginUser!=''&&(this.data.strloginUser.length==11))
{
this.setData({
loginbtnstate:false
})
}
else{
this.setData({
loginbtnstate:true,
})
}
}
else{
this.setData({
loginbtnstate:true,
password:''
})
}
}, },
data: { //输入手机号(登录界面判断有无)
user:"",//输入账号 inputiphone1:function(event){
pwd:"",//输入密码 console.log(event.detail.value)
default_user:"user",//默认账号 var m=event.detail.value
default_pwd:"123456",//默认密码
}, if(m!=''&&(m.length==11)){
//登录按钮 this.setData({
log_on() strloginUser:m
{ })
console.log("账号",this.data.user,this.data.pwd); if(this.data.strloginpassword!='')
if(this.data.user==this.data.default_user&& this.data.pwd==this.data.default_pwd)
{ {
wx.reLaunch({ this.setData({
url: '/pages/navigation/index/index', loginbtnstate:false
})
}
else{
this.setData({
loginbtnstate:true,
})
}
}
else{
this.setData({
loginbtnstate:true,
}) })
}else{
Toast.fail('账号或密码错误');
} }
}, },
//忘记密码 //输入密码(注册界面判断有无)
forget() password2:function(event){
console.log(event.detail.value)
var m=event.detail.value
if(m!=''){
this.setData({
password:m
})
if(this.data.inputipone!=''&&(this.data.inputipone.length==11))
{ {
this.setData({
loginbtnstate:false
})
}
else{
this.setData({
loginbtnstate:true,
})
}
}
else{
this.setData({
loginbtnstate:true,
password:''
})
}
}, },
//输入手机号(注册界面判断有无)
inputiphone2:function(event){
console.log(event.detail.value)
var m=event.detail.value
if(m!=''&&(m.length==11)){
this.setData({
inputipone:m
})
if(this.data.password!='')
{
this.setData({
loginbtnstate:false
})
}
else{
this.setData({
loginbtnstate:true,
})
}
//获取用户名 }
getName(user) { else{
console.log('获取输入的用户名', user.detail.value)
this.setData({ this.setData({
name: user.detail.value loginbtnstate:true,
inputipone:''
}) })
}
}, },
//获取用户账号 //找回密码输入框
getZhangHao(user) { compass:function(event){
console.log('获取输入的账号', user.detail.value) console.log("找回密码"+event.detail.value)
var m=event.detail.value
if(m!=''&&(m.length==11)){
this.setData({ this.setData({
zhanghao: user.detail.value compassiphone:m,
loginbtnstate:false
}) })
}, }
// 获取密码 else{
getMiMa(pwd) {
console.log('获取输入的密码', pwd.detail.value)
this.setData({ this.setData({
mima: pwd.detail.value loginbtnstate:true,
inputipone:''
}) })
}
}, },
//登录
onlogin:function(e){
var that=this
//记住密码
var checkedValue = that.data.switchChecked;
console.log(checkedValue);
//如果记住密码则向微信缓存写入账号密码
//如果不记住密码则清空微信缓存存在的账号密码
if (checkedValue == true) {
wx.setStorageSync("iphone",that.data.strloginUser);
wx.setStorageSync("password",that.data.strloginpassword);
wx.setStorageSync("checkedValue", that.data.switchChecked);
wx.setStorageSync("wxlogin", false);
console.log(that.data.loginbtnstate)
} else if (checkedValue == false) {
wx.setStorageSync("iphone","");
wx.setStorageSync("password","");
wx.setStorageSync("checkedValue", false);
wx.setStorageSync("wxlogin", true);
}
//开始检查用户名和密码是否一致
var userinfos=wx.getStorageSync('userjobs') ||[];//找数组
if(userinfos.iphone==that.data.strloginUser){
if(userinfos.password==that.data.strloginpassword)
{
//注册
zhuce() {
let name = this.data.name
let zhanghao = this.data.zhanghao
let mima = this.data.mima
console.log("点击了注册")
console.log("name", name)
console.log("zhanghao", zhanghao)
console.log("mima", mima)
//校验用户名
if (name.length < 2) {
wx.showToast({ wx.showToast({
icon: 'none', title: '登录成功',
title: '用户名至少2位', duration:2000,
}),
wx.switchTab({
url: '../navigation/index/index'
}) })
return
} }
if (name.length > 10) { else{
wx.showToast({ wx.showToast({
icon: 'none', title: '密码错误',
title: '用户名最多10位', duration:2000
}) })
return
} }
//校验账号
if (zhanghao.length < 4) {
wx.showToast({
icon: 'none',
title: '账号至少4位',
})
return
} }
//校验密码 else{
if (mima.length < 4) {
wx.showToast({ wx.showToast({
icon: 'none', title: '用户名不存在',
title: '密码至少4位', duration:2000
}) })
return
} }
//注册功能的实现 },
wx.cloud.database().collection('user').add({ //注册
formsubmit:function(e){
var that=this
console.log(e.detail.value)
var obj={}
obj.password=e.detail.value.inputpassword,
obj.iphone=e.detail.value.iphone,
console.log(obj)
//存入多个注册用户
//初始化云
wx.cloud.init({
env:'cloud1-5ggzbo3kcd4ea4e2'
});
//初始化数据库
const db=wx.cloud.database();
db.collection('user').add({
data: { data: {
user:"",//账号 iphone:obj.iphone,
pwd:"",//密码 password:obj.password,
}, },
success(res) { sucess:function(res){
console.log('注册成功', res) console.log("添加成功",res);
},
fail:function(res){
console.log(res.errMsg,"添加失败")
}
})
//var arr=wx.getStorageSync('userjobs') ||[];
//arr.push(obj);
wx.setStorageSync('userjobs', obj);
wx.showToast({ wx.showToast({
title: '注册成功', title: '注册成功',
duration:1000,
success:function(){
that.setData({
islogin:1
}) })
wx.navigateTo({ }
url: '../login/login',
}) })
}, },
fail(res) { //找回密码
console.log('注册失败', res) comebackpassword:function(e){
var that =this
let wsy=wx.getStorageSync('userjobs') || [];//找数组
console.log("输入的手机号"+that.data.compassiphone)
console.log("本地缓存的手机号"+wsy.iphone)
if(wsy.iphone==that.data.compassiphone)
{
wx.setClipboardData({
data: wsy.password,
success (res) {
wx.getClipboardData({
success (res) {
console.log(res.data) // data
that.setData({
islogin:1
})
wx.showToast({
title: '密码已复制',
duration:2000
})
} }
}) })
}
})
}
else
{
wx.showToast({
title: '该手机号码未注册',
duration:2000
})
}
}, },
//转到注册
register:function(event){
/** var that = this
* 生命周期函数--监听页面加载 that.setData({
*/ islogin:3
onLoad(options) { })
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
}, },
//转到登录
/** denglu:function(event){
* 页面相关事件处理函数--监听用户下拉动作 var that = this
*/ that.setData({
onPullDownRefresh() { islogin:1
})
}, },
//转到忘记密码
forget:function(event){
this.setData({
islogin:2
})
}
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
}, })
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

@ -2,42 +2,85 @@
--> -->
<view class="wrapper">
<view> <!-- 第一部分 -->
<van-toast id="van-toast" /> <view wx:if="{{islogin==1}}">
<view style="width:100vw; height:100vh;position:relative;overflow: hidden"> <image class="photo1" src="../img/登陆.jpg"></image>
<view class="header">
<van-image width="100vw" height="100vh" fit="fill" src="/pages/img/登陆.jpg" />
<view style="display: -webkit-flex;display: flex; flex-direction:column; position:relative;top:-700rpx;left:100rpx; z-index:100;">
<view style="display: -webkit-flex;display: flex;align-content:flex-start">
<van-icon size="70rpx" name="/pages/img/手机.jpg" />
<view style="width:450rpx;border-bottom: solid #d4d4d4 calc(0.1rem);">
<van-cell-group>
<van-field clearable model:value="{{ user }}" placeholder="请输入用户名" border="{{ false }}" />
</van-cell-group>
</view> </view>
</view> </view>
<view style="display: -webkit-flex;display: flex;align-content:flex-start;margin-top:50rpx;"> <!-- 找回密码 -->
<van-icon size="70rpx" name="/pages/img/密码.jpg" /> <view wx:elif="{{islogin==2}}">
<view style="width:450rpx;border-bottom: solid #d4d4d4 calc(0.1rem);"> <view class="header">
<van-cell-group> <view class="title">找回密码</view>
<van-field password clearable model:value="{{ pwd }}" placeholder="请输入密码" border="{{ false }}" /> <view class="info">Retrieve the password</view>
</view>
</van-cell-group> </view>
<!-- 请注册 -->
<view wx:else="{{islogin==3}}">
<view class="header">
<view class="title">请注册</view>
<view class="info">Please Register Your Account</view>
</view> </view>
</view> </view>
<van-button bind:click="log_on"round custom-style="width:550rpx;background-color:#32b16c;color:white;margin-top:60rpx;">登 录</van-button>
<view style="display: -webkit-flex;display: flex;padding:20rpx;">
<view style="flex:1 1 30%;">忘记密码?</view> <!-- 第二部分 -->
<view style="flex:1 1 70%;text-align:center;">注册</view> <view class="body">
<!-- 登录页面 -->
<view wx:if="{{islogin==1}}">
<view class="input1">
<input class="one" type="number" bindinput="inputiphone1" maxlength="11" placeholder="请输入手机号" value="{{strloginUser}}"/>
<input class="one" password="true" bindinput="password1" placeholder="请输入密码" value="{{strloginpassword}}"/>
</view> </view>
<view class="remenber"> <switch type="checkbox" checked="{{switchChecked}}" bindswitcheck="switchChecked" bindchange="bindswitchchange" style="transform:scale(0.8)"/>记住密码</view>
<button class="two" color="#3d7ef9" type="primary" bindtap="onlogin" disabled="{{loginbtnstate}}">登录</button>
</view> </view>
<!-- 找回密码 -->
<view wx:elif="{{islogin==2}}">
<view class="input1">
<input class="one" type="number" bindinput="compass" maxlength="11" placeholder="请输入手机号" />
</view> </view>
<button class="two" color="#3d7ef9" type="primary" bindtap="comebackpassword" disabled="{{loginbtnstate}}">找回密码</button>
</view> </view>
<!-- 注册页面 -->
<view wx:else="{{islogin==3}}">
<form bindsubmit="formsubmit">
<view class="input1">
<input class="one" type="number" bindinput="inputiphone2" maxlength="11" placeholder="请输入手机号" name="iphone" />
<input class="one" password="true" bindinput="password2" placeholder="请输入密码" name="inputpassword" />
</view>
<button class="two" color="#3d7ef9" type="primary" form-type="submit" disabled="{{loginbtnstate}}">注册</button>
</form>
</view>
<!-- 第三部分 -->
<!-- 登录 -->
<view wx:if="{{islogin==1}}">
<view class="end">
<text bindtap="register">注册账户</text>
<text>|</text>
<text bindtap="forget">忘记密码</text>
</view>
</view>
<!-- 找回密码 -->
<view wx:elif="{{islogin==2}}">
<view class="end">
<text bindtap="denglu">登录页面</text>
</view>
</view>
<!-- 注册 -->
<view wx:else="{{islogin==3}}">
<view class="end">
<text bindtap="denglu">登录页面</text>
</view>
</view>
<view class="end-power">
<view class="power">
<text>Power By WSY</text>
</view>
</view>
</view>
</view>

@ -1 +1,67 @@
/* pages/index/index.wxss */ /* pages/index/index.wxss */
.photo1{
position: absolute;
width: 100%;
height: 100%;
z-index: -999;
}
.header{
height: 200rpx;
padding:40rpx 30rpx;
display: flex;
flex-direction: column;
color: white;
}
.title{
font-size: 52rpx;
font-weight: 700;
padding: 20rpx;
}
.header .info{
font-size:28rpx ;
padding: 20rpx;
}
.body{
padding: 40rpx;
padding-top: 230rpx;
}
.input{
margin-top: 20rpx;
}
.one{
height: 100rpx;
margin-top: 20rpx;
box-shadow: #77778a 0 0 5rpx;
border-radius: 10rpx;
}
.two{
border: solid 1rpx #73ccd8;
margin-top: 40rpx;
width: 100%;
background-color: #73ccd8;
border-radius: 40rpx;
}
.end{
display: flex;
justify-content: center;
margin-top: 40rpx;
color: #9f9f9f;
}
.end text{
margin-left:30rpx;
}
.end-power{
display: flex;
justify-content: center;
}
.power{
color: #d6d6d6;
position: fixed;
bottom: 50rpx;
}
.remenber{
margin-top: 20rpx;
}

@ -0,0 +1,73 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var component_1 = require("../common/component");
var button_1 = require("../mixins/button");
(0, component_1.VantComponent)({
mixins: [button_1.button],
props: {
show: Boolean,
title: String,
cancelText: String,
description: String,
round: {
type: Boolean,
value: true,
},
zIndex: {
type: Number,
value: 100,
},
actions: {
type: Array,
value: [],
},
overlay: {
type: Boolean,
value: true,
},
closeOnClickOverlay: {
type: Boolean,
value: true,
},
closeOnClickAction: {
type: Boolean,
value: true,
},
safeAreaInsetBottom: {
type: Boolean,
value: true,
},
},
methods: {
onSelect: function (event) {
var _this = this;
var index = event.currentTarget.dataset.index;
var _a = this.data, actions = _a.actions, closeOnClickAction = _a.closeOnClickAction, canIUseGetUserProfile = _a.canIUseGetUserProfile;
var item = actions[index];
if (item) {
this.$emit('select', item);
if (closeOnClickAction) {
this.onClose();
}
if (item.openType === 'getUserInfo' && canIUseGetUserProfile) {
wx.getUserProfile({
desc: item.getUserProfileDesc || ' ',
complete: function (userProfile) {
_this.$emit('getuserinfo', userProfile);
},
});
}
}
},
onCancel: function () {
this.$emit('cancel');
},
onClose: function () {
this.$emit('close');
},
onClickOverlay: function () {
this.$emit('click-overlay');
this.onClose();
},
},
});

@ -0,0 +1,8 @@
{
"component": true,
"usingComponents": {
"van-icon": "../icon/index",
"van-popup": "../popup/index",
"van-loading": "../loading/index"
}
}

@ -0,0 +1,69 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<van-popup
show="{{ show }}"
position="bottom"
round="{{ round }}"
z-index="{{ zIndex }}"
overlay="{{ overlay }}"
custom-class="van-action-sheet"
safe-area-inset-bottom="{{ safeAreaInsetBottom }}"
close-on-click-overlay="{{ closeOnClickOverlay }}"
bind:close="onClickOverlay"
>
<view wx:if="{{ title }}" class="van-action-sheet__header">
{{ title }}
<van-icon
name="cross"
custom-class="van-action-sheet__close"
bind:click="onClose"
/>
</view>
<view wx:if="{{ description }}" class="van-action-sheet__description van-hairline--bottom">
{{ description }}
</view>
<view wx:if="{{ actions && actions.length }}">
<!-- button外包一层view防止actions动态变化导致渲染时button被打散 -->
<button
wx:for="{{ actions }}"
wx:key="index"
open-type="{{ item.disabled || item.loading || (canIUseGetUserProfile && item.openType === 'getUserInfo') ? '' : item.openType }}"
style="{{ item.color ? 'color: ' + item.color : '' }}"
class="{{ utils.bem('action-sheet__item', { disabled: item.disabled || item.loading }) }} {{ item.className || '' }}"
hover-class="van-action-sheet__item--hover"
data-index="{{ index }}"
bindtap="{{ item.disabled || item.loading ? '' : 'onSelect' }}"
bindgetuserinfo="onGetUserInfo"
bindcontact="onContact"
bindgetphonenumber="onGetPhoneNumber"
binderror="onError"
bindlaunchapp="onLaunchApp"
bindopensetting="onOpenSetting"
lang="{{ lang }}"
session-from="{{ sessionFrom }}"
send-message-title="{{ sendMessageTitle }}"
send-message-path="{{ sendMessagePath }}"
send-message-img="{{ sendMessageImg }}"
show-message-card="{{ showMessageCard }}"
app-parameter="{{ appParameter }}"
>
<block wx:if="{{ !item.loading }}">
{{ item.name }}
<view wx:if="{{ item.subname }}" class="van-action-sheet__subname" >{{ item.subname }}</view>
</block>
<van-loading wx:else custom-class="van-action-sheet__loading" size="22px" />
</button>
</view>
<slot />
<block wx:if="{{ cancelText }}">
<view class="van-action-sheet__gap" />
<view
class="van-action-sheet__cancel"
hover-class="van-action-sheet__cancel--hover"
hover-stay-time="70"
bind:tap="onCancel"
>
{{ cancelText }}
</view>
</block>
</van-popup>

@ -0,0 +1 @@
@import '../common/index.wxss';.van-action-sheet{color:var(--action-sheet-item-text-color,#323233);max-height:var(--action-sheet-max-height,90%)!important}.van-action-sheet__cancel,.van-action-sheet__item{background-color:var(--action-sheet-item-background,#fff);font-size:var(--action-sheet-item-font-size,16px);line-height:var(--action-sheet-item-line-height,22px);padding:14px 16px;text-align:center}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5}.van-action-sheet__cancel:after,.van-action-sheet__item:after{border-width:0}.van-action-sheet__cancel{color:var(--action-sheet-cancel-text-color,#646566)}.van-action-sheet__gap{background-color:var(--action-sheet-cancel-padding-color,#f7f8fa);display:block;height:var(--action-sheet-cancel-padding-top,8px)}.van-action-sheet__item--disabled{color:var(--action-sheet-item-disabled-text-color,#c8c9cc)}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__subname{color:var(--action-sheet-subname-color,#969799);font-size:var(--action-sheet-subname-font-size,12px);line-height:var(--action-sheet-subname-line-height,20px);margin-top:var(--padding-xs,8px)}.van-action-sheet__header{font-size:var(--action-sheet-header-font-size,16px);font-weight:var(--font-weight-bold,500);line-height:var(--action-sheet-header-height,48px);text-align:center}.van-action-sheet__description{color:var(--action-sheet-description-color,#969799);font-size:var(--action-sheet-description-font-size,14px);line-height:var(--action-sheet-description-line-height,20px);padding:20px var(--padding-md,16px);text-align:center}.van-action-sheet__close{color:var(--action-sheet-close-icon-color,#c8c9cc);font-size:var(--action-sheet-close-icon-size,22px)!important;line-height:inherit!important;padding:var(--action-sheet-close-icon-padding,0 16px);position:absolute!important;right:0;top:0}.van-action-sheet__loading{display:flex!important}

@ -0,0 +1,232 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var component_1 = require("../common/component");
var shared_1 = require("../picker/shared");
var utils_1 = require("../common/utils");
var EMPTY_CODE = '000000';
(0, component_1.VantComponent)({
classes: ['active-class', 'toolbar-class', 'column-class'],
props: __assign(__assign({}, shared_1.pickerProps), { value: {
type: String,
observer: function (value) {
this.code = value;
this.setValues();
},
}, areaList: {
type: Object,
value: {},
observer: 'setValues',
}, columnsNum: {
type: null,
value: 3,
}, columnsPlaceholder: {
type: Array,
observer: function (val) {
this.setData({
typeToColumnsPlaceholder: {
province: val[0] || '',
city: val[1] || '',
county: val[2] || '',
},
});
},
} }),
data: {
columns: [{ values: [] }, { values: [] }, { values: [] }],
typeToColumnsPlaceholder: {},
},
mounted: function () {
var _this = this;
(0, utils_1.requestAnimationFrame)(function () {
_this.setValues();
});
},
methods: {
getPicker: function () {
if (this.picker == null) {
this.picker = this.selectComponent('.van-area__picker');
}
return this.picker;
},
onCancel: function (event) {
this.emit('cancel', event.detail);
},
onConfirm: function (event) {
var index = event.detail.index;
var value = event.detail.value;
value = this.parseValues(value);
this.emit('confirm', { value: value, index: index });
},
emit: function (type, detail) {
detail.values = detail.value;
delete detail.value;
this.$emit(type, detail);
},
parseValues: function (values) {
var columnsPlaceholder = this.data.columnsPlaceholder;
return values.map(function (value, index) {
if (value &&
(!value.code || value.name === columnsPlaceholder[index])) {
return __assign(__assign({}, value), { code: '', name: '' });
}
return value;
});
},
onChange: function (event) {
var _this = this;
var _a;
var _b = event.detail, index = _b.index, picker = _b.picker, value = _b.value;
this.code = value[index].code;
(_a = this.setValues()) === null || _a === void 0 ? void 0 : _a.then(function () {
_this.$emit('change', {
picker: picker,
values: _this.parseValues(picker.getValues()),
index: index,
});
});
},
getConfig: function (type) {
var areaList = this.data.areaList;
return (areaList && areaList[type + "_list"]) || {};
},
getList: function (type, code) {
if (type !== 'province' && !code) {
return [];
}
var typeToColumnsPlaceholder = this.data.typeToColumnsPlaceholder;
var list = this.getConfig(type);
var result = Object.keys(list).map(function (code) { return ({
code: code,
name: list[code],
}); });
if (code != null) {
// oversea code
if (code[0] === '9' && type === 'city') {
code = '9';
}
result = result.filter(function (item) { return item.code.indexOf(code) === 0; });
}
if (typeToColumnsPlaceholder[type] && result.length) {
// set columns placeholder
var codeFill = type === 'province'
? ''
: type === 'city'
? EMPTY_CODE.slice(2, 4)
: EMPTY_CODE.slice(4, 6);
result.unshift({
code: "" + code + codeFill,
name: typeToColumnsPlaceholder[type],
});
}
return result;
},
getIndex: function (type, code) {
var compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
var list = this.getList(type, code.slice(0, compareNum - 2));
// oversea code
if (code[0] === '9' && type === 'province') {
compareNum = 1;
}
code = code.slice(0, compareNum);
for (var i = 0; i < list.length; i++) {
if (list[i].code.slice(0, compareNum) === code) {
return i;
}
}
return 0;
},
setValues: function () {
var picker = this.getPicker();
if (!picker) {
return;
}
var code = this.code || this.getDefaultCode();
var provinceList = this.getList('province');
var cityList = this.getList('city', code.slice(0, 2));
var stack = [];
var indexes = [];
var columnsNum = this.data.columnsNum;
if (columnsNum >= 1) {
stack.push(picker.setColumnValues(0, provinceList, false));
indexes.push(this.getIndex('province', code));
}
if (columnsNum >= 2) {
stack.push(picker.setColumnValues(1, cityList, false));
indexes.push(this.getIndex('city', code));
if (cityList.length && code.slice(2, 4) === '00') {
code = cityList[0].code;
}
}
if (columnsNum === 3) {
stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false));
indexes.push(this.getIndex('county', code));
}
return Promise.all(stack)
.catch(function () { })
.then(function () { return picker.setIndexes(indexes); })
.catch(function () { });
},
getDefaultCode: function () {
var columnsPlaceholder = this.data.columnsPlaceholder;
if (columnsPlaceholder.length) {
return EMPTY_CODE;
}
var countyCodes = Object.keys(this.getConfig('county'));
if (countyCodes[0]) {
return countyCodes[0];
}
var cityCodes = Object.keys(this.getConfig('city'));
if (cityCodes[0]) {
return cityCodes[0];
}
return '';
},
getValues: function () {
var picker = this.getPicker();
if (!picker) {
return [];
}
return this.parseValues(picker.getValues().filter(function (value) { return !!value; }));
},
getDetail: function () {
var values = this.getValues();
var area = {
code: '',
country: '',
province: '',
city: '',
county: '',
};
if (!values.length) {
return area;
}
var names = values.map(function (item) { return item.name; });
area.code = values[values.length - 1].code;
if (area.code[0] === '9') {
area.country = names[1] || '';
area.province = names[2] || '';
}
else {
area.province = names[0] || '';
area.city = names[1] || '';
area.county = names[2] || '';
}
return area;
},
reset: function (code) {
this.code = code || '';
return this.setValues();
},
},
});

@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"van-picker": "../picker/index"
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save