Merge branch 'master' of gitee.com:iot_camp/wumei-smart
12
wechat/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# 云开发 quickstart
|
||||||
|
|
||||||
|
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
|
||||||
|
|
||||||
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
||||||
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
||||||
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
||||||
|
|
||||||
|
## 参考文档
|
||||||
|
|
||||||
|
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
|
||||||
|
|
||||||
7
wechat/cloudfunctions/callback/config.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
"customerServiceMessage.send"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
25
wechat/cloudfunctions/callback/index.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
// API 调用都保持和云函数当前所在环境一致
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
})
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
console.log(event)
|
||||||
|
|
||||||
|
const { OPENID } = cloud.getWXContext()
|
||||||
|
|
||||||
|
const result = await cloud.openapi.customerServiceMessage.send({
|
||||||
|
touser: OPENID,
|
||||||
|
msgtype: 'text',
|
||||||
|
text: {
|
||||||
|
content: `收到:${event.Content}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(result)
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
14
wechat/cloudfunctions/callback/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "callback",
|
||||||
|
"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.5.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
wechat/cloudfunctions/echo/config.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": []
|
||||||
|
}
|
||||||
|
}
|
||||||
8
wechat/cloudfunctions/echo/index.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// event.userInfo 是已废弃的保留字段,在此不做展示
|
||||||
|
// 获取 OPENID 等微信上下文请使用 cloud.getWXContext()
|
||||||
|
delete event.userInfo
|
||||||
|
return event
|
||||||
|
}
|
||||||
14
wechat/cloudfunctions/echo/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "echo",
|
||||||
|
"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.5.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
wechat/cloudfunctions/login/config.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": []
|
||||||
|
}
|
||||||
|
}
|
||||||
36
wechat/cloudfunctions/login/index.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// 云函数模板
|
||||||
|
// 部署:在 cloud-functions/login 文件夹右击选择 “上传并部署”
|
||||||
|
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
// 初始化 cloud
|
||||||
|
cloud.init({
|
||||||
|
// API 调用都保持和云函数当前所在环境一致
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个示例将经自动鉴权过的小程序用户 openid 返回给小程序端
|
||||||
|
*
|
||||||
|
* event 参数包含小程序端调用传入的 data
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
console.log(event)
|
||||||
|
console.log(context)
|
||||||
|
|
||||||
|
// 可执行其他自定义逻辑
|
||||||
|
// console.log 的内容可以在云开发云函数调用日志查看
|
||||||
|
|
||||||
|
// 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)等信息
|
||||||
|
const wxContext = cloud.getWXContext()
|
||||||
|
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
openid: wxContext.OPENID,
|
||||||
|
appid: wxContext.APPID,
|
||||||
|
unionid: wxContext.UNIONID,
|
||||||
|
env: wxContext.ENV,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
14
wechat/cloudfunctions/login/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "login",
|
||||||
|
"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.5.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
wechat/cloudfunctions/openapi/config.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
"wxacode.get",
|
||||||
|
"subscribeMessage.send",
|
||||||
|
"subscribeMessage.addTemplate",
|
||||||
|
"templateMessage.send",
|
||||||
|
"templateMessage.addTemplate",
|
||||||
|
"templateMessage.deleteTemplate",
|
||||||
|
"templateMessage.getTemplateList",
|
||||||
|
"templateMessage.getTemplateLibraryById",
|
||||||
|
"templateMessage.getTemplateLibraryList"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
86
wechat/cloudfunctions/openapi/index.js
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
cloud.init()
|
||||||
|
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
console.log(event)
|
||||||
|
switch (event.action) {
|
||||||
|
case 'requestSubscribeMessage': {
|
||||||
|
return requestSubscribeMessage(event)
|
||||||
|
}
|
||||||
|
case 'sendSubscribeMessage': {
|
||||||
|
return sendSubscribeMessage(event)
|
||||||
|
}
|
||||||
|
case 'getWXACode': {
|
||||||
|
return getWXACode(event)
|
||||||
|
}
|
||||||
|
case 'getOpenData': {
|
||||||
|
return getOpenData(event)
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requestSubscribeMessage(event) {
|
||||||
|
// 此处为模板 ID,开发者需要到小程序管理后台 - 订阅消息 - 公共模板库中添加模板,
|
||||||
|
// 然后在我的模板中找到对应模板的 ID,填入此处
|
||||||
|
return '请到管理后台申请模板 ID 然后在此替换' // 如 'N_J6F05_bjhqd6zh2h1LHJ9TAv9IpkCiAJEpSw0PrmQ'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendSubscribeMessage(event) {
|
||||||
|
const { OPENID } = cloud.getWXContext()
|
||||||
|
|
||||||
|
const { templateId } = event
|
||||||
|
|
||||||
|
const sendResult = await cloud.openapi.subscribeMessage.send({
|
||||||
|
touser: OPENID,
|
||||||
|
templateId,
|
||||||
|
miniprogram_state: 'developer',
|
||||||
|
page: 'pages/openapi/openapi',
|
||||||
|
// 此处字段应修改为所申请模板所要求的字段
|
||||||
|
data: {
|
||||||
|
thing1: {
|
||||||
|
value: '咖啡',
|
||||||
|
},
|
||||||
|
time3: {
|
||||||
|
value: '2020-01-01 00:00',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return sendResult
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getWXACode(event) {
|
||||||
|
// 此处将获取永久有效的小程序码,并将其保存在云文件存储中,最后返回云文件 ID 给前端使用
|
||||||
|
|
||||||
|
const wxacodeResult = await cloud.openapi.wxacode.get({
|
||||||
|
path: 'pages/openapi/openapi',
|
||||||
|
})
|
||||||
|
|
||||||
|
const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^/]+)/)
|
||||||
|
const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'
|
||||||
|
|
||||||
|
const uploadResult = await cloud.uploadFile({
|
||||||
|
// 云文件路径,此处为演示采用一个固定名称
|
||||||
|
cloudPath: `wxacode_default_openapi_page.${fileExtension}`,
|
||||||
|
// 要上传的文件内容可直接传入图片 Buffer
|
||||||
|
fileContent: wxacodeResult.buffer,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!uploadResult.fileID) {
|
||||||
|
throw new Error(`upload failed with empty fileID and storage server status code ${uploadResult.statusCode}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return uploadResult.fileID
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOpenData(event) {
|
||||||
|
return cloud.getOpenData({
|
||||||
|
list: event.openData.list,
|
||||||
|
})
|
||||||
|
}
|
||||||
14
wechat/cloudfunctions/openapi/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "openapi",
|
||||||
|
"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.5.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
43
wechat/miniprogram/API/request.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
const baseURL = 'http://106.12.9.213:80/prod-api';
|
||||||
|
const token = wx.getStorageSync('token') || '';
|
||||||
|
|
||||||
|
const loginApi = (url, params = {} ) => {
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
wx.request({
|
||||||
|
url:baseURL+url,
|
||||||
|
...params,
|
||||||
|
success:(res)=>{
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail:(err) => {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestApi = ( url, params={} ) => {
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
wx.request({
|
||||||
|
url:baseURL+url,
|
||||||
|
...params,
|
||||||
|
header:{
|
||||||
|
"Authorization":token
|
||||||
|
},
|
||||||
|
success:(res)=>{
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail:(err) => {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports={
|
||||||
|
loginApi,
|
||||||
|
requestApi
|
||||||
|
}
|
||||||
38
wechat/miniprogram/app.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//app.js
|
||||||
|
import { request } from "./utils/request.js";
|
||||||
|
|
||||||
|
App({
|
||||||
|
onLaunch:async function () {
|
||||||
|
|
||||||
|
// const res =await request('ag-api.ctwing.cn/aep_product_management/products','GET',20190507004824,
|
||||||
|
// {
|
||||||
|
// 'searchValue':'',
|
||||||
|
// 'pageSize':'',
|
||||||
|
// 'pageNow':''
|
||||||
|
// });
|
||||||
|
// const res = await request('ag-api.ctwing.cn/aep_device_management/device','PUT',20181031202122,
|
||||||
|
// {'MasterKey':'f9ceed06f3374bb28cfc0083e2899bac',
|
||||||
|
// 'deviceId':'15058943ssdhhsnfvvf23'
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "deviceName": "ssd",
|
||||||
|
// "operator": "qll",
|
||||||
|
// "productId": 15058943
|
||||||
|
// })
|
||||||
|
|
||||||
|
if (!wx.cloud) {
|
||||||
|
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
|
||||||
|
} else {
|
||||||
|
wx.cloud.init({
|
||||||
|
// env 参数说明:
|
||||||
|
// env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
|
||||||
|
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
|
||||||
|
// 如不填则使用默认环境(第一个创建的环境)
|
||||||
|
env: 'mmydev-1ge33h7a9c3abf3fy-env-id',
|
||||||
|
traceUser: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.globalData = {}
|
||||||
|
}
|
||||||
|
})
|
||||||
20
wechat/miniprogram/app.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
"pages/index/index",
|
||||||
|
"pages/login/index",
|
||||||
|
"pages/roomSystem/index"
|
||||||
|
],
|
||||||
|
"window": {
|
||||||
|
"backgroundColor": "#F6F6F6",
|
||||||
|
"backgroundTextStyle": "light",
|
||||||
|
"navigationBarBackgroundColor": "#F6F6F6",
|
||||||
|
"navigationBarTitleText": "智慧宿舍",
|
||||||
|
"navigationBarTextStyle": "black"
|
||||||
|
},
|
||||||
|
"sitemapLocation": "sitemap.json",
|
||||||
|
"permission": {
|
||||||
|
"scope.userLocation": {
|
||||||
|
"desc": "你的位置信息将用于小程序位置接口的效果展示"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
156
wechat/miniprogram/app.wxss
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
/**app.wxss**/
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
background: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:focus{
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button::after{
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
page {
|
||||||
|
background: #f6f6f6;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo, .uploader, .tunnel {
|
||||||
|
margin-top: 40rpx;
|
||||||
|
height: 140rpx;
|
||||||
|
width: 100%;
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
transition: all 300ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo-avatar {
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
margin: 20rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-size: cover;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo-avatar:after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo-nickname {
|
||||||
|
font-size: 32rpx;
|
||||||
|
color: #007aff;
|
||||||
|
background-color: white;
|
||||||
|
background-size: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userinfo-nickname::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploader, .tunnel {
|
||||||
|
height: auto;
|
||||||
|
padding: 0 0 0 40rpx;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploader-text, .tunnel-text {
|
||||||
|
width: 100%;
|
||||||
|
line-height: 52px;
|
||||||
|
font-size: 34rpx;
|
||||||
|
color: #007aff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploader-container {
|
||||||
|
width: 100%;
|
||||||
|
height: 400rpx;
|
||||||
|
padding: 20rpx 20rpx 20rpx 0;
|
||||||
|
display: flex;
|
||||||
|
align-content: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploader-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 360rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tunnel {
|
||||||
|
padding: 0 0 0 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tunnel-text {
|
||||||
|
position: relative;
|
||||||
|
color: #222;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-content: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tunnel-text:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tunnel-switch {
|
||||||
|
position: absolute;
|
||||||
|
right: 20rpx;
|
||||||
|
top: -2rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disable {
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service {
|
||||||
|
position: fixed;
|
||||||
|
right: 40rpx;
|
||||||
|
bottom: 40rpx;
|
||||||
|
width: 140rpx;
|
||||||
|
height: 140rpx;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: linear-gradient(#007aff, #0063ce);
|
||||||
|
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
|
||||||
|
display: flex;
|
||||||
|
align-content: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: all 300ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-button {
|
||||||
|
position: absolute;
|
||||||
|
top: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.service:active {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-text {
|
||||||
|
padding: 20rpx 0;
|
||||||
|
font-size: 24rpx;
|
||||||
|
line-height: 36rpx;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
337
wechat/miniprogram/components/chatroom/chatroom.js
Normal file
@@ -0,0 +1,337 @@
|
|||||||
|
const FATAL_REBUILD_TOLERANCE = 10
|
||||||
|
const SETDATA_SCROLL_TO_BOTTOM = {
|
||||||
|
scrollTop: 100000,
|
||||||
|
scrollWithAnimation: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
Component({
|
||||||
|
properties: {
|
||||||
|
envId: String,
|
||||||
|
collection: String,
|
||||||
|
groupId: String,
|
||||||
|
groupName: String,
|
||||||
|
userInfo: Object,
|
||||||
|
onGetUserInfo: {
|
||||||
|
type: Function,
|
||||||
|
},
|
||||||
|
getOpenID: {
|
||||||
|
type: Function,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data: {
|
||||||
|
chats: [],
|
||||||
|
textInputValue: '',
|
||||||
|
openId: '',
|
||||||
|
scrollTop: 0,
|
||||||
|
scrollToMessage: '',
|
||||||
|
hasKeyboard: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onGetUserInfo(e) {
|
||||||
|
this.properties.onGetUserInfo(e)
|
||||||
|
},
|
||||||
|
|
||||||
|
getOpenID() {
|
||||||
|
return this.properties.getOpenID()
|
||||||
|
},
|
||||||
|
|
||||||
|
mergeCommonCriteria(criteria) {
|
||||||
|
return {
|
||||||
|
groupId: this.data.groupId,
|
||||||
|
...criteria,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async initRoom() {
|
||||||
|
this.try(async () => {
|
||||||
|
await this.initOpenID()
|
||||||
|
|
||||||
|
const { envId, collection } = this.properties
|
||||||
|
this.db = wx.cloud.database({
|
||||||
|
env: envId,
|
||||||
|
})
|
||||||
|
const db = this.db
|
||||||
|
const _ = db.command
|
||||||
|
|
||||||
|
const { data: initList } = await db.collection(collection).where(this.mergeCommonCriteria()).orderBy('sendTimeTS', 'desc').get()
|
||||||
|
|
||||||
|
console.log('init query chats', initList)
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
chats: initList.reverse(),
|
||||||
|
scrollTop: 10000,
|
||||||
|
})
|
||||||
|
|
||||||
|
this.initWatch(initList.length ? {
|
||||||
|
sendTimeTS: _.gt(initList[initList.length - 1].sendTimeTS),
|
||||||
|
} : {})
|
||||||
|
}, '初始化失败')
|
||||||
|
},
|
||||||
|
|
||||||
|
async initOpenID() {
|
||||||
|
return this.try(async () => {
|
||||||
|
const openId = await this.getOpenID()
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
openId,
|
||||||
|
})
|
||||||
|
}, '初始化 openId 失败')
|
||||||
|
},
|
||||||
|
|
||||||
|
async initWatch(criteria) {
|
||||||
|
this.try(() => {
|
||||||
|
const { collection } = this.properties
|
||||||
|
const db = this.db
|
||||||
|
const _ = db.command
|
||||||
|
|
||||||
|
console.warn(`开始监听`, criteria)
|
||||||
|
this.messageListener = db.collection(collection).where(this.mergeCommonCriteria(criteria)).watch({
|
||||||
|
onChange: this.onRealtimeMessageSnapshot.bind(this),
|
||||||
|
onError: e => {
|
||||||
|
if (!this.inited || this.fatalRebuildCount >= FATAL_REBUILD_TOLERANCE) {
|
||||||
|
this.showError(this.inited ? '监听错误,已断开' : '初始化监听失败', e, '重连', () => {
|
||||||
|
this.initWatch(this.data.chats.length ? {
|
||||||
|
sendTimeTS: _.gt(this.data.chats[this.data.chats.length - 1].sendTimeTS),
|
||||||
|
} : {})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.initWatch(this.data.chats.length ? {
|
||||||
|
sendTimeTS: _.gt(this.data.chats[this.data.chats.length - 1].sendTimeTS),
|
||||||
|
} : {})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}, '初始化监听失败')
|
||||||
|
},
|
||||||
|
|
||||||
|
onRealtimeMessageSnapshot(snapshot) {
|
||||||
|
console.warn(`收到消息`, snapshot)
|
||||||
|
|
||||||
|
if (snapshot.type === 'init') {
|
||||||
|
this.setData({
|
||||||
|
chats: [
|
||||||
|
...this.data.chats,
|
||||||
|
...[...snapshot.docs].sort((x, y) => x.sendTimeTS - y.sendTimeTS),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
this.scrollToBottom()
|
||||||
|
this.inited = true
|
||||||
|
} else {
|
||||||
|
let hasNewMessage = false
|
||||||
|
let hasOthersMessage = false
|
||||||
|
const chats = [...this.data.chats]
|
||||||
|
for (const docChange of snapshot.docChanges) {
|
||||||
|
switch (docChange.queueType) {
|
||||||
|
case 'enqueue': {
|
||||||
|
hasOthersMessage = docChange.doc._openid !== this.data.openId
|
||||||
|
const ind = chats.findIndex(chat => chat._id === docChange.doc._id)
|
||||||
|
if (ind > -1) {
|
||||||
|
if (chats[ind].msgType === 'image' && chats[ind].tempFilePath) {
|
||||||
|
chats.splice(ind, 1, {
|
||||||
|
...docChange.doc,
|
||||||
|
tempFilePath: chats[ind].tempFilePath,
|
||||||
|
})
|
||||||
|
} else chats.splice(ind, 1, docChange.doc)
|
||||||
|
} else {
|
||||||
|
hasNewMessage = true
|
||||||
|
chats.push(docChange.doc)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setData({
|
||||||
|
chats: chats.sort((x, y) => x.sendTimeTS - y.sendTimeTS),
|
||||||
|
})
|
||||||
|
if (hasOthersMessage || hasNewMessage) {
|
||||||
|
this.scrollToBottom()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async onConfirmSendText(e) {
|
||||||
|
this.try(async () => {
|
||||||
|
if (!e.detail.value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { collection } = this.properties
|
||||||
|
const db = this.db
|
||||||
|
const _ = db.command
|
||||||
|
|
||||||
|
const doc = {
|
||||||
|
_id: `${Math.random()}_${Date.now()}`,
|
||||||
|
groupId: this.data.groupId,
|
||||||
|
avatar: this.data.userInfo.avatarUrl,
|
||||||
|
nickName: this.data.userInfo.nickName,
|
||||||
|
msgType: 'text',
|
||||||
|
textContent: e.detail.value,
|
||||||
|
sendTime: new Date(),
|
||||||
|
sendTimeTS: Date.now(), // fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
textInputValue: '',
|
||||||
|
chats: [
|
||||||
|
...this.data.chats,
|
||||||
|
{
|
||||||
|
...doc,
|
||||||
|
_openid: this.data.openId,
|
||||||
|
writeStatus: 'pending',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
this.scrollToBottom(true)
|
||||||
|
|
||||||
|
await db.collection(collection).add({
|
||||||
|
data: doc,
|
||||||
|
})
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
chats: this.data.chats.map(chat => {
|
||||||
|
if (chat._id === doc._id) {
|
||||||
|
return {
|
||||||
|
...chat,
|
||||||
|
writeStatus: 'written',
|
||||||
|
}
|
||||||
|
} else return chat
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}, '发送文字失败')
|
||||||
|
},
|
||||||
|
|
||||||
|
async onChooseImage(e) {
|
||||||
|
wx.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
sourceType: ['album', 'camera'],
|
||||||
|
success: async res => {
|
||||||
|
const { envId, collection } = this.properties
|
||||||
|
const doc = {
|
||||||
|
_id: `${Math.random()}_${Date.now()}`,
|
||||||
|
groupId: this.data.groupId,
|
||||||
|
avatar: this.data.userInfo.avatarUrl,
|
||||||
|
nickName: this.data.userInfo.nickName,
|
||||||
|
msgType: 'image',
|
||||||
|
sendTime: new Date(),
|
||||||
|
sendTimeTS: Date.now(), // fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
chats: [
|
||||||
|
...this.data.chats,
|
||||||
|
{
|
||||||
|
...doc,
|
||||||
|
_openid: this.data.openId,
|
||||||
|
tempFilePath: res.tempFilePaths[0],
|
||||||
|
writeStatus: 0,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
this.scrollToBottom(true)
|
||||||
|
|
||||||
|
const uploadTask = wx.cloud.uploadFile({
|
||||||
|
cloudPath: `${this.data.openId}/${Math.random()}_${Date.now()}.${res.tempFilePaths[0].match(/\.(\w+)$/)[1]}`,
|
||||||
|
filePath: res.tempFilePaths[0],
|
||||||
|
config: {
|
||||||
|
env: envId,
|
||||||
|
},
|
||||||
|
success: res => {
|
||||||
|
this.try(async () => {
|
||||||
|
await this.db.collection(collection).add({
|
||||||
|
data: {
|
||||||
|
...doc,
|
||||||
|
imgFileID: res.fileID,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}, '发送图片失败')
|
||||||
|
},
|
||||||
|
fail: e => {
|
||||||
|
this.showError('发送图片失败', e)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
uploadTask.onProgressUpdate(({ progress }) => {
|
||||||
|
this.setData({
|
||||||
|
chats: this.data.chats.map(chat => {
|
||||||
|
if (chat._id === doc._id) {
|
||||||
|
return {
|
||||||
|
...chat,
|
||||||
|
writeStatus: progress,
|
||||||
|
}
|
||||||
|
} else return chat
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onMessageImageTap(e) {
|
||||||
|
wx.previewImage({
|
||||||
|
urls: [e.target.dataset.fileid],
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
scrollToBottom(force) {
|
||||||
|
if (force) {
|
||||||
|
console.log('force scroll to bottom')
|
||||||
|
this.setData(SETDATA_SCROLL_TO_BOTTOM)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.createSelectorQuery().select('.body').boundingClientRect(bodyRect => {
|
||||||
|
this.createSelectorQuery().select(`.body`).scrollOffset(scroll => {
|
||||||
|
if (scroll.scrollTop + bodyRect.height * 3 > scroll.scrollHeight) {
|
||||||
|
console.log('should scroll to bottom')
|
||||||
|
this.setData(SETDATA_SCROLL_TO_BOTTOM)
|
||||||
|
}
|
||||||
|
}).exec()
|
||||||
|
}).exec()
|
||||||
|
},
|
||||||
|
|
||||||
|
async onScrollToUpper() {
|
||||||
|
if (this.db && this.data.chats.length) {
|
||||||
|
const { collection } = this.properties
|
||||||
|
const _ = this.db.command
|
||||||
|
const { data } = await this.db.collection(collection).where(this.mergeCommonCriteria({
|
||||||
|
sendTimeTS: _.lt(this.data.chats[0].sendTimeTS),
|
||||||
|
})).orderBy('sendTimeTS', 'desc').get()
|
||||||
|
this.data.chats.unshift(...data.reverse())
|
||||||
|
this.setData({
|
||||||
|
chats: this.data.chats,
|
||||||
|
scrollToMessage: `item-${data.length}`,
|
||||||
|
scrollWithAnimation: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async try(fn, title) {
|
||||||
|
try {
|
||||||
|
await fn()
|
||||||
|
} catch (e) {
|
||||||
|
this.showError(title, e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showError(title, content, confirmText, confirmCallback) {
|
||||||
|
console.error(title, content)
|
||||||
|
wx.showModal({
|
||||||
|
title,
|
||||||
|
content: content.toString(),
|
||||||
|
showCancel: confirmText ? true : false,
|
||||||
|
confirmText,
|
||||||
|
success: res => {
|
||||||
|
res.confirm && confirmCallback()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
ready() {
|
||||||
|
global.chatroom = this
|
||||||
|
this.initRoom()
|
||||||
|
this.fatalRebuildCount = 0
|
||||||
|
},
|
||||||
|
})
|
||||||
4
wechat/miniprogram/components/chatroom/chatroom.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {}
|
||||||
|
}
|
||||||
85
wechat/miniprogram/components/chatroom/chatroom.wxml
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<view class="chatroom">
|
||||||
|
<view class="header">
|
||||||
|
<!-- display number of people in the room -->
|
||||||
|
<view class="left"></view>
|
||||||
|
<!-- room name -->
|
||||||
|
<view class="middle">{{groupName}}</view>
|
||||||
|
<!-- reserved -->
|
||||||
|
<view class="right"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- chats -->
|
||||||
|
<scroll-view
|
||||||
|
class="body"
|
||||||
|
scroll-y
|
||||||
|
scroll-with-animation="{{scrollWithAnimation}}"
|
||||||
|
scroll-top="{{scrollTop}}"
|
||||||
|
scroll-into-view="{{scrollToMessage}}"
|
||||||
|
bindscrolltoupper="onScrollToUpper"
|
||||||
|
>
|
||||||
|
<view
|
||||||
|
wx:for="{{chats}}"
|
||||||
|
wx:key="{{item._id}}"
|
||||||
|
id="item-{{index}}"
|
||||||
|
class="message {{openId == item._openid ? 'message__self' : ''}}"
|
||||||
|
>
|
||||||
|
<image
|
||||||
|
class="avatar"
|
||||||
|
src="{{item.avatar}}"
|
||||||
|
mode="scaleToFill"
|
||||||
|
></image>
|
||||||
|
<view class="main">
|
||||||
|
<view class="nickname">{{item.nickName}}</view>
|
||||||
|
<block wx:if="{{item.msgType === 'image'}}">
|
||||||
|
<view class="image-wrapper">
|
||||||
|
<view class="loading" wx:if="{{item.writeStatus > -1}}">{{item.writeStatus}}%</view>
|
||||||
|
<image
|
||||||
|
src="{{item.tempFilePath || item.imgFileID}}"
|
||||||
|
data-fileid="{{item.tempFilePath || item.imgFileID}}"
|
||||||
|
class="image-content"
|
||||||
|
style="{{item.imgStyle}}"
|
||||||
|
mode="scallToFill"
|
||||||
|
bindtap="onMessageImageTap"></image>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
<block wx:else>
|
||||||
|
<view class="text-wrapper">
|
||||||
|
<view class="loading" wx:if="{{item.writeStatus === 'pending'}}">···</view>
|
||||||
|
<view class="text-content">{{item.textContent}}</view>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<!-- message sender -->
|
||||||
|
<view class="footer">
|
||||||
|
<view class="message-sender" wx:if="{{userInfo}}">
|
||||||
|
<input
|
||||||
|
class="text-input"
|
||||||
|
type="text"
|
||||||
|
confirm-type="send"
|
||||||
|
bindconfirm="onConfirmSendText"
|
||||||
|
cursor-spacing="20"
|
||||||
|
value="{{textInputValue}}"
|
||||||
|
></input>
|
||||||
|
|
||||||
|
<image
|
||||||
|
src="./photo.png"
|
||||||
|
class="btn-send-image"
|
||||||
|
mode="scaleToFill"
|
||||||
|
bindtap="onChooseImage"
|
||||||
|
></image>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="message-sender" wx:if="{{!userInfo}}">
|
||||||
|
<button
|
||||||
|
open-type="getUserInfo"
|
||||||
|
bindgetuserinfo="onGetUserInfo"
|
||||||
|
class="userinfo"
|
||||||
|
>请先登录后参与聊天</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
|
||||||
161
wechat/miniprogram/components/chatroom/chatroom.wxss
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
.chatroom {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .header {
|
||||||
|
flex-basis: fit-content;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
padding: 20rpx 0 30rpx;
|
||||||
|
font-size: 30rpx;
|
||||||
|
/* background: rgb(34, 187, 47);
|
||||||
|
color: rgba(255, 255, 255, 1) */
|
||||||
|
/* font-family: 'Microsoft YaHei' */
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .header .left {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .header .middle {
|
||||||
|
flex: 2;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .header .right {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .body {
|
||||||
|
flex: 2;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: rgb(237,237,237);
|
||||||
|
padding-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
position: relative;
|
||||||
|
margin: 12rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message.message__self {
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .avatar {
|
||||||
|
position: relative;
|
||||||
|
top: 5rpx;
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
border-radius: 5rpx;
|
||||||
|
margin: 15rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .main {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message.message__self .main {
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .nickname {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .text-content {
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #fff;
|
||||||
|
margin: 2px 0 0 0;
|
||||||
|
padding: 4px 10px;
|
||||||
|
font-size: 30rpx;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message.message__self .text-content {
|
||||||
|
background-color: paleturquoise;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .text-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
max-width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message.message__self .text-wrapper .loading{
|
||||||
|
font-size: 16rpx;
|
||||||
|
margin-right: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .image-wrapper {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message .image-content {
|
||||||
|
max-width: 240rpx;
|
||||||
|
max-height: 240rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body .message.message__self .image-wrapper .loading {
|
||||||
|
font-size: 20rpx;
|
||||||
|
margin-right: 18rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .footer {
|
||||||
|
flex-basis: fit-content;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
font-size: 10rpx;
|
||||||
|
padding: 20rpx 30rpx;
|
||||||
|
background: rgb(246,246,246);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chatroom .footer .message-sender {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-sender .text-input {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 16px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
margin: 0 10px 0 5px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message-sender .btn-send-image {
|
||||||
|
width: 50rpx;
|
||||||
|
height: 50rpx;
|
||||||
|
align-self: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.userinfo {
|
||||||
|
background: darkturquoise;
|
||||||
|
color: aliceblue;
|
||||||
|
padding: 0 100rpx;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
BIN
wechat/miniprogram/components/chatroom/dots.gif
Normal file
|
After Width: | Height: | Size: 244 KiB |
BIN
wechat/miniprogram/components/chatroom/photo.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
wechat/miniprogram/icons/add.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
wechat/miniprogram/icons/close.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
wechat/miniprogram/icons/device.jpg
Normal file
|
After Width: | Height: | Size: 126 KiB |
BIN
wechat/miniprogram/icons/home.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
wechat/miniprogram/icons/home_selected.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
wechat/miniprogram/icons/open.png
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
wechat/miniprogram/icons/pwd.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
wechat/miniprogram/icons/route.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
wechat/miniprogram/icons/start.png
Normal file
|
After Width: | Height: | Size: 125 KiB |
BIN
wechat/miniprogram/icons/user.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
wechat/miniprogram/icons/user_selected.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
BIN
wechat/miniprogram/icons/wifi.png
Normal file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
wechat/miniprogram/images/curtain.png
Normal file
|
After Width: | Height: | Size: 498 B |
BIN
wechat/miniprogram/images/fan.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
wechat/miniprogram/images/power_off.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
wechat/miniprogram/images/power_on.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
wechat/miniprogram/images/room.jpeg
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
wechat/miniprogram/images/temp.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
1
wechat/miniprogram/libs/amap-wx.js
Normal file
117
wechat/miniprogram/libs/util.js
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
let rgb2hsl = function(r, g, b) {
|
||||||
|
r /= 255, g /= 255, b /= 255;
|
||||||
|
var max = Math.max(r, g, b),
|
||||||
|
min = Math.min(r, g, b);
|
||||||
|
var h, s, l = (max + min) / 2;
|
||||||
|
|
||||||
|
if (max == min) {
|
||||||
|
h = s = 0; // achromatic
|
||||||
|
} else {
|
||||||
|
var d = max - min;
|
||||||
|
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
||||||
|
switch (max) {
|
||||||
|
case r:
|
||||||
|
h = (g - b) / d + (g < b ? 6 : 0);
|
||||||
|
break;
|
||||||
|
case g:
|
||||||
|
h = (b - r) / d + 2;
|
||||||
|
break;
|
||||||
|
case b:
|
||||||
|
h = (r - g) / d + 4;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
h /= 6;
|
||||||
|
}
|
||||||
|
return [h, s, l];
|
||||||
|
}
|
||||||
|
|
||||||
|
let hslToRgb = function(h, s, l) {
|
||||||
|
var r, g, b;
|
||||||
|
if (s == 0) {
|
||||||
|
r = g = b = l; // achromatic
|
||||||
|
} else {
|
||||||
|
var hue2rgb = function hue2rgb(p, q, t) {
|
||||||
|
if (t < 0) t += 1;
|
||||||
|
if (t > 1) t -= 1;
|
||||||
|
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
||||||
|
if (t < 1 / 2) return q;
|
||||||
|
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||||
|
var p = 2 * l - q;
|
||||||
|
r = hue2rgb(p, q, h + 1 / 3);
|
||||||
|
g = hue2rgb(p, q, h);
|
||||||
|
b = hue2rgb(p, q, h - 1 / 3);
|
||||||
|
}
|
||||||
|
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
||||||
|
}
|
||||||
|
|
||||||
|
let drawRing = function(ctx, width, height) {
|
||||||
|
// 画圆环
|
||||||
|
var radius = width / 2;
|
||||||
|
var toRad = (2 * Math.PI) / 360;
|
||||||
|
var step = 0.1;
|
||||||
|
for (var i = 0; i < 360; i += step) {
|
||||||
|
var rad = i * toRad;
|
||||||
|
var color = hslToRgb(i / 360, 1, 0.5);
|
||||||
|
ctx.strokeStyle = `rgb(${color[0]},${color[1]},${color[2]})`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(radius, radius);
|
||||||
|
ctx.lineTo(radius + radius * Math.cos(rad), radius + radius * Math.sin(rad));
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||||
|
ctx.strokeStyle = 'rgb(0, 255, 255)';
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(radius, radius, radius * 0.65, 0, Math.PI * 2, true);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
ctx.draw();
|
||||||
|
};
|
||||||
|
|
||||||
|
let drawSlider = function(ctx, width, height, angle) {
|
||||||
|
var radius = width / 2;
|
||||||
|
|
||||||
|
ctx.save();
|
||||||
|
ctx.clearRect(0, 0, width, height);
|
||||||
|
ctx.translate(width / 2, height / 2);
|
||||||
|
|
||||||
|
var color = hslToRgb(angle, 1, 0.5);
|
||||||
|
|
||||||
|
ctx.fillStyle = `rgb(${color[0]},${color[1]},${color[2]})`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(0, 0, radius * 0.3, 0, Math.PI * 2, true);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.fill();
|
||||||
|
ctx.rotate((angle * 360) * Math.PI / 180);
|
||||||
|
|
||||||
|
ctx.beginPath()
|
||||||
|
ctx.setLineWidth(height * 0.015);
|
||||||
|
//圆心的 x 坐标 , 圆心的 Y 坐标 , 圆的半径
|
||||||
|
ctx.arc(height * 0.41, 0, 17, 0, 2 * Math.PI);
|
||||||
|
|
||||||
|
const grd = ctx.createCircularGradient(height * 0.41, 0, 17)
|
||||||
|
grd.addColorStop(0, '#fff');
|
||||||
|
grd.addColorStop(0.2, '#fff');
|
||||||
|
grd.addColorStop(.7, '#bfbfbf');
|
||||||
|
grd.addColorStop(1, '#666');
|
||||||
|
|
||||||
|
// Fill with gradient
|
||||||
|
ctx.setFillStyle(grd);
|
||||||
|
ctx.fill();
|
||||||
|
// ctx.strokeStyle = 'rgb(255, 255, 255)';
|
||||||
|
// ctx.stroke()
|
||||||
|
|
||||||
|
ctx.draw();
|
||||||
|
ctx.restore();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
rgb2hsl: rgb2hsl,
|
||||||
|
hslToRgb: hslToRgb,
|
||||||
|
drawRing: drawRing,
|
||||||
|
drawSlider: drawSlider,
|
||||||
|
}
|
||||||
8
wechat/miniprogram/libs/wx-promisify.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = api => (object, ...params) => new Promise((resolve, reject) => {
|
||||||
|
if (api) {
|
||||||
|
api.call(wx, { ...object, success: resolve, fail: reject }, ...params);
|
||||||
|
} else {
|
||||||
|
console.error('调用不支持的 API');
|
||||||
|
reject({ errCode: 'WXAPI_NOT_SUPPORTED' });
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
var button_1 = require('../mixins/button');
|
||||||
|
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{max-height:90%!important;max-height:var(--action-sheet-max-height,90%)!important;color:#323233;color:var(--action-sheet-item-text-color,#323233)}.van-action-sheet__cancel,.van-action-sheet__item{padding:14px 16px;text-align:center;font-size:16px;font-size:var(--action-sheet-item-font-size,16px);line-height:22px;line-height:var(--action-sheet-item-line-height,22px);background-color:#fff;background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5;background-color:var(--active-color,#f2f3f5)}.van-action-sheet__cancel:after,.van-action-sheet__item:after{border-width:0}.van-action-sheet__cancel{color:#646566;color:var(--action-sheet-cancel-text-color,#646566)}.van-action-sheet__gap{display:block;height:8px;height:var(--action-sheet-cancel-padding-top,8px);background-color:#f7f8fa;background-color:var(--action-sheet-cancel-padding-color,#f7f8fa)}.van-action-sheet__item--disabled{color:#c8c9cc;color:var(--action-sheet-item-disabled-text-color,#c8c9cc)}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:#fff;background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__subname{margin-top:8px;margin-top:var(--padding-xs,8px);font-size:12px;font-size:var(--action-sheet-subname-font-size,12px);color:#969799;color:var(--action-sheet-subname-color,#969799);line-height:20px;line-height:var(--action-sheet-subname-line-height,20px)}.van-action-sheet__header{text-align:center;font-weight:500;font-weight:var(--font-weight-bold,500);font-size:16px;font-size:var(--action-sheet-header-font-size,16px);line-height:48px;line-height:var(--action-sheet-header-height,48px)}.van-action-sheet__description{text-align:center;padding:20px 16px;padding:20px var(--padding-md,16px);color:#969799;color:var(--action-sheet-description-color,#969799);font-size:14px;font-size:var(--action-sheet-description-font-size,14px);line-height:20px;line-height:var(--action-sheet-description-line-height,20px)}.van-action-sheet__close{position:absolute!important;top:0;right:0;line-height:inherit!important;padding:0 16px;padding:var(--action-sheet-close-icon-padding,0 16px);font-size:22px!important;font-size:var(--action-sheet-close-icon-size,22px)!important;color:#c8c9cc;color:var(--action-sheet-close-icon-color,#c8c9cc)}.van-action-sheet__loading{display:-webkit-flex!important;display:flex!important}
|
||||||
266
wechat/miniprogram/miniprogram_npm/@vant/weapp/area/index.js
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
'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';
|
||||||
|
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;
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
|
||||||
|
<van-picker
|
||||||
|
class="van-area__picker"
|
||||||
|
active-class="active-class"
|
||||||
|
toolbar-class="toolbar-class"
|
||||||
|
column-class="column-class"
|
||||||
|
show-toolbar
|
||||||
|
value-key="name"
|
||||||
|
title="{{ title }}"
|
||||||
|
loading="{{ loading }}"
|
||||||
|
columns="{{ computed.displayColumns(columns, columnsNum) }}"
|
||||||
|
item-height="{{ itemHeight }}"
|
||||||
|
visible-item-count="{{ visibleItemCount }}"
|
||||||
|
cancel-button-text="{{ cancelButtonText }}"
|
||||||
|
confirm-button-text="{{ confirmButtonText }}"
|
||||||
|
bind:change="onChange"
|
||||||
|
bind:confirm="onConfirm"
|
||||||
|
bind:cancel="onCancel"
|
||||||
|
/>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
function displayColumns(columns, columnsNum) {
|
||||||
|
return columns.slice(0, +columnsNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
displayColumns: displayColumns,
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
var button_1 = require('../mixins/button');
|
||||||
|
var version_1 = require('../common/version');
|
||||||
|
var mixins = [button_1.button];
|
||||||
|
if (version_1.canIUseFormFieldButton()) {
|
||||||
|
mixins.push('wx://form-field-button');
|
||||||
|
}
|
||||||
|
component_1.VantComponent({
|
||||||
|
mixins: mixins,
|
||||||
|
classes: ['hover-class', 'loading-class'],
|
||||||
|
data: {
|
||||||
|
baseStyle: '',
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
formType: String,
|
||||||
|
icon: String,
|
||||||
|
classPrefix: {
|
||||||
|
type: String,
|
||||||
|
value: 'van-icon',
|
||||||
|
},
|
||||||
|
plain: Boolean,
|
||||||
|
block: Boolean,
|
||||||
|
round: Boolean,
|
||||||
|
square: Boolean,
|
||||||
|
loading: Boolean,
|
||||||
|
hairline: Boolean,
|
||||||
|
disabled: Boolean,
|
||||||
|
loadingText: String,
|
||||||
|
customStyle: String,
|
||||||
|
loadingType: {
|
||||||
|
type: String,
|
||||||
|
value: 'circular',
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
value: 'default',
|
||||||
|
},
|
||||||
|
dataset: null,
|
||||||
|
size: {
|
||||||
|
type: String,
|
||||||
|
value: 'normal',
|
||||||
|
},
|
||||||
|
loadingSize: {
|
||||||
|
type: String,
|
||||||
|
value: '20px',
|
||||||
|
},
|
||||||
|
color: String,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick: function (event) {
|
||||||
|
var _this = this;
|
||||||
|
this.$emit('click', event);
|
||||||
|
var _a = this.data,
|
||||||
|
canIUseGetUserProfile = _a.canIUseGetUserProfile,
|
||||||
|
openType = _a.openType,
|
||||||
|
getUserProfileDesc = _a.getUserProfileDesc;
|
||||||
|
if (openType === 'getUserInfo' && canIUseGetUserProfile) {
|
||||||
|
wx.getUserProfile({
|
||||||
|
desc: getUserProfileDesc || ' ',
|
||||||
|
complete: function (userProfile) {
|
||||||
|
_this.$emit('getuserinfo', userProfile);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"van-icon": "../icon/index",
|
||||||
|
"van-loading": "../loading/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
|
||||||
|
<button
|
||||||
|
id="{{ id }}"
|
||||||
|
data-detail="{{ dataset }}"
|
||||||
|
class="custom-class {{ utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]) }} {{ hairline ? 'van-hairline--surround' : '' }}"
|
||||||
|
hover-class="van-button--active hover-class"
|
||||||
|
lang="{{ lang }}"
|
||||||
|
form-type="{{ formType }}"
|
||||||
|
style="{{ computed.rootStyle({ plain, color, customStyle }) }}"
|
||||||
|
open-type="{{ disabled || loading || (canIUseGetUserProfile && openType === 'getUserInfo') ? '' : openType }}"
|
||||||
|
business-id="{{ businessId }}"
|
||||||
|
session-from="{{ sessionFrom }}"
|
||||||
|
send-message-title="{{ sendMessageTitle }}"
|
||||||
|
send-message-path="{{ sendMessagePath }}"
|
||||||
|
send-message-img="{{ sendMessageImg }}"
|
||||||
|
show-message-card="{{ showMessageCard }}"
|
||||||
|
app-parameter="{{ appParameter }}"
|
||||||
|
aria-label="{{ ariaLabel }}"
|
||||||
|
bindtap="{{ disabled || loading ? '' : 'onClick' }}"
|
||||||
|
bindgetuserinfo="onGetUserInfo"
|
||||||
|
bindcontact="onContact"
|
||||||
|
bindgetphonenumber="onGetPhoneNumber"
|
||||||
|
binderror="onError"
|
||||||
|
bindlaunchapp="onLaunchApp"
|
||||||
|
bindopensetting="onOpenSetting"
|
||||||
|
>
|
||||||
|
<block wx:if="{{ loading }}">
|
||||||
|
<van-loading
|
||||||
|
custom-class="loading-class"
|
||||||
|
size="{{ loadingSize }}"
|
||||||
|
type="{{ loadingType }}"
|
||||||
|
color="{{ computed.loadingColor({ type, color, plain }) }}"
|
||||||
|
/>
|
||||||
|
<view wx:if="{{ loadingText }}" class="van-button__loading-text">
|
||||||
|
{{ loadingText }}
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
<block wx:else>
|
||||||
|
<van-icon
|
||||||
|
wx:if="{{ icon }}"
|
||||||
|
size="1.2em"
|
||||||
|
name="{{ icon }}"
|
||||||
|
class-prefix="{{ classPrefix }}"
|
||||||
|
class="van-button__icon"
|
||||||
|
custom-style="line-height: inherit;"
|
||||||
|
/>
|
||||||
|
<view class="van-button__text">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
</button>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var style = require('../wxs/style.wxs');
|
||||||
|
|
||||||
|
function rootStyle(data) {
|
||||||
|
if (!data.color) {
|
||||||
|
return data.customStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = {
|
||||||
|
color: data.plain ? data.color : '#fff',
|
||||||
|
background: data.plain ? null : data.color,
|
||||||
|
};
|
||||||
|
|
||||||
|
// hide border when color is linear-gradient
|
||||||
|
if (data.color.indexOf('gradient') !== -1) {
|
||||||
|
properties.border = 0;
|
||||||
|
} else {
|
||||||
|
properties['border-color'] = data.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style([properties, data.customStyle]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadingColor(data) {
|
||||||
|
if (data.plain) {
|
||||||
|
return data.color ? data.color : '#c9c9c9';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.type === 'default') {
|
||||||
|
return '#c9c9c9';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '#fff';
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
rootStyle: rootStyle,
|
||||||
|
loadingColor: loadingColor,
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-button{position:relative;display:-webkit-inline-flex;display:inline-flex;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;box-sizing:border-box;padding:0;text-align:center;vertical-align:middle;-webkit-appearance:none;-webkit-text-size-adjust:100%;height:44px;height:var(--button-default-height,44px);line-height:20px;line-height:var(--button-line-height,20px);font-size:16px;font-size:var(--button-default-font-size,16px);transition:opacity .2s;transition:opacity var(--animation-duration-fast,.2s);border-radius:2px;border-radius:var(--button-border-radius,2px)}.van-button:before{position:absolute;top:50%;left:50%;width:100%;height:100%;border:inherit;border-radius:inherit;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);opacity:0;content:" ";background-color:#000;background-color:var(--black,#000);border-color:#000;border-color:var(--black,#000)}.van-button:after{border-width:0}.van-button--active:before{opacity:.15}.van-button--unclickable:after{display:none}.van-button--default{color:#323233;color:var(--button-default-color,#323233);background:#fff;background:var(--button-default-background-color,#fff);border:1px solid #ebedf0;border:var(--button-border-width,1px) solid var(--button-default-border-color,#ebedf0)}.van-button--primary{color:#fff;color:var(--button-primary-color,#fff);background:#07c160;background:var(--button-primary-background-color,#07c160);border:1px solid #07c160;border:var(--button-border-width,1px) solid var(--button-primary-border-color,#07c160)}.van-button--info{color:#fff;color:var(--button-info-color,#fff);background:#1989fa;background:var(--button-info-background-color,#1989fa);border:1px solid #1989fa;border:var(--button-border-width,1px) solid var(--button-info-border-color,#1989fa)}.van-button--danger{color:#fff;color:var(--button-danger-color,#fff);background:#ee0a24;background:var(--button-danger-background-color,#ee0a24);border:1px solid #ee0a24;border:var(--button-border-width,1px) solid var(--button-danger-border-color,#ee0a24)}.van-button--warning{color:#fff;color:var(--button-warning-color,#fff);background:#ff976a;background:var(--button-warning-background-color,#ff976a);border:1px solid #ff976a;border:var(--button-border-width,1px) solid var(--button-warning-border-color,#ff976a)}.van-button--plain{background:#fff;background:var(--button-plain-background-color,#fff)}.van-button--plain.van-button--primary{color:#07c160;color:var(--button-primary-background-color,#07c160)}.van-button--plain.van-button--info{color:#1989fa;color:var(--button-info-background-color,#1989fa)}.van-button--plain.van-button--danger{color:#ee0a24;color:var(--button-danger-background-color,#ee0a24)}.van-button--plain.van-button--warning{color:#ff976a;color:var(--button-warning-background-color,#ff976a)}.van-button--large{width:100%;height:50px;height:var(--button-large-height,50px)}.van-button--normal{padding:0 15px;font-size:14px;font-size:var(--button-normal-font-size,14px)}.van-button--small{min-width:60px;min-width:var(--button-small-min-width,60px);height:30px;height:var(--button-small-height,30px);padding:0 8px;padding:0 var(--padding-xs,8px);font-size:12px;font-size:var(--button-small-font-size,12px)}.van-button--mini{display:inline-block;min-width:50px;min-width:var(--button-mini-min-width,50px);height:22px;height:var(--button-mini-height,22px);font-size:10px;font-size:var(--button-mini-font-size,10px)}.van-button--mini+.van-button--mini{margin-left:5px}.van-button--block{display:-webkit-flex;display:flex;width:100%}.van-button--round{border-radius:999px;border-radius:var(--button-round-border-radius,999px)}.van-button--square{border-radius:0}.van-button--disabled{opacity:.5;opacity:var(--button-disabled-opacity,.5)}.van-button__text{display:inline}.van-button__icon+.van-button__text:not(:empty),.van-button__loading-text{margin-left:4px}.van-button__icon{min-width:1em;line-height:inherit!important;vertical-align:top}.van-button--hairline{padding-top:1px;border-width:0}.van-button--hairline:after{border-color:inherit;border-width:1px;border-radius:4px;border-radius:calc(var(--button-border-radius, 2px)*2)}.van-button--hairline.van-button--round:after{border-radius:999px;border-radius:var(--button-round-border-radius,999px)}.van-button--hairline.van-button--square:after{border-radius:0}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<view class="van-calendar">
|
||||||
|
<header
|
||||||
|
title="{{ title }}"
|
||||||
|
showTitle="{{ showTitle }}"
|
||||||
|
subtitle="{{ subtitle }}"
|
||||||
|
showSubtitle="{{ showSubtitle }}"
|
||||||
|
firstDayOfWeek="{{ firstDayOfWeek }}"
|
||||||
|
>
|
||||||
|
<slot name="title" slot="title"></slot>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<scroll-view
|
||||||
|
class="van-calendar__body"
|
||||||
|
scroll-y
|
||||||
|
scroll-into-view="{{ scrollIntoView }}"
|
||||||
|
>
|
||||||
|
<month
|
||||||
|
wx:for="{{ computed.getMonths(minDate, maxDate) }}"
|
||||||
|
wx:key="index"
|
||||||
|
id="month{{ index }}"
|
||||||
|
class="month"
|
||||||
|
data-date="{{ item }}"
|
||||||
|
date="{{ item }}"
|
||||||
|
type="{{ type }}"
|
||||||
|
color="{{ color }}"
|
||||||
|
minDate="{{ minDate }}"
|
||||||
|
maxDate="{{ maxDate }}"
|
||||||
|
showMark="{{ showMark }}"
|
||||||
|
formatter="{{ formatter }}"
|
||||||
|
rowHeight="{{ rowHeight }}"
|
||||||
|
currentDate="{{ currentDate }}"
|
||||||
|
showSubtitle="{{ showSubtitle }}"
|
||||||
|
allowSameDay="{{ allowSameDay }}"
|
||||||
|
showMonthTitle="{{ index !== 0 || !showSubtitle }}"
|
||||||
|
firstDayOfWeek="{{ firstDayOfWeek }}"
|
||||||
|
bind:click="onClickDay"
|
||||||
|
/>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
|
||||||
|
>
|
||||||
|
<slot name="footer"></slot>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
class="{{ utils.bem('calendar__footer', { safeAreaInsetBottom }) }}"
|
||||||
|
>
|
||||||
|
<van-button
|
||||||
|
wx:if="{{ showConfirm }}"
|
||||||
|
round
|
||||||
|
block
|
||||||
|
type="danger"
|
||||||
|
color="{{ color }}"
|
||||||
|
custom-class="van-calendar__confirm"
|
||||||
|
disabled="{{ computed.getButtonDisabled(type, currentDate) }}"
|
||||||
|
nativeType="text"
|
||||||
|
bind:click="onConfirm"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
computed.getButtonDisabled(type, currentDate)
|
||||||
|
? confirmDisabledText
|
||||||
|
: confirmText
|
||||||
|
}}
|
||||||
|
</van-button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
'use strict';
|
||||||
|
var __spreadArray =
|
||||||
|
(this && this.__spreadArray) ||
|
||||||
|
function (to, from) {
|
||||||
|
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||||
|
to[j] = from[i];
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../../../common/component');
|
||||||
|
component_1.VantComponent({
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
value: '日期选择',
|
||||||
|
},
|
||||||
|
subtitle: String,
|
||||||
|
showTitle: Boolean,
|
||||||
|
showSubtitle: Boolean,
|
||||||
|
firstDayOfWeek: {
|
||||||
|
type: Number,
|
||||||
|
observer: 'initWeekDay',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
weekdays: [],
|
||||||
|
},
|
||||||
|
created: function () {
|
||||||
|
this.initWeekDay();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
initWeekDay: function () {
|
||||||
|
var defaultWeeks = ['日', '一', '二', '三', '四', '五', '六'];
|
||||||
|
var firstDayOfWeek = this.data.firstDayOfWeek || 0;
|
||||||
|
this.setData({
|
||||||
|
weekdays: __spreadArray(
|
||||||
|
__spreadArray([], defaultWeeks.slice(firstDayOfWeek, 7)),
|
||||||
|
defaultWeeks.slice(0, firstDayOfWeek)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"component": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<view class="van-calendar__header">
|
||||||
|
<block wx:if="{{ showTitle }}">
|
||||||
|
<view class="van-calendar__header-title"><slot name="title"></slot></view>
|
||||||
|
<view class="van-calendar__header-title">{{ title }}</view>
|
||||||
|
</block>
|
||||||
|
|
||||||
|
<view wx:if="{{ showSubtitle }}" class="van-calendar__header-subtitle">
|
||||||
|
{{ subtitle }}
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="van-calendar__weekdays">
|
||||||
|
<view wx:for="{{ weekdays }}" wx:key="index" class="van-calendar__weekday">
|
||||||
|
{{ item }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../../../common/index.wxss';.van-calendar__header{-webkit-flex-shrink:0;flex-shrink:0;box-shadow:0 2px 10px rgba(125,126,128,.16);box-shadow:var(--calendar-header-box-shadow,0 2px 10px rgba(125,126,128,.16))}.van-calendar__header-subtitle,.van-calendar__header-title{text-align:center;height:44px;height:var(--calendar-header-title-height,44px);font-weight:500;font-weight:var(--font-weight-bold,500);line-height:44px;line-height:var(--calendar-header-title-height,44px)}.van-calendar__header-title+.van-calendar__header-title,.van-calendar__header-title:empty{display:none}.van-calendar__header-title:empty+.van-calendar__header-title{display:block!important}.van-calendar__weekdays{display:-webkit-flex;display:flex}.van-calendar__weekday{-webkit-flex:1;flex:1;text-align:center;font-size:12px;font-size:var(--calendar-weekdays-font-size,12px);line-height:30px;line-height:var(--calendar-weekdays-height,30px)}
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../../../common/component');
|
||||||
|
var utils_1 = require('../../utils');
|
||||||
|
component_1.VantComponent({
|
||||||
|
props: {
|
||||||
|
date: {
|
||||||
|
type: null,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
color: String,
|
||||||
|
minDate: {
|
||||||
|
type: null,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
maxDate: {
|
||||||
|
type: null,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
showMark: Boolean,
|
||||||
|
rowHeight: null,
|
||||||
|
formatter: {
|
||||||
|
type: null,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
currentDate: {
|
||||||
|
type: null,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
firstDayOfWeek: {
|
||||||
|
type: Number,
|
||||||
|
observer: 'setDays',
|
||||||
|
},
|
||||||
|
allowSameDay: Boolean,
|
||||||
|
showSubtitle: Boolean,
|
||||||
|
showMonthTitle: Boolean,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
visible: true,
|
||||||
|
days: [],
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick: function (event) {
|
||||||
|
var index = event.currentTarget.dataset.index;
|
||||||
|
var item = this.data.days[index];
|
||||||
|
if (item.type !== 'disabled') {
|
||||||
|
this.$emit('click', item);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setDays: function () {
|
||||||
|
var days = [];
|
||||||
|
var startDate = new Date(this.data.date);
|
||||||
|
var year = startDate.getFullYear();
|
||||||
|
var month = startDate.getMonth();
|
||||||
|
var totalDay = utils_1.getMonthEndDay(
|
||||||
|
startDate.getFullYear(),
|
||||||
|
startDate.getMonth() + 1
|
||||||
|
);
|
||||||
|
for (var day = 1; day <= totalDay; day++) {
|
||||||
|
var date = new Date(year, month, day);
|
||||||
|
var type = this.getDayType(date);
|
||||||
|
var config = {
|
||||||
|
date: date,
|
||||||
|
type: type,
|
||||||
|
text: day,
|
||||||
|
bottomInfo: this.getBottomInfo(type),
|
||||||
|
};
|
||||||
|
if (this.data.formatter) {
|
||||||
|
config = this.data.formatter(config);
|
||||||
|
}
|
||||||
|
days.push(config);
|
||||||
|
}
|
||||||
|
this.setData({ days: days });
|
||||||
|
},
|
||||||
|
getMultipleDayType: function (day) {
|
||||||
|
var currentDate = this.data.currentDate;
|
||||||
|
if (!Array.isArray(currentDate)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
var isSelected = function (date) {
|
||||||
|
return currentDate.some(function (item) {
|
||||||
|
return utils_1.compareDay(item, date) === 0;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
if (isSelected(day)) {
|
||||||
|
var prevDay = utils_1.getPrevDay(day);
|
||||||
|
var nextDay = utils_1.getNextDay(day);
|
||||||
|
var prevSelected = isSelected(prevDay);
|
||||||
|
var nextSelected = isSelected(nextDay);
|
||||||
|
if (prevSelected && nextSelected) {
|
||||||
|
return 'multiple-middle';
|
||||||
|
}
|
||||||
|
if (prevSelected) {
|
||||||
|
return 'end';
|
||||||
|
}
|
||||||
|
return nextSelected ? 'start' : 'multiple-selected';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
getRangeDayType: function (day) {
|
||||||
|
var _a = this.data,
|
||||||
|
currentDate = _a.currentDate,
|
||||||
|
allowSameDay = _a.allowSameDay;
|
||||||
|
if (!Array.isArray(currentDate)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
var startDay = currentDate[0],
|
||||||
|
endDay = currentDate[1];
|
||||||
|
if (!startDay) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
var compareToStart = utils_1.compareDay(day, startDay);
|
||||||
|
if (!endDay) {
|
||||||
|
return compareToStart === 0 ? 'start' : '';
|
||||||
|
}
|
||||||
|
var compareToEnd = utils_1.compareDay(day, endDay);
|
||||||
|
if (compareToStart === 0 && compareToEnd === 0 && allowSameDay) {
|
||||||
|
return 'start-end';
|
||||||
|
}
|
||||||
|
if (compareToStart === 0) {
|
||||||
|
return 'start';
|
||||||
|
}
|
||||||
|
if (compareToEnd === 0) {
|
||||||
|
return 'end';
|
||||||
|
}
|
||||||
|
if (compareToStart > 0 && compareToEnd < 0) {
|
||||||
|
return 'middle';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
getDayType: function (day) {
|
||||||
|
var _a = this.data,
|
||||||
|
type = _a.type,
|
||||||
|
minDate = _a.minDate,
|
||||||
|
maxDate = _a.maxDate,
|
||||||
|
currentDate = _a.currentDate;
|
||||||
|
if (
|
||||||
|
utils_1.compareDay(day, minDate) < 0 ||
|
||||||
|
utils_1.compareDay(day, maxDate) > 0
|
||||||
|
) {
|
||||||
|
return 'disabled';
|
||||||
|
}
|
||||||
|
if (type === 'single') {
|
||||||
|
return utils_1.compareDay(day, currentDate) === 0 ? 'selected' : '';
|
||||||
|
}
|
||||||
|
if (type === 'multiple') {
|
||||||
|
return this.getMultipleDayType(day);
|
||||||
|
}
|
||||||
|
/* istanbul ignore else */
|
||||||
|
if (type === 'range') {
|
||||||
|
return this.getRangeDayType(day);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
getBottomInfo: function (type) {
|
||||||
|
if (this.data.type === 'range') {
|
||||||
|
if (type === 'start') {
|
||||||
|
return '开始';
|
||||||
|
}
|
||||||
|
if (type === 'end') {
|
||||||
|
return '结束';
|
||||||
|
}
|
||||||
|
if (type === 'start-end') {
|
||||||
|
return '开始/结束';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"component": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<wxs src="./index.wxs" module="computed"></wxs>
|
||||||
|
<wxs src="../../../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
|
<view class="van-calendar__month" style="{{ computed.getMonthStyle(visible, date, rowHeight) }}">
|
||||||
|
<view wx:if="{{ showMonthTitle }}" class="van-calendar__month-title">
|
||||||
|
{{ computed.formatMonthTitle(date) }}
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{ visible }}" class="van-calendar__days">
|
||||||
|
<view wx:if="{{ showMark }}" class="van-calendar__month-mark">
|
||||||
|
{{ computed.getMark(date) }}
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view
|
||||||
|
wx:for="{{ days }}"
|
||||||
|
wx:key="index"
|
||||||
|
style="{{ computed.getDayStyle(item.type, index, date, rowHeight, color, firstDayOfWeek) }}"
|
||||||
|
class="{{ utils.bem('calendar__day', [item.type]) }} {{ item.className }}"
|
||||||
|
data-index="{{ index }}"
|
||||||
|
bindtap="onClick"
|
||||||
|
>
|
||||||
|
<view wx:if="{{ item.type === 'selected' }}" class="van-calendar__selected-day" style="background: {{ color }}">
|
||||||
|
<view wx:if="{{ item.topInfo }}" class="van-calendar__top-info">{{ item.topInfo }}</view>
|
||||||
|
{{ item.text }}
|
||||||
|
<view wx:if="{{ item.bottomInfo }}" class="van-calendar__bottom-info">
|
||||||
|
{{ item.bottomInfo }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view wx:else>
|
||||||
|
<view wx:if="{{ item.topInfo }}" class="van-calendar__top-info">{{ item.topInfo }}</view>
|
||||||
|
{{ item.text }}
|
||||||
|
<view wx:if="{{ item.bottomInfo }}" class="van-calendar__bottom-info">
|
||||||
|
{{ item.bottomInfo }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var utils = require('../../utils.wxs');
|
||||||
|
|
||||||
|
function getMark(date) {
|
||||||
|
return getDate(date).getMonth() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ROW_HEIGHT = 64;
|
||||||
|
|
||||||
|
function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
|
||||||
|
var style = [];
|
||||||
|
var current = getDate(date).getDay() || 7;
|
||||||
|
var offset = current < firstDayOfWeek ? (7 - firstDayOfWeek + current) :
|
||||||
|
current === 7 && firstDayOfWeek === 0 ? 0 :
|
||||||
|
(current - firstDayOfWeek);
|
||||||
|
|
||||||
|
if (index === 0) {
|
||||||
|
style.push(['margin-left', (100 * offset) / 7 + '%']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rowHeight !== ROW_HEIGHT) {
|
||||||
|
style.push(['height', rowHeight + 'px']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color) {
|
||||||
|
if (
|
||||||
|
type === 'start' ||
|
||||||
|
type === 'end' ||
|
||||||
|
type === 'start-end' ||
|
||||||
|
type === 'multiple-selected' ||
|
||||||
|
type === 'multiple-middle'
|
||||||
|
) {
|
||||||
|
style.push(['background', color]);
|
||||||
|
} else if (type === 'middle') {
|
||||||
|
style.push(['color', color]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return style
|
||||||
|
.map(function(item) {
|
||||||
|
return item.join(':');
|
||||||
|
})
|
||||||
|
.join(';');
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMonthTitle(date) {
|
||||||
|
date = getDate(date);
|
||||||
|
return date.getFullYear() + '年' + (date.getMonth() + 1) + '月';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMonthStyle(visible, date, rowHeight) {
|
||||||
|
if (!visible) {
|
||||||
|
date = getDate(date);
|
||||||
|
|
||||||
|
var totalDay = utils.getMonthEndDay(
|
||||||
|
date.getFullYear(),
|
||||||
|
date.getMonth() + 1
|
||||||
|
);
|
||||||
|
var offset = getDate(date).getDay();
|
||||||
|
var padding = Math.ceil((totalDay + offset) / 7) * rowHeight;
|
||||||
|
|
||||||
|
return 'padding-bottom:' + padding + 'px';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getMark: getMark,
|
||||||
|
getDayStyle: getDayStyle,
|
||||||
|
formatMonthTitle: formatMonthTitle,
|
||||||
|
getMonthStyle: getMonthStyle
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../../../common/index.wxss';.van-calendar{display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;height:100%;background-color:#fff;background-color:var(--calendar-background-color,#fff)}.van-calendar__month-title{text-align:center;height:44px;height:var(--calendar-header-title-height,44px);font-weight:500;font-weight:var(--font-weight-bold,500);font-size:14px;font-size:var(--calendar-month-title-font-size,14px);line-height:44px;line-height:var(--calendar-header-title-height,44px)}.van-calendar__days{position:relative;display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;-webkit-user-select:none;user-select:none}.van-calendar__month-mark{position:absolute;top:50%;left:50%;z-index:0;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);pointer-events:none;color:rgba(242,243,245,.8);color:var(--calendar-month-mark-color,rgba(242,243,245,.8));font-size:160px;font-size:var(--calendar-month-mark-font-size,160px)}.van-calendar__day,.van-calendar__selected-day{display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;text-align:center}.van-calendar__day{position:relative;width:14.285%;height:64px;height:var(--calendar-day-height,64px);font-size:16px;font-size:var(--calendar-day-font-size,16px)}.van-calendar__day--end,.van-calendar__day--multiple-middle,.van-calendar__day--multiple-selected,.van-calendar__day--start,.van-calendar__day--start-end{color:#fff;color:var(--calendar-range-edge-color,#fff);background-color:#ee0a24;background-color:var(--calendar-range-edge-background-color,#ee0a24)}.van-calendar__day--start{border-radius:4px 0 0 4px;border-radius:var(--border-radius-md,4px) 0 0 var(--border-radius-md,4px)}.van-calendar__day--end{border-radius:0 4px 4px 0;border-radius:0 var(--border-radius-md,4px) var(--border-radius-md,4px) 0}.van-calendar__day--multiple-selected,.van-calendar__day--start-end{border-radius:4px;border-radius:var(--border-radius-md,4px)}.van-calendar__day--middle{color:#ee0a24;color:var(--calendar-range-middle-color,#ee0a24)}.van-calendar__day--middle:after{position:absolute;top:0;right:0;bottom:0;left:0;background-color:currentColor;content:"";opacity:.1;opacity:var(--calendar-range-middle-background-opacity,.1)}.van-calendar__day--disabled{cursor:default;color:#c8c9cc;color:var(--calendar-day-disabled-color,#c8c9cc)}.van-calendar__bottom-info,.van-calendar__top-info{position:absolute;right:0;left:0;font-size:10px;font-size:var(--calendar-info-font-size,10px);line-height:14px;line-height:var(--calendar-info-line-height,14px)}@media (max-width:350px){.van-calendar__bottom-info,.van-calendar__top-info{font-size:9px}}.van-calendar__top-info{top:6px}.van-calendar__bottom-info{bottom:6px}.van-calendar__selected-day{width:54px;width:var(--calendar-selected-day-size,54px);height:54px;height:var(--calendar-selected-day-size,54px);color:#fff;color:var(--calendar-selected-day-color,#fff);background-color:#ee0a24;background-color:var(--calendar-selected-day-background-color,#ee0a24);border-radius:4px;border-radius:var(--border-radius-md,4px)}
|
||||||
335
wechat/miniprogram/miniprogram_npm/@vant/weapp/calendar/index.js
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
'use strict';
|
||||||
|
var __spreadArray =
|
||||||
|
(this && this.__spreadArray) ||
|
||||||
|
function (to, from) {
|
||||||
|
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
||||||
|
to[j] = from[i];
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
var __importDefault =
|
||||||
|
(this && this.__importDefault) ||
|
||||||
|
function (mod) {
|
||||||
|
return mod && mod.__esModule ? mod : { default: mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
var utils_1 = require('./utils');
|
||||||
|
var toast_1 = __importDefault(require('../toast/toast'));
|
||||||
|
var utils_2 = require('../common/utils');
|
||||||
|
component_1.VantComponent({
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
value: '日期选择',
|
||||||
|
},
|
||||||
|
color: String,
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
observer: function (val) {
|
||||||
|
if (val) {
|
||||||
|
this.initRect();
|
||||||
|
this.scrollIntoView();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
formatter: null,
|
||||||
|
confirmText: {
|
||||||
|
type: String,
|
||||||
|
value: '确定',
|
||||||
|
},
|
||||||
|
rangePrompt: String,
|
||||||
|
showRangePrompt: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
defaultDate: {
|
||||||
|
type: null,
|
||||||
|
observer: function (val) {
|
||||||
|
this.setData({ currentDate: val });
|
||||||
|
this.scrollIntoView();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
allowSameDay: Boolean,
|
||||||
|
confirmDisabledText: String,
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
value: 'single',
|
||||||
|
observer: 'reset',
|
||||||
|
},
|
||||||
|
minDate: {
|
||||||
|
type: null,
|
||||||
|
value: Date.now(),
|
||||||
|
},
|
||||||
|
maxDate: {
|
||||||
|
type: null,
|
||||||
|
value: new Date(
|
||||||
|
new Date().getFullYear(),
|
||||||
|
new Date().getMonth() + 6,
|
||||||
|
new Date().getDate()
|
||||||
|
).getTime(),
|
||||||
|
},
|
||||||
|
position: {
|
||||||
|
type: String,
|
||||||
|
value: 'bottom',
|
||||||
|
},
|
||||||
|
rowHeight: {
|
||||||
|
type: null,
|
||||||
|
value: utils_1.ROW_HEIGHT,
|
||||||
|
},
|
||||||
|
round: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
poppable: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
showMark: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
showTitle: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
showConfirm: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
showSubtitle: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
safeAreaInsetBottom: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
closeOnClickOverlay: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
maxRange: {
|
||||||
|
type: null,
|
||||||
|
value: null,
|
||||||
|
},
|
||||||
|
firstDayOfWeek: {
|
||||||
|
type: Number,
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
subtitle: '',
|
||||||
|
currentDate: null,
|
||||||
|
scrollIntoView: '',
|
||||||
|
},
|
||||||
|
created: function () {
|
||||||
|
this.setData({
|
||||||
|
currentDate: this.getInitialDate(),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
mounted: function () {
|
||||||
|
if (this.data.show || !this.data.poppable) {
|
||||||
|
this.initRect();
|
||||||
|
this.scrollIntoView();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
reset: function () {
|
||||||
|
this.setData({ currentDate: this.getInitialDate() });
|
||||||
|
this.scrollIntoView();
|
||||||
|
},
|
||||||
|
initRect: function () {
|
||||||
|
var _this = this;
|
||||||
|
if (this.contentObserver != null) {
|
||||||
|
this.contentObserver.disconnect();
|
||||||
|
}
|
||||||
|
var contentObserver = this.createIntersectionObserver({
|
||||||
|
thresholds: [0, 0.1, 0.9, 1],
|
||||||
|
observeAll: true,
|
||||||
|
});
|
||||||
|
this.contentObserver = contentObserver;
|
||||||
|
contentObserver.relativeTo('.van-calendar__body');
|
||||||
|
contentObserver.observe('.month', function (res) {
|
||||||
|
if (res.boundingClientRect.top <= res.relativeRect.top) {
|
||||||
|
// @ts-ignore
|
||||||
|
_this.setData({
|
||||||
|
subtitle: utils_1.formatMonthTitle(res.dataset.date),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getInitialDate: function () {
|
||||||
|
var _a = this.data,
|
||||||
|
type = _a.type,
|
||||||
|
defaultDate = _a.defaultDate,
|
||||||
|
minDate = _a.minDate;
|
||||||
|
if (type === 'range') {
|
||||||
|
var _b = defaultDate || [],
|
||||||
|
startDay = _b[0],
|
||||||
|
endDay = _b[1];
|
||||||
|
return [
|
||||||
|
startDay || minDate,
|
||||||
|
endDay || utils_1.getNextDay(new Date(minDate)).getTime(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if (type === 'multiple') {
|
||||||
|
return defaultDate || [minDate];
|
||||||
|
}
|
||||||
|
return defaultDate || minDate;
|
||||||
|
},
|
||||||
|
scrollIntoView: function () {
|
||||||
|
var _this = this;
|
||||||
|
utils_2.requestAnimationFrame(function () {
|
||||||
|
var _a = _this.data,
|
||||||
|
currentDate = _a.currentDate,
|
||||||
|
type = _a.type,
|
||||||
|
show = _a.show,
|
||||||
|
poppable = _a.poppable,
|
||||||
|
minDate = _a.minDate,
|
||||||
|
maxDate = _a.maxDate;
|
||||||
|
// @ts-ignore
|
||||||
|
var targetDate = type === 'single' ? currentDate : currentDate[0];
|
||||||
|
var displayed = show || !poppable;
|
||||||
|
if (!targetDate || !displayed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var months = utils_1.getMonths(minDate, maxDate);
|
||||||
|
months.some(function (month, index) {
|
||||||
|
if (utils_1.compareMonth(month, targetDate) === 0) {
|
||||||
|
_this.setData({ scrollIntoView: 'month' + index });
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onOpen: function () {
|
||||||
|
this.$emit('open');
|
||||||
|
},
|
||||||
|
onOpened: function () {
|
||||||
|
this.$emit('opened');
|
||||||
|
},
|
||||||
|
onClose: function () {
|
||||||
|
this.$emit('close');
|
||||||
|
},
|
||||||
|
onClosed: function () {
|
||||||
|
this.$emit('closed');
|
||||||
|
},
|
||||||
|
onClickDay: function (event) {
|
||||||
|
var date = event.detail.date;
|
||||||
|
var _a = this.data,
|
||||||
|
type = _a.type,
|
||||||
|
currentDate = _a.currentDate,
|
||||||
|
allowSameDay = _a.allowSameDay;
|
||||||
|
if (type === 'range') {
|
||||||
|
// @ts-ignore
|
||||||
|
var startDay = currentDate[0],
|
||||||
|
endDay = currentDate[1];
|
||||||
|
if (startDay && !endDay) {
|
||||||
|
var compareToStart = utils_1.compareDay(date, startDay);
|
||||||
|
if (compareToStart === 1) {
|
||||||
|
this.select([startDay, date], true);
|
||||||
|
} else if (compareToStart === -1) {
|
||||||
|
this.select([date, null]);
|
||||||
|
} else if (allowSameDay) {
|
||||||
|
this.select([date, date]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.select([date, null]);
|
||||||
|
}
|
||||||
|
} else if (type === 'multiple') {
|
||||||
|
var selectedIndex_1;
|
||||||
|
// @ts-ignore
|
||||||
|
var selected = currentDate.some(function (dateItem, index) {
|
||||||
|
var equal = utils_1.compareDay(dateItem, date) === 0;
|
||||||
|
if (equal) {
|
||||||
|
selectedIndex_1 = index;
|
||||||
|
}
|
||||||
|
return equal;
|
||||||
|
});
|
||||||
|
if (selected) {
|
||||||
|
// @ts-ignore
|
||||||
|
var cancelDate = currentDate.splice(selectedIndex_1, 1);
|
||||||
|
this.setData({ currentDate: currentDate });
|
||||||
|
this.unselect(cancelDate);
|
||||||
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
|
this.select(__spreadArray(__spreadArray([], currentDate), [date]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.select(date, true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unselect: function (dateArray) {
|
||||||
|
var date = dateArray[0];
|
||||||
|
if (date) {
|
||||||
|
this.$emit('unselect', utils_1.copyDates(date));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
select: function (date, complete) {
|
||||||
|
if (complete && this.data.type === 'range') {
|
||||||
|
var valid = this.checkRange(date);
|
||||||
|
if (!valid) {
|
||||||
|
// auto selected to max range if showConfirm
|
||||||
|
if (this.data.showConfirm) {
|
||||||
|
this.emit([
|
||||||
|
date[0],
|
||||||
|
utils_1.getDayByOffset(date[0], this.data.maxRange - 1),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
this.emit(date);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.emit(date);
|
||||||
|
if (complete && !this.data.showConfirm) {
|
||||||
|
this.onConfirm();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emit: function (date) {
|
||||||
|
var getTime = function (date) {
|
||||||
|
return date instanceof Date ? date.getTime() : date;
|
||||||
|
};
|
||||||
|
this.setData({
|
||||||
|
currentDate: Array.isArray(date) ? date.map(getTime) : getTime(date),
|
||||||
|
});
|
||||||
|
this.$emit('select', utils_1.copyDates(date));
|
||||||
|
},
|
||||||
|
checkRange: function (date) {
|
||||||
|
var _a = this.data,
|
||||||
|
maxRange = _a.maxRange,
|
||||||
|
rangePrompt = _a.rangePrompt,
|
||||||
|
showRangePrompt = _a.showRangePrompt;
|
||||||
|
if (maxRange && utils_1.calcDateNum(date) > maxRange) {
|
||||||
|
if (showRangePrompt) {
|
||||||
|
toast_1.default({
|
||||||
|
duration: 0,
|
||||||
|
context: this,
|
||||||
|
message:
|
||||||
|
rangePrompt ||
|
||||||
|
'\u9009\u62E9\u5929\u6570\u4E0D\u80FD\u8D85\u8FC7 ' +
|
||||||
|
maxRange +
|
||||||
|
' \u5929',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.$emit('over-range');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
onConfirm: function () {
|
||||||
|
var _this = this;
|
||||||
|
if (
|
||||||
|
this.data.type === 'range' &&
|
||||||
|
!this.checkRange(this.data.currentDate)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wx.nextTick(function () {
|
||||||
|
// @ts-ignore
|
||||||
|
_this.$emit('confirm', utils_1.copyDates(_this.data.currentDate));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"header": "./components/header/index",
|
||||||
|
"month": "./components/month/index",
|
||||||
|
"van-button": "../button/index",
|
||||||
|
"van-popup": "../popup/index",
|
||||||
|
"van-toast": "../toast/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
|
<import src="./calendar.wxml" />
|
||||||
|
|
||||||
|
<van-popup
|
||||||
|
wx:if="{{ poppable }}"
|
||||||
|
custom-class="van-calendar__popup--{{ position }}"
|
||||||
|
close-icon-class="van-calendar__close-icon"
|
||||||
|
show="{{ show }}"
|
||||||
|
round="{{ round }}"
|
||||||
|
position="{{ position }}"
|
||||||
|
closeable="{{ showTitle || showSubtitle }}"
|
||||||
|
close-on-click-overlay="{{ closeOnClickOverlay }}"
|
||||||
|
bind:enter="onOpen"
|
||||||
|
bind:close="onClose"
|
||||||
|
bind:after-enter="onOpened"
|
||||||
|
bind:after-leave="onClosed"
|
||||||
|
>
|
||||||
|
<include src="calendar.wxml" />
|
||||||
|
</van-popup>
|
||||||
|
|
||||||
|
<include wx:else src="calendar.wxml" />
|
||||||
|
|
||||||
|
<van-toast id="van-toast" />
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var utils = require('./utils.wxs');
|
||||||
|
|
||||||
|
function getMonths(minDate, maxDate) {
|
||||||
|
var months = [];
|
||||||
|
var cursor = getDate(minDate);
|
||||||
|
|
||||||
|
cursor.setDate(1);
|
||||||
|
|
||||||
|
do {
|
||||||
|
months.push(cursor.getTime());
|
||||||
|
cursor.setMonth(cursor.getMonth() + 1);
|
||||||
|
} while (utils.compareMonth(cursor, getDate(maxDate)) !== 1);
|
||||||
|
|
||||||
|
return months;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getButtonDisabled(type, currentDate) {
|
||||||
|
if (currentDate == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'range') {
|
||||||
|
return !currentDate[0] || !currentDate[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'multiple') {
|
||||||
|
return !currentDate.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !currentDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getMonths: getMonths,
|
||||||
|
getButtonDisabled: getButtonDisabled
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-calendar{display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;height:100%;height:var(--calendar-height,100%);background-color:#fff;background-color:var(--calendar-background-color,#fff)}.van-calendar__close-icon{top:11px}.van-calendar__popup--bottom,.van-calendar__popup--top{height:80%;height:var(--calendar-popup-height,80%)}.van-calendar__popup--left,.van-calendar__popup--right{height:100%}.van-calendar__body{-webkit-flex:1;flex:1;overflow:auto;-webkit-overflow-scrolling:touch}.van-calendar__footer{-webkit-flex-shrink:0;flex-shrink:0;padding:0 16px;padding:0 var(--padding-md,16px)}.van-calendar__footer--safe-area-inset-bottom{padding-bottom:env(safe-area-inset-bottom)}.van-calendar__footer+.van-calendar__footer,.van-calendar__footer:empty{display:none}.van-calendar__footer:empty+.van-calendar__footer{display:block!important}.van-calendar__confirm{height:36px!important;height:var(--calendar-confirm-button-height,36px)!important;margin:7px 0!important;margin:var(--calendar-confirm-button-margin,7px 0)!important;line-height:34px!important;line-height:var(--calendar-confirm-button-line-height,34px)!important}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
exports.getMonths = exports.getMonthEndDay = exports.copyDates = exports.calcDateNum = exports.getNextDay = exports.getPrevDay = exports.getDayByOffset = exports.compareDay = exports.compareMonth = exports.formatMonthTitle = exports.ROW_HEIGHT = void 0;
|
||||||
|
exports.ROW_HEIGHT = 64;
|
||||||
|
function formatMonthTitle(date) {
|
||||||
|
if (!(date instanceof Date)) {
|
||||||
|
date = new Date(date);
|
||||||
|
}
|
||||||
|
return date.getFullYear() + '\u5E74' + (date.getMonth() + 1) + '\u6708';
|
||||||
|
}
|
||||||
|
exports.formatMonthTitle = formatMonthTitle;
|
||||||
|
function compareMonth(date1, date2) {
|
||||||
|
if (!(date1 instanceof Date)) {
|
||||||
|
date1 = new Date(date1);
|
||||||
|
}
|
||||||
|
if (!(date2 instanceof Date)) {
|
||||||
|
date2 = new Date(date2);
|
||||||
|
}
|
||||||
|
var year1 = date1.getFullYear();
|
||||||
|
var year2 = date2.getFullYear();
|
||||||
|
var month1 = date1.getMonth();
|
||||||
|
var month2 = date2.getMonth();
|
||||||
|
if (year1 === year2) {
|
||||||
|
return month1 === month2 ? 0 : month1 > month2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
return year1 > year2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
exports.compareMonth = compareMonth;
|
||||||
|
function compareDay(day1, day2) {
|
||||||
|
if (!(day1 instanceof Date)) {
|
||||||
|
day1 = new Date(day1);
|
||||||
|
}
|
||||||
|
if (!(day2 instanceof Date)) {
|
||||||
|
day2 = new Date(day2);
|
||||||
|
}
|
||||||
|
var compareMonthResult = compareMonth(day1, day2);
|
||||||
|
if (compareMonthResult === 0) {
|
||||||
|
var date1 = day1.getDate();
|
||||||
|
var date2 = day2.getDate();
|
||||||
|
return date1 === date2 ? 0 : date1 > date2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
return compareMonthResult;
|
||||||
|
}
|
||||||
|
exports.compareDay = compareDay;
|
||||||
|
function getDayByOffset(date, offset) {
|
||||||
|
date = new Date(date);
|
||||||
|
date.setDate(date.getDate() + offset);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
exports.getDayByOffset = getDayByOffset;
|
||||||
|
function getPrevDay(date) {
|
||||||
|
return getDayByOffset(date, -1);
|
||||||
|
}
|
||||||
|
exports.getPrevDay = getPrevDay;
|
||||||
|
function getNextDay(date) {
|
||||||
|
return getDayByOffset(date, 1);
|
||||||
|
}
|
||||||
|
exports.getNextDay = getNextDay;
|
||||||
|
function calcDateNum(date) {
|
||||||
|
var day1 = new Date(date[0]).getTime();
|
||||||
|
var day2 = new Date(date[1]).getTime();
|
||||||
|
return (day2 - day1) / (1000 * 60 * 60 * 24) + 1;
|
||||||
|
}
|
||||||
|
exports.calcDateNum = calcDateNum;
|
||||||
|
function copyDates(dates) {
|
||||||
|
if (Array.isArray(dates)) {
|
||||||
|
return dates.map(function (date) {
|
||||||
|
if (date === null) {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
return new Date(date);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return new Date(dates);
|
||||||
|
}
|
||||||
|
exports.copyDates = copyDates;
|
||||||
|
function getMonthEndDay(year, month) {
|
||||||
|
return 32 - new Date(year, month - 1, 32).getDate();
|
||||||
|
}
|
||||||
|
exports.getMonthEndDay = getMonthEndDay;
|
||||||
|
function getMonths(minDate, maxDate) {
|
||||||
|
var months = [];
|
||||||
|
var cursor = new Date(minDate);
|
||||||
|
cursor.setDate(1);
|
||||||
|
do {
|
||||||
|
months.push(cursor.getTime());
|
||||||
|
cursor.setMonth(cursor.getMonth() + 1);
|
||||||
|
} while (compareMonth(cursor, maxDate) !== 1);
|
||||||
|
return months;
|
||||||
|
}
|
||||||
|
exports.getMonths = getMonths;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
function getMonthEndDay(year, month) {
|
||||||
|
return 32 - getDate(year, month - 1, 32).getDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareMonth(date1, date2) {
|
||||||
|
date1 = getDate(date1);
|
||||||
|
date2 = getDate(date2);
|
||||||
|
|
||||||
|
var year1 = date1.getFullYear();
|
||||||
|
var year2 = date2.getFullYear();
|
||||||
|
var month1 = date1.getMonth();
|
||||||
|
var month2 = date2.getMonth();
|
||||||
|
|
||||||
|
if (year1 === year2) {
|
||||||
|
return month1 === month2 ? 0 : month1 > month2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return year1 > year2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getMonthEndDay: getMonthEndDay,
|
||||||
|
compareMonth: compareMonth
|
||||||
|
};
|
||||||
51
wechat/miniprogram/miniprogram_npm/@vant/weapp/card/index.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var link_1 = require('../mixins/link');
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
component_1.VantComponent({
|
||||||
|
classes: [
|
||||||
|
'num-class',
|
||||||
|
'desc-class',
|
||||||
|
'thumb-class',
|
||||||
|
'title-class',
|
||||||
|
'price-class',
|
||||||
|
'origin-price-class',
|
||||||
|
],
|
||||||
|
mixins: [link_1.link],
|
||||||
|
props: {
|
||||||
|
tag: String,
|
||||||
|
num: String,
|
||||||
|
desc: String,
|
||||||
|
thumb: String,
|
||||||
|
title: String,
|
||||||
|
price: {
|
||||||
|
type: String,
|
||||||
|
observer: 'updatePrice',
|
||||||
|
},
|
||||||
|
centered: Boolean,
|
||||||
|
lazyLoad: Boolean,
|
||||||
|
thumbLink: String,
|
||||||
|
originPrice: String,
|
||||||
|
thumbMode: {
|
||||||
|
type: String,
|
||||||
|
value: 'aspectFit',
|
||||||
|
},
|
||||||
|
currency: {
|
||||||
|
type: String,
|
||||||
|
value: '¥',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
updatePrice: function () {
|
||||||
|
var price = this.data.price;
|
||||||
|
var priceArr = price.toString().split('.');
|
||||||
|
this.setData({
|
||||||
|
integerStr: priceArr[0],
|
||||||
|
decimalStr: priceArr[1] ? '.' + priceArr[1] : '',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onClickThumb: function () {
|
||||||
|
this.jumpLink('thumbLink');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"van-tag": "../tag/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
|
<view class="custom-class van-card">
|
||||||
|
<view class="{{ utils.bem('card__header', { center: centered }) }}">
|
||||||
|
<view class="van-card__thumb" bind:tap="onClickThumb">
|
||||||
|
<image
|
||||||
|
wx:if="{{ thumb }}"
|
||||||
|
src="{{ thumb }}"
|
||||||
|
mode="{{ thumbMode }}"
|
||||||
|
lazy-load="{{ lazyLoad }}"
|
||||||
|
class="van-card__img thumb-class"
|
||||||
|
/>
|
||||||
|
<slot wx:else name="thumb" />
|
||||||
|
<van-tag
|
||||||
|
wx:if="{{ tag }}"
|
||||||
|
mark
|
||||||
|
type="danger"
|
||||||
|
custom-class="van-card__tag"
|
||||||
|
>
|
||||||
|
{{ tag }}
|
||||||
|
</van-tag>
|
||||||
|
<slot wx:else name="tag" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="van-card__content {{ utils.bem('card__content', { center: centered }) }}">
|
||||||
|
<view>
|
||||||
|
<view wx:if="{{ title }}" class="van-card__title title-class">{{ title }}</view>
|
||||||
|
<slot wx:else name="title" />
|
||||||
|
|
||||||
|
<view wx:if="{{ desc }}" class="van-card__desc desc-class">{{ desc }}</view>
|
||||||
|
<slot wx:else name="desc" />
|
||||||
|
|
||||||
|
<slot name="tags" />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="van-card__bottom">
|
||||||
|
<slot name="price-top" />
|
||||||
|
<view wx:if="{{ price || price === 0 }}" class="van-card__price price-class">
|
||||||
|
<text>{{ currency }}</text>
|
||||||
|
<text class="van-card__price-integer">{{ integerStr }}</text>
|
||||||
|
<text class="van-card__price-decimal">{{ decimalStr }}</text>
|
||||||
|
</view>
|
||||||
|
<slot wx:else name="price" />
|
||||||
|
<view wx:if="{{ originPrice || originPrice === 0 }}" class="van-card__origin-price origin-price-class">{{ currency }} {{ originPrice }}</view>
|
||||||
|
<slot wx:else name="origin-price" />
|
||||||
|
<view wx:if="{{ num }}" class="van-card__num num-class">x {{ num }}</view>
|
||||||
|
<slot wx:else name="num" />
|
||||||
|
<slot name="bottom" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="van-card__footer">
|
||||||
|
<slot name="footer" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-card{position:relative;box-sizing:border-box;padding:8px 16px;padding:var(--card-padding,8px 16px);font-size:12px;font-size:var(--card-font-size,12px);color:#323233;color:var(--card-text-color,#323233);background-color:#fafafa;background-color:var(--card-background-color,#fafafa)}.van-card__header{display:-webkit-flex;display:flex}.van-card__header--center{-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center}.van-card__thumb{position:relative;-webkit-flex:none;flex:none;width:88px;width:var(--card-thumb-size,88px);height:88px;height:var(--card-thumb-size,88px);margin-right:8px;margin-right:var(--padding-xs,8px)}.van-card__thumb:empty{display:none}.van-card__img{width:100%;height:100%;border-radius:8px;border-radius:var(--border-radius-lg,8px)}.van-card__content{position:relative;display:-webkit-flex;display:flex;-webkit-flex:1;flex:1;-webkit-flex-direction:column;flex-direction:column;-webkit-justify-content:space-between;justify-content:space-between;min-width:0;min-height:88px;min-height:var(--card-thumb-size,88px)}.van-card__content--center{-webkit-justify-content:center;justify-content:center}.van-card__desc,.van-card__title{word-wrap:break-word}.van-card__title{font-weight:700;line-height:16px;line-height:var(--card-title-line-height,16px)}.van-card__desc{line-height:20px;line-height:var(--card-desc-line-height,20px);color:#646566;color:var(--card-desc-color,#646566)}.van-card__bottom{line-height:20px}.van-card__price{display:inline-block;font-weight:700;color:#ee0a24;color:var(--card-price-color,#ee0a24);font-size:12px;font-size:var(--card-price-font-size,12px)}.van-card__price-integer{font-size:16px;font-size:var(--card-price-integer-font-size,16px)}.van-card__price-decimal,.van-card__price-integer{font-family:Avenir-Heavy,PingFang SC,Helvetica Neue,Arial,sans-serif;font-family:var(--card-price-font-family,Avenir-Heavy,PingFang SC,Helvetica Neue,Arial,sans-serif)}.van-card__origin-price{display:inline-block;margin-left:5px;text-decoration:line-through;font-size:10px;font-size:var(--card-origin-price-font-size,10px);color:#646566;color:var(--card-origin-price-color,#646566)}.van-card__num{float:right}.van-card__tag{position:absolute!important;top:2px;left:0}.van-card__footer{-webkit-flex:none;flex:none;width:100%;text-align:right}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
component_1.VantComponent({
|
||||||
|
props: {
|
||||||
|
title: String,
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"component": true
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<view
|
||||||
|
wx:if="{{ title }}"
|
||||||
|
class="van-cell-group__title"
|
||||||
|
>
|
||||||
|
{{ title }}
|
||||||
|
</view>
|
||||||
|
<view class="custom-class van-cell-group {{ border ? 'van-hairline--top-bottom' : '' }}">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-cell-group__title{padding:16px 16px 8px;padding:var(--cell-group-title-padding,16px 16px 8px);font-size:14px;font-size:var(--cell-group-title-font-size,14px);line-height:16px;line-height:var(--cell-group-title-line-height,16px);color:#969799;color:var(--cell-group-title-color,#969799)}
|
||||||
40
wechat/miniprogram/miniprogram_npm/@vant/weapp/cell/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var link_1 = require('../mixins/link');
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
component_1.VantComponent({
|
||||||
|
classes: [
|
||||||
|
'title-class',
|
||||||
|
'label-class',
|
||||||
|
'value-class',
|
||||||
|
'right-icon-class',
|
||||||
|
'hover-class',
|
||||||
|
],
|
||||||
|
mixins: [link_1.link],
|
||||||
|
props: {
|
||||||
|
title: null,
|
||||||
|
value: null,
|
||||||
|
icon: String,
|
||||||
|
size: String,
|
||||||
|
label: String,
|
||||||
|
center: Boolean,
|
||||||
|
isLink: Boolean,
|
||||||
|
required: Boolean,
|
||||||
|
clickable: Boolean,
|
||||||
|
titleWidth: String,
|
||||||
|
customStyle: String,
|
||||||
|
arrowDirection: String,
|
||||||
|
useLabelSlot: Boolean,
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
titleStyle: String,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick: function (event) {
|
||||||
|
this.$emit('click', event.detail);
|
||||||
|
this.jumpLink();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"van-icon": "../icon/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
|
||||||
|
<view
|
||||||
|
class="custom-class {{ utils.bem('cell', [size, { center, required, borderless: !border, clickable: isLink || clickable }]) }}"
|
||||||
|
hover-class="van-cell--hover hover-class"
|
||||||
|
hover-stay-time="70"
|
||||||
|
style="{{ customStyle }}"
|
||||||
|
bind:tap="onClick"
|
||||||
|
>
|
||||||
|
<van-icon
|
||||||
|
wx:if="{{ icon }}"
|
||||||
|
name="{{ icon }}"
|
||||||
|
class="van-cell__left-icon-wrap"
|
||||||
|
custom-class="van-cell__left-icon"
|
||||||
|
/>
|
||||||
|
<slot wx:else name="icon" />
|
||||||
|
|
||||||
|
<view
|
||||||
|
style="{{ computed.titleStyle({ titleWidth, titleStyle }) }}"
|
||||||
|
class="van-cell__title title-class"
|
||||||
|
>
|
||||||
|
|
||||||
|
<block wx:if="{{ title }}">{{ title }}</block>
|
||||||
|
<slot wx:else name="title" />
|
||||||
|
|
||||||
|
<view wx:if="{{ label || useLabelSlot }}" class="van-cell__label label-class">
|
||||||
|
<slot wx:if="{{ useLabelSlot }}" name="label" />
|
||||||
|
<block wx:elif="{{ label }}">{{ label }}</block>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="van-cell__value value-class">
|
||||||
|
<block wx:if="{{ value || value === 0 }}">{{ value }}</block>
|
||||||
|
<slot wx:else />
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<van-icon
|
||||||
|
wx:if="{{ isLink }}"
|
||||||
|
name="{{ arrowDirection ? 'arrow' + '-' + arrowDirection : 'arrow' }}"
|
||||||
|
class="van-cell__right-icon-wrap right-icon-class"
|
||||||
|
custom-class="van-cell__right-icon"
|
||||||
|
/>
|
||||||
|
<slot wx:else name="right-icon" />
|
||||||
|
|
||||||
|
<slot name="extra" />
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var style = require('../wxs/style.wxs');
|
||||||
|
var addUnit = require('../wxs/add-unit.wxs');
|
||||||
|
|
||||||
|
function titleStyle(data) {
|
||||||
|
return style([
|
||||||
|
{
|
||||||
|
'max-width': addUnit(data.titleWidth),
|
||||||
|
'min-width': addUnit(data.titleWidth),
|
||||||
|
},
|
||||||
|
data.titleStyle,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
titleStyle: titleStyle,
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-cell{position:relative;display:-webkit-flex;display:flex;box-sizing:border-box;width:100%;padding:10px 16px;padding:var(--cell-vertical-padding,10px) var(--cell-horizontal-padding,16px);font-size:14px;font-size:var(--cell-font-size,14px);line-height:24px;line-height:var(--cell-line-height,24px);color:#323233;color:var(--cell-text-color,#323233);background-color:#fff;background-color:var(--cell-background-color,#fff)}.van-cell:after{position:absolute;box-sizing:border-box;-webkit-transform-origin:center;transform-origin:center;content:" ";pointer-events:none;right:16px;bottom:0;left:16px;border-bottom:1px solid #ebedf0;-webkit-transform:scaleY(.5);transform:scaleY(.5)}.van-cell--borderless:after{display:none}.van-cell-group{background-color:#fff;background-color:var(--cell-background-color,#fff)}.van-cell__label{margin-top:3px;margin-top:var(--cell-label-margin-top,3px);font-size:12px;font-size:var(--cell-label-font-size,12px);line-height:18px;line-height:var(--cell-label-line-height,18px);color:#969799;color:var(--cell-label-color,#969799)}.van-cell__value{overflow:hidden;text-align:right;vertical-align:middle;color:#969799;color:var(--cell-value-color,#969799)}.van-cell__title,.van-cell__value{-webkit-flex:1;flex:1}.van-cell__title:empty,.van-cell__value:empty{display:none}.van-cell__left-icon-wrap,.van-cell__right-icon-wrap{display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;height:24px;height:var(--cell-line-height,24px);font-size:16px;font-size:var(--cell-icon-size,16px)}.van-cell__left-icon-wrap{margin-right:4px;margin-right:var(--padding-base,4px)}.van-cell__right-icon-wrap{margin-left:4px;margin-left:var(--padding-base,4px);color:#969799;color:var(--cell-right-icon-color,#969799)}.van-cell__left-icon{vertical-align:middle}.van-cell__left-icon,.van-cell__right-icon{line-height:24px;line-height:var(--cell-line-height,24px)}.van-cell--clickable.van-cell--hover{background-color:#f2f3f5;background-color:var(--cell-active-color,#f2f3f5)}.van-cell--required{overflow:visible}.van-cell--required:before{position:absolute;content:"*";left:8px;left:var(--padding-xs,8px);font-size:14px;font-size:var(--cell-font-size,14px);color:#ee0a24;color:var(--cell-required-color,#ee0a24)}.van-cell--center{-webkit-align-items:center;align-items:center}.van-cell--large{padding-top:12px;padding-top:var(--cell-large-vertical-padding,12px);padding-bottom:12px;padding-bottom:var(--cell-large-vertical-padding,12px)}.van-cell--large .van-cell__title{font-size:16px;font-size:var(--cell-large-title-font-size,16px)}.van-cell--large .van-cell__value{font-size:16px;font-size:var(--cell-large-value-font-size,16px)}.van-cell--large .van-cell__label{font-size:14px;font-size:var(--cell-large-label-font-size,14px)}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var relation_1 = require('../common/relation');
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
component_1.VantComponent({
|
||||||
|
field: true,
|
||||||
|
relation: relation_1.useChildren('checkbox', function (target) {
|
||||||
|
this.updateChild(target);
|
||||||
|
}),
|
||||||
|
props: {
|
||||||
|
max: Number,
|
||||||
|
value: {
|
||||||
|
type: Array,
|
||||||
|
observer: 'updateChildren',
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
observer: 'updateChildren',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
updateChildren: function () {
|
||||||
|
var _this = this;
|
||||||
|
this.children.forEach(function (child) {
|
||||||
|
return _this.updateChild(child);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
updateChild: function (child) {
|
||||||
|
var _a = this.data,
|
||||||
|
value = _a.value,
|
||||||
|
disabled = _a.disabled;
|
||||||
|
child.setData({
|
||||||
|
value: value.indexOf(child.data.name) !== -1,
|
||||||
|
parentDisabled: disabled,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"component": true
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<slot />
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var relation_1 = require('../common/relation');
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
function emit(target, value) {
|
||||||
|
target.$emit('input', value);
|
||||||
|
target.$emit('change', value);
|
||||||
|
}
|
||||||
|
component_1.VantComponent({
|
||||||
|
field: true,
|
||||||
|
relation: relation_1.useParent('checkbox-group'),
|
||||||
|
classes: ['icon-class', 'label-class'],
|
||||||
|
props: {
|
||||||
|
value: Boolean,
|
||||||
|
disabled: Boolean,
|
||||||
|
useIconSlot: Boolean,
|
||||||
|
checkedColor: String,
|
||||||
|
labelPosition: {
|
||||||
|
type: String,
|
||||||
|
value: 'right',
|
||||||
|
},
|
||||||
|
labelDisabled: Boolean,
|
||||||
|
shape: {
|
||||||
|
type: String,
|
||||||
|
value: 'round',
|
||||||
|
},
|
||||||
|
iconSize: {
|
||||||
|
type: null,
|
||||||
|
value: 20,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
parentDisabled: false,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
emitChange: function (value) {
|
||||||
|
if (this.parent) {
|
||||||
|
this.setParentValue(this.parent, value);
|
||||||
|
} else {
|
||||||
|
emit(this, value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggle: function () {
|
||||||
|
var _a = this.data,
|
||||||
|
parentDisabled = _a.parentDisabled,
|
||||||
|
disabled = _a.disabled,
|
||||||
|
value = _a.value;
|
||||||
|
if (!disabled && !parentDisabled) {
|
||||||
|
this.emitChange(!value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClickLabel: function () {
|
||||||
|
var _a = this.data,
|
||||||
|
labelDisabled = _a.labelDisabled,
|
||||||
|
parentDisabled = _a.parentDisabled,
|
||||||
|
disabled = _a.disabled,
|
||||||
|
value = _a.value;
|
||||||
|
if (!disabled && !labelDisabled && !parentDisabled) {
|
||||||
|
this.emitChange(!value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setParentValue: function (parent, value) {
|
||||||
|
var parentValue = parent.data.value.slice();
|
||||||
|
var name = this.data.name;
|
||||||
|
var max = parent.data.max;
|
||||||
|
if (value) {
|
||||||
|
if (max && parentValue.length >= max) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (parentValue.indexOf(name) === -1) {
|
||||||
|
parentValue.push(name);
|
||||||
|
emit(parent, parentValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var index = parentValue.indexOf(name);
|
||||||
|
if (index !== -1) {
|
||||||
|
parentValue.splice(index, 1);
|
||||||
|
emit(parent, parentValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"component": true,
|
||||||
|
"usingComponents": {
|
||||||
|
"van-icon": "../icon/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
<wxs src="./index.wxs" module="computed" />
|
||||||
|
|
||||||
|
<view class="van-checkbox custom-class">
|
||||||
|
<view
|
||||||
|
wx:if="{{ labelPosition === 'left' }}"
|
||||||
|
class="label-class {{ utils.bem('checkbox__label', [labelPosition, { disabled: disabled || parentDisabled }]) }}"
|
||||||
|
bindtap="onClickLabel"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
<view class="van-checkbox__icon-wrap" bindtap="toggle">
|
||||||
|
<slot wx:if="{{ useIconSlot }}" name="icon" />
|
||||||
|
<van-icon
|
||||||
|
wx:else
|
||||||
|
name="success"
|
||||||
|
size="0.8em"
|
||||||
|
class="{{ utils.bem('checkbox__icon', [shape, { disabled: disabled || parentDisabled, checked: value }]) }}"
|
||||||
|
style="{{ computed.iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) }}"
|
||||||
|
custom-class="icon-class"
|
||||||
|
custom-style="line-height: 1.25em;"
|
||||||
|
/>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
wx:if="{{ labelPosition === 'right' }}"
|
||||||
|
class="label-class {{ utils.bem('checkbox__label', [labelPosition, { disabled: disabled || parentDisabled }]) }}"
|
||||||
|
bindtap="onClickLabel"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var style = require('../wxs/style.wxs');
|
||||||
|
var addUnit = require('../wxs/add-unit.wxs');
|
||||||
|
|
||||||
|
function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) {
|
||||||
|
var styles = {
|
||||||
|
'font-size': addUnit(iconSize),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (checkedColor && value && !disabled && !parentDisabled) {
|
||||||
|
styles['border-color'] = checkedColor;
|
||||||
|
styles['background-color'] = checkedColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style(styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
iconStyle: iconStyle,
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
@import '../common/index.wxss';.van-checkbox{display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;overflow:hidden;-webkit-user-select:none;user-select:none}.van-checkbox__icon-wrap,.van-checkbox__label{line-height:20px;line-height:var(--checkbox-size,20px)}.van-checkbox__icon-wrap{-webkit-flex:none;flex:none}.van-checkbox__icon{display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;box-sizing:border-box;width:1em;height:1em;color:transparent;text-align:center;transition-property:color,border-color,background-color;font-size:20px;font-size:var(--checkbox-size,20px);border:1px solid #c8c9cc;border:1px solid var(--checkbox-border-color,#c8c9cc);transition-duration:.2s;transition-duration:var(--checkbox-transition-duration,.2s)}.van-checkbox__icon--round{border-radius:100%}.van-checkbox__icon--checked{color:#fff;color:var(--white,#fff);background-color:#1989fa;background-color:var(--checkbox-checked-icon-color,#1989fa);border-color:#1989fa;border-color:var(--checkbox-checked-icon-color,#1989fa)}.van-checkbox__icon--disabled{background-color:#ebedf0;background-color:var(--checkbox-disabled-background-color,#ebedf0);border-color:#c8c9cc;border-color:var(--checkbox-disabled-icon-color,#c8c9cc)}.van-checkbox__icon--disabled.van-checkbox__icon--checked{color:#c8c9cc;color:var(--checkbox-disabled-icon-color,#c8c9cc)}.van-checkbox__label{word-wrap:break-word;margin-left:10px;margin-left:var(--checkbox-label-margin,10px);color:#323233;color:var(--checkbox-label-color,#323233)}.van-checkbox__label--left{float:left;margin:0 10px 0 0;margin:0 var(--checkbox-label-margin,10px) 0 0}.van-checkbox__label--disabled{color:#c8c9cc;color:var(--checkbox-disabled-label-color,#c8c9cc)}.van-checkbox__label:empty{margin:0}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
exports.adaptor = void 0;
|
||||||
|
function adaptor(ctx) {
|
||||||
|
// @ts-ignore
|
||||||
|
return Object.assign(ctx, {
|
||||||
|
setStrokeStyle: function (val) {
|
||||||
|
ctx.strokeStyle = val;
|
||||||
|
},
|
||||||
|
setLineWidth: function (val) {
|
||||||
|
ctx.lineWidth = val;
|
||||||
|
},
|
||||||
|
setLineCap: function (val) {
|
||||||
|
ctx.lineCap = val;
|
||||||
|
},
|
||||||
|
setFillStyle: function (val) {
|
||||||
|
ctx.fillStyle = val;
|
||||||
|
},
|
||||||
|
setFontSize: function (val) {
|
||||||
|
ctx.font = String(val);
|
||||||
|
},
|
||||||
|
setGlobalAlpha: function (val) {
|
||||||
|
ctx.globalAlpha = val;
|
||||||
|
},
|
||||||
|
setLineJoin: function (val) {
|
||||||
|
ctx.lineJoin = val;
|
||||||
|
},
|
||||||
|
setTextAlign: function (val) {
|
||||||
|
ctx.textAlign = val;
|
||||||
|
},
|
||||||
|
setMiterLimit: function (val) {
|
||||||
|
ctx.miterLimit = val;
|
||||||
|
},
|
||||||
|
setShadow: function (offsetX, offsetY, blur, color) {
|
||||||
|
ctx.shadowOffsetX = offsetX;
|
||||||
|
ctx.shadowOffsetY = offsetY;
|
||||||
|
ctx.shadowBlur = blur;
|
||||||
|
ctx.shadowColor = color;
|
||||||
|
},
|
||||||
|
setTextBaseline: function (val) {
|
||||||
|
ctx.textBaseline = val;
|
||||||
|
},
|
||||||
|
createCircularGradient: function () {},
|
||||||
|
draw: function () {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.adaptor = adaptor;
|
||||||
215
wechat/miniprogram/miniprogram_npm/@vant/weapp/circle/index.js
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
'use strict';
|
||||||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
var color_1 = require('../common/color');
|
||||||
|
var component_1 = require('../common/component');
|
||||||
|
var utils_1 = require('../common/utils');
|
||||||
|
var validator_1 = require('../common/validator');
|
||||||
|
var version_1 = require('../common/version');
|
||||||
|
var canvas_1 = require('./canvas');
|
||||||
|
function format(rate) {
|
||||||
|
return Math.min(Math.max(rate, 0), 100);
|
||||||
|
}
|
||||||
|
var PERIMETER = 2 * Math.PI;
|
||||||
|
var BEGIN_ANGLE = -Math.PI / 2;
|
||||||
|
var STEP = 1;
|
||||||
|
component_1.VantComponent({
|
||||||
|
props: {
|
||||||
|
text: String,
|
||||||
|
lineCap: {
|
||||||
|
type: String,
|
||||||
|
value: 'round',
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Number,
|
||||||
|
value: 0,
|
||||||
|
observer: 'reRender',
|
||||||
|
},
|
||||||
|
speed: {
|
||||||
|
type: Number,
|
||||||
|
value: 50,
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: Number,
|
||||||
|
value: 100,
|
||||||
|
observer: function () {
|
||||||
|
this.drawCircle(this.currentValue);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fill: String,
|
||||||
|
layerColor: {
|
||||||
|
type: String,
|
||||||
|
value: color_1.WHITE,
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: null,
|
||||||
|
value: color_1.BLUE,
|
||||||
|
observer: function () {
|
||||||
|
var _this = this;
|
||||||
|
this.setHoverColor().then(function () {
|
||||||
|
_this.drawCircle(_this.currentValue);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
strokeWidth: {
|
||||||
|
type: Number,
|
||||||
|
value: 4,
|
||||||
|
},
|
||||||
|
clockwise: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
hoverColor: color_1.BLUE,
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getContext: function () {
|
||||||
|
var _this = this;
|
||||||
|
var _a = this.data,
|
||||||
|
type = _a.type,
|
||||||
|
size = _a.size;
|
||||||
|
if (type === '' || !version_1.canIUseCanvas2d()) {
|
||||||
|
var ctx = wx.createCanvasContext('van-circle', this);
|
||||||
|
return Promise.resolve(ctx);
|
||||||
|
}
|
||||||
|
var dpr = utils_1.getSystemInfoSync().pixelRatio;
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
wx.createSelectorQuery()
|
||||||
|
.in(_this)
|
||||||
|
.select('#van-circle')
|
||||||
|
.node()
|
||||||
|
.exec(function (res) {
|
||||||
|
var canvas = res[0].node;
|
||||||
|
var ctx = canvas.getContext(type);
|
||||||
|
if (!_this.inited) {
|
||||||
|
_this.inited = true;
|
||||||
|
canvas.width = size * dpr;
|
||||||
|
canvas.height = size * dpr;
|
||||||
|
ctx.scale(dpr, dpr);
|
||||||
|
}
|
||||||
|
resolve(canvas_1.adaptor(ctx));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setHoverColor: function () {
|
||||||
|
var _this = this;
|
||||||
|
var _a = this.data,
|
||||||
|
color = _a.color,
|
||||||
|
size = _a.size;
|
||||||
|
if (validator_1.isObj(color)) {
|
||||||
|
return this.getContext().then(function (context) {
|
||||||
|
var LinearColor = context.createLinearGradient(size, 0, 0, 0);
|
||||||
|
Object.keys(color)
|
||||||
|
.sort(function (a, b) {
|
||||||
|
return parseFloat(a) - parseFloat(b);
|
||||||
|
})
|
||||||
|
.map(function (key) {
|
||||||
|
return LinearColor.addColorStop(
|
||||||
|
parseFloat(key) / 100,
|
||||||
|
color[key]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
_this.hoverColor = LinearColor;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.hoverColor = color;
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
presetCanvas: function (context, strokeStyle, beginAngle, endAngle, fill) {
|
||||||
|
var _a = this.data,
|
||||||
|
strokeWidth = _a.strokeWidth,
|
||||||
|
lineCap = _a.lineCap,
|
||||||
|
clockwise = _a.clockwise,
|
||||||
|
size = _a.size;
|
||||||
|
var position = size / 2;
|
||||||
|
var radius = position - strokeWidth / 2;
|
||||||
|
context.setStrokeStyle(strokeStyle);
|
||||||
|
context.setLineWidth(strokeWidth);
|
||||||
|
context.setLineCap(lineCap);
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(position, position, radius, beginAngle, endAngle, !clockwise);
|
||||||
|
context.stroke();
|
||||||
|
if (fill) {
|
||||||
|
context.setFillStyle(fill);
|
||||||
|
context.fill();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
renderLayerCircle: function (context) {
|
||||||
|
var _a = this.data,
|
||||||
|
layerColor = _a.layerColor,
|
||||||
|
fill = _a.fill;
|
||||||
|
this.presetCanvas(context, layerColor, 0, PERIMETER, fill);
|
||||||
|
},
|
||||||
|
renderHoverCircle: function (context, formatValue) {
|
||||||
|
var clockwise = this.data.clockwise;
|
||||||
|
// 结束角度
|
||||||
|
var progress = PERIMETER * (formatValue / 100);
|
||||||
|
var endAngle = clockwise
|
||||||
|
? BEGIN_ANGLE + progress
|
||||||
|
: 3 * Math.PI - (BEGIN_ANGLE + progress);
|
||||||
|
this.presetCanvas(context, this.hoverColor, BEGIN_ANGLE, endAngle);
|
||||||
|
},
|
||||||
|
drawCircle: function (currentValue) {
|
||||||
|
var _this = this;
|
||||||
|
var size = this.data.size;
|
||||||
|
this.getContext().then(function (context) {
|
||||||
|
context.clearRect(0, 0, size, size);
|
||||||
|
_this.renderLayerCircle(context);
|
||||||
|
var formatValue = format(currentValue);
|
||||||
|
if (formatValue !== 0) {
|
||||||
|
_this.renderHoverCircle(context, formatValue);
|
||||||
|
}
|
||||||
|
context.draw();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
reRender: function () {
|
||||||
|
var _this = this;
|
||||||
|
// tofector 动画暂时没有想到好的解决方案
|
||||||
|
var _a = this.data,
|
||||||
|
value = _a.value,
|
||||||
|
speed = _a.speed;
|
||||||
|
if (speed <= 0 || speed > 1000) {
|
||||||
|
this.drawCircle(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.clearInterval();
|
||||||
|
this.currentValue = this.currentValue || 0;
|
||||||
|
this.interval = setInterval(function () {
|
||||||
|
if (_this.currentValue !== value) {
|
||||||
|
if (Math.abs(_this.currentValue - value) < STEP) {
|
||||||
|
_this.currentValue = value;
|
||||||
|
} else {
|
||||||
|
if (_this.currentValue < value) {
|
||||||
|
_this.currentValue += STEP;
|
||||||
|
} else {
|
||||||
|
_this.currentValue -= STEP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_this.drawCircle(_this.currentValue);
|
||||||
|
} else {
|
||||||
|
_this.clearInterval();
|
||||||
|
}
|
||||||
|
}, 1000 / speed);
|
||||||
|
},
|
||||||
|
clearInterval: function () {
|
||||||
|
if (this.interval) {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
this.interval = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted: function () {
|
||||||
|
var _this = this;
|
||||||
|
this.currentValue = this.data.value;
|
||||||
|
this.setHoverColor().then(function () {
|
||||||
|
_this.drawCircle(_this.currentValue);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
destroyed: function () {
|
||||||
|
this.clearInterval();
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"component": true
|
||||||
|
}
|
||||||