初始提交:知书小程序项目
This commit is contained in:
commit
61fcf7dd71
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
// 使用 IntelliSense 了解相关属性。
|
||||||
|
// 悬停以查看现有属性的描述。
|
||||||
|
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "pwa-chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Chrome against localhost",
|
||||||
|
"url": "https://api.buzhiyushu.cn",
|
||||||
|
"webRoot": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
85
App.vue
Normal file
85
App.vue
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<style lang="scss">
|
||||||
|
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
|
||||||
|
@import "@/uni_modules/uview-ui/index.scss";
|
||||||
|
</style>
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<router-view />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
onLaunch() {
|
||||||
|
console.log('App Launch')
|
||||||
|
// 检查登录状态
|
||||||
|
this.checkLoginStatus()
|
||||||
|
// 设置全局下拉刷新
|
||||||
|
this.setGlobalRefresh()
|
||||||
|
},
|
||||||
|
onShow() {
|
||||||
|
console.log('App Show')
|
||||||
|
// 切换到前台时检查登录状态
|
||||||
|
this.checkLoginStatus()
|
||||||
|
},
|
||||||
|
onHide() {
|
||||||
|
console.log('App Hide')
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 设置全局下拉刷新
|
||||||
|
setGlobalRefresh() {
|
||||||
|
// 设置全局下拉刷新
|
||||||
|
uni.setBackgroundColor({
|
||||||
|
backgroundColor: '#F5F5F5' // 下拉背景色
|
||||||
|
})
|
||||||
|
|
||||||
|
// 设置下拉刷新的样式(仅支持iOS)
|
||||||
|
uni.setBackgroundTextStyle({
|
||||||
|
textStyle: 'dark' // 下拉loading的样式
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 全局下拉刷新触发
|
||||||
|
async onPullDownRefresh() {
|
||||||
|
try {
|
||||||
|
// 重新检查登录状态
|
||||||
|
await this.checkLoginStatus()
|
||||||
|
// 获取当前页面实例
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const currentPage = pages[pages.length - 1]
|
||||||
|
|
||||||
|
// 如果当前页面有自己的刷新方法,则调用
|
||||||
|
if (currentPage.$vm.refresh) {
|
||||||
|
await currentPage.$vm.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 停止下拉刷新
|
||||||
|
uni.stopPullDownRefresh()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('刷新失败:', error)
|
||||||
|
uni.stopPullDownRefresh()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async checkLoginStatus() {
|
||||||
|
try {
|
||||||
|
// 检查本地存储的登录状态
|
||||||
|
const isLoggedIn = await this.$store.dispatch('checkLogin')
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
const token = uni.getStorageSync('token')
|
||||||
|
const userInfo = uni.getStorageSync('userInfo')
|
||||||
|
if (token && userInfo) {
|
||||||
|
// 恢复登录状态
|
||||||
|
this.$store.commit('SET_TOKEN', token)
|
||||||
|
this.$store.commit('SET_USER_INFO', userInfo)
|
||||||
|
this.$store.commit('SET_LOGIN_STATUS', true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('检查登录状态失败:', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
63
README.md
Normal file
63
README.md
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# 图书上传系统 - 页面拆分说明
|
||||||
|
|
||||||
|
## 已完成工作
|
||||||
|
|
||||||
|
已将原有的单页面应用拆分为三个独立页面:
|
||||||
|
|
||||||
|
1. **首页(pages/index/index.vue)**
|
||||||
|
- 重新设计为导航页面
|
||||||
|
- 提供两种上传方式的入口:ISBN上传和仅书名上传
|
||||||
|
- 简洁直观的UI,便于用户选择
|
||||||
|
|
||||||
|
2. **ISBN上传页面(pages/isbn-upload/index.vue)**
|
||||||
|
- 专门用于ISBN扫码上传
|
||||||
|
- 包含扫码功能、书籍信息填写、图片上传等功能
|
||||||
|
- 与原页面中的ISBN上传部分功能一致
|
||||||
|
|
||||||
|
3. **仅书名上传页面(pages/title-upload/index.vue)**
|
||||||
|
- 专门用于根据书名搜索上传
|
||||||
|
- 包含书名搜索、结果选择、图片上传等功能
|
||||||
|
- 与原页面中的仅书名上传部分功能一致
|
||||||
|
|
||||||
|
## 下一步操作
|
||||||
|
|
||||||
|
为完成系统集成,需要进行以下操作:
|
||||||
|
|
||||||
|
1. **更新pages.json配置文件**
|
||||||
|
- 添加新创建的页面路径
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "pages/index/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "图书上传系统"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/isbn-upload/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "ISBN上传"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/title-upload/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "仅书名上传"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 其他已有页面...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **测试新页面功能**
|
||||||
|
- 确保所有功能正常运行
|
||||||
|
- 检查页面间的跳转是否流畅
|
||||||
|
- 验证各项功能是否与原系统一致
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
- 拆分后的页面共用同样的组件和样式
|
||||||
|
- 保留了原始功能,只是将其分散到不同页面
|
||||||
|
- 如有UI上的问题,可能需要调整相应的样式
|
||||||
650
api/kongfz.js
Normal file
650
api/kongfz.js
Normal file
@ -0,0 +1,650 @@
|
|||||||
|
/**
|
||||||
|
* 孔夫子旧书网API服务
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录孔夫子旧书网
|
||||||
|
* @param {string} username - 用户名
|
||||||
|
* @param {string} password - 密码
|
||||||
|
* @returns {Promise<{success: boolean, token: string, message: string}>} - 登录结果
|
||||||
|
*/
|
||||||
|
export function login(username, password) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!username || !password) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '请输入用户名和密码'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建请求参数
|
||||||
|
const url = 'https://login.kongfz.com/Pc/Login/account';
|
||||||
|
const data = {
|
||||||
|
loginName: username,
|
||||||
|
loginPass: password,
|
||||||
|
autoLogin: '0',
|
||||||
|
returnUrl: 'http://user.kongfz.com/'
|
||||||
|
};
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'POST',
|
||||||
|
data: data,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
console.log("登录...", res)
|
||||||
|
// 检查登录是否成功
|
||||||
|
if (res.data && res.data.indexOf(
|
||||||
|
"window.location.href='https://login.kongfz.cn/Pc/Session/rsync") !== -1) {
|
||||||
|
// 提取PHPSESSID
|
||||||
|
const cookies = res.cookies;
|
||||||
|
let phpsessid = '';
|
||||||
|
|
||||||
|
if (cookies && cookies.length > 0) {
|
||||||
|
for (const cookie of cookies) {
|
||||||
|
if (cookie.indexOf('PHPSESSID=') !== -1) {
|
||||||
|
phpsessid = cookie.split('PHPSESSID=')[1].split(';')[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phpsessid) {
|
||||||
|
resolve({
|
||||||
|
success: true,
|
||||||
|
token: phpsessid,
|
||||||
|
message: '登录成功'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '登录失败: 未找到PHPSESSID'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 尝试解析错误信息
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(res.data);
|
||||||
|
if (data.errCode === 1001) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '登录失败: 账号或密码错误'
|
||||||
|
});
|
||||||
|
} else if (data.errInfo) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: `登录失败: ${data.errInfo}`
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '登录失败: 未知错误'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '登录失败: 响应不包含成功跳转信息'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(new Error(`登录请求失败: ${err.errMsg}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品列表
|
||||||
|
* @param {string} token - 登录令牌
|
||||||
|
* @param {Object} params - 查询参数
|
||||||
|
* @param {function} onProgress - 进度回调
|
||||||
|
* @returns {Promise<Array>} - 商品列表
|
||||||
|
*/
|
||||||
|
export function fetchItems(token, params = {}, onProgress = null) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!token) {
|
||||||
|
reject(new Error('请先登录获取Token'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// const token = 'ebb26189289d0dc068f9aac748881bccf890e694';
|
||||||
|
const url = 'https://seller.kongfz.com/pc-gw/book-manage-service/client/pc/goods/unSold/list';
|
||||||
|
const headers = {
|
||||||
|
'Cookie': `PHPSESSID=${token}`,
|
||||||
|
// 'Cookie': 'PHPSESSID=ebb26189289d0dc068f9aac748881bccf890e694'
|
||||||
|
// 'User-Agent' 头在浏览器环境中无法设置,会被拒绝
|
||||||
|
// 'Content-Type': 'application/json'
|
||||||
|
};
|
||||||
|
|
||||||
|
let page = 1;
|
||||||
|
const size = 50;
|
||||||
|
const allItemIds = [];
|
||||||
|
|
||||||
|
const fetchPage = () => {
|
||||||
|
// 准备请求体
|
||||||
|
const requestBody = {
|
||||||
|
"requestType": "onSale", // 标识 出售中
|
||||||
|
"isItemSnEqual": "0",
|
||||||
|
"page": page,
|
||||||
|
"size": size
|
||||||
|
};
|
||||||
|
|
||||||
|
// 添加可选参数
|
||||||
|
if (params.itemSn) requestBody.itemSn = params.itemSn;
|
||||||
|
if (params.priceMin) requestBody.priceMin = params.priceMin;
|
||||||
|
if (params.priceMax) requestBody.priceMax = params.priceMax;
|
||||||
|
if (params.startCreateTime) requestBody.startCreateTime = params.startCreateTime;
|
||||||
|
if (params.endCreateTime) requestBody.endCreateTime = params.endCreateTime;
|
||||||
|
|
||||||
|
// 调用进度回调
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(`正在获取第 ${page} 页数据...`);
|
||||||
|
// 添加请求参数日志
|
||||||
|
if (page === 1) {
|
||||||
|
onProgress(`请求参数: ${JSON.stringify(requestBody)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("请求参数", requestBody)
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'POST',
|
||||||
|
data: requestBody,
|
||||||
|
header: headers,
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
console.error('API 失败响应:', res);
|
||||||
|
reject(new Error(`API返回错误: HTTP ${res.statusCode}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = res.data;
|
||||||
|
if (!data.status) {
|
||||||
|
console.error('API 失败响应:', data);
|
||||||
|
reject(new Error(`API返回错误: ${data.errMessage || '未知错误'}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取商品列表
|
||||||
|
const result = data.result || {};
|
||||||
|
const productInfo = result.productInfoPageResult || {};
|
||||||
|
const items = productInfo.list || [];
|
||||||
|
const pager = productInfo.pager || {};
|
||||||
|
|
||||||
|
// 提取商品ID
|
||||||
|
for (const item of items) {
|
||||||
|
const itemId = item.itemId;
|
||||||
|
if (itemId) {
|
||||||
|
allItemIds.push({
|
||||||
|
id: itemId,
|
||||||
|
status: 'wait'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新状态
|
||||||
|
const totalPages = pager.pages || 0;
|
||||||
|
const totalCount = pager.count || 0;
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(`获取到 ${items.length} 个商品 (第 ${page}/${totalPages} 页)`);
|
||||||
|
// 添加更详细的商品信息
|
||||||
|
if (items.length > 0) {
|
||||||
|
const firstItem = items[0];
|
||||||
|
onProgress(
|
||||||
|
`商品示例: ID=${firstItem.itemId}, 标题=${firstItem.title || '无标题'}, 价格=${firstItem.price || '未知'}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// 添加总数信息
|
||||||
|
onProgress(`当前已获取: ${allItemIds.length}/${totalCount} 个商品`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否还有下一页
|
||||||
|
if (page >= totalPages) {
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(`拉取完成,共获取 ${allItemIds.length} 个商品`);
|
||||||
|
if (allItemIds.length === 0) {
|
||||||
|
onProgress('未找到符合条件的商品,请检查筛选条件');
|
||||||
|
} else {
|
||||||
|
onProgress(
|
||||||
|
`商品ID示例: ${allItemIds.slice(0, 3).map(item => item.id).join(', ')}${allItemIds.length > 3 ? '...' : ''}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(allItemIds);
|
||||||
|
} else {
|
||||||
|
page++;
|
||||||
|
// 延迟1秒后获取下一页
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(`等待1秒后获取下一页...`);
|
||||||
|
}
|
||||||
|
setTimeout(fetchPage, 1000);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
const errorMsg = `拉取商品失败: ${err.errMsg}`;
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(errorMsg);
|
||||||
|
onProgress('请检查网络连接是否正常');
|
||||||
|
onProgress('请确认登录状态是否有效');
|
||||||
|
}
|
||||||
|
reject(new Error(errorMsg));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 开始获取第一页
|
||||||
|
fetchPage();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取商品模板字段
|
||||||
|
* @param {string} token - 登录令牌
|
||||||
|
* @param {string} itemId - 商品ID
|
||||||
|
* @returns {Promise<Object>} - 商品模板字段
|
||||||
|
*/
|
||||||
|
export function getItemTplFields(token, itemId) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!token) {
|
||||||
|
reject(new Error('请先登录获取Token'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url =
|
||||||
|
`https://seller.kongfz.com/pc/itemInfo/getTplFields?itemId=${itemId}&isClone=1&v=${Math.floor(Date.now() / 1000)}`;
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'GET',
|
||||||
|
header: {
|
||||||
|
'Cookie': `PHPSESSID=${token}`,
|
||||||
|
// 'User-Agent' 头在浏览器环境中无法设置,会被拒绝
|
||||||
|
'Referer': 'https://seller.kongfz.com/',
|
||||||
|
'Origin': 'https://seller.kongfz.com'
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
reject(new Error(`HTTP错误: ${res.statusCode}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = res.data;
|
||||||
|
if (data.status === 1) {
|
||||||
|
resolve(data);
|
||||||
|
} else {
|
||||||
|
reject(new Error(`API返回错误: ${data.message || '未知错误'}`));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(new Error(`请求失败: ${err.errMsg}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交商品表单
|
||||||
|
* @param {string} token - 登录令牌
|
||||||
|
* @param {Object} itemData - 商品数据
|
||||||
|
* @param {Object} priceConfig - 价格配置
|
||||||
|
* @returns {Promise<boolean>} - 是否成功
|
||||||
|
*/
|
||||||
|
export function submitItemForm(token, itemData, priceConfig) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!token) {
|
||||||
|
reject(new Error('请先登录获取Token'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 准备表单数据
|
||||||
|
const formData = {
|
||||||
|
"pageType": "clone"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 添加图书基本信息(bookSection)
|
||||||
|
const bookSection = (itemData.data && itemData.data.bookSection) || [];
|
||||||
|
for (const field of bookSection) {
|
||||||
|
const key = field.key;
|
||||||
|
const value = field.value;
|
||||||
|
|
||||||
|
// 处理嵌套字段(如出版时间)
|
||||||
|
if (field.group) {
|
||||||
|
for (const subField of field.group) {
|
||||||
|
const subKey = subField.key;
|
||||||
|
const subValue = subField.value;
|
||||||
|
|
||||||
|
if (subKey && subValue !== null && subValue !== undefined) {
|
||||||
|
formData[subKey] = String(subValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理options中的嵌套
|
||||||
|
if (subField.options) {
|
||||||
|
const selectedValue = subField.value; // 获取当前选中的值
|
||||||
|
for (const option of subField.options) {
|
||||||
|
const optionValue = option.value;
|
||||||
|
// 如果选项是当前选中的,或者选项中有group字段,则处理其中的字段
|
||||||
|
if (String(optionValue) === String(selectedValue) || option.group) {
|
||||||
|
if (option.group) {
|
||||||
|
for (const optionField of option.group) {
|
||||||
|
const optionKey = optionField.key;
|
||||||
|
const optionValue = optionField.value;
|
||||||
|
|
||||||
|
if (optionKey && optionValue !== null && optionValue !== undefined) {
|
||||||
|
formData[optionKey] = String(optionValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理更深层的嵌套
|
||||||
|
if (optionField.group) {
|
||||||
|
for (const deepField of optionField.group) {
|
||||||
|
const deepKey = deepField.key;
|
||||||
|
const deepValue = deepField.value;
|
||||||
|
|
||||||
|
if (deepKey && deepValue !== null && deepValue !== undefined) {
|
||||||
|
formData[deepKey] = String(deepValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理更深层的嵌套(如年月)
|
||||||
|
if (subField.group) {
|
||||||
|
for (const deepField of subField.group) {
|
||||||
|
const deepKey = deepField.key;
|
||||||
|
const deepValue = deepField.value;
|
||||||
|
|
||||||
|
if (deepKey && deepValue !== null && deepValue !== undefined) {
|
||||||
|
formData[deepKey] = String(deepValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加顶层字段
|
||||||
|
if (key && value !== null && value !== undefined) {
|
||||||
|
formData[key] = String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 特殊处理 yearsGroup 字段,确保处理其 options 中的字段
|
||||||
|
if (key === 'yearsGroup' && field.options) {
|
||||||
|
const selectedValue = value; // 获取当前选中的值
|
||||||
|
for (const option of field.options) {
|
||||||
|
const optionValue = option.value;
|
||||||
|
// 如果选项是当前选中的,处理其中的字段
|
||||||
|
if (String(optionValue) === String(selectedValue) && option.group) {
|
||||||
|
for (const optionField of option.group) {
|
||||||
|
const optionKey = optionField.key;
|
||||||
|
const optionValue = optionField.value;
|
||||||
|
|
||||||
|
if (optionKey && optionValue !== null && optionValue !== undefined) {
|
||||||
|
formData[optionKey] = String(optionValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理出版时间的年月字段
|
||||||
|
if (optionKey === 'pubDate' && optionField.group) {
|
||||||
|
for (const dateField of optionField.group) {
|
||||||
|
const dateKey = dateField.key;
|
||||||
|
const dateValue = dateField.value;
|
||||||
|
|
||||||
|
if (dateKey && dateValue !== null && dateValue !== undefined) {
|
||||||
|
formData[dateKey] = String(dateValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加商品基本信息
|
||||||
|
const goodsSection = (itemData.data && itemData.data.goodsSection) || [];
|
||||||
|
for (const field of goodsSection) {
|
||||||
|
const key = field.key;
|
||||||
|
const value = field.value;
|
||||||
|
|
||||||
|
// 跳过 images 字段,因为我们会单独处理图片
|
||||||
|
if (key === 'images') {
|
||||||
|
const images = field.images || [];
|
||||||
|
for (let i = 0; i < images.length; i++) {
|
||||||
|
formData[`images[${i}][imgId]`] = String(images[i].imgId || '');
|
||||||
|
formData[`images[${i}][imgType]`] = String(images[i].imgType || '');
|
||||||
|
formData[`images[${i}][imgDesc]`] = '';
|
||||||
|
formData[`images[${i}][isMain]`] = String(images[i].isMain || '');
|
||||||
|
formData[`images[${i}][imgUrl]`] = images[i].imgUrl || '';
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key && value !== null && value !== undefined) {
|
||||||
|
// 特殊处理价格字段
|
||||||
|
if (key === 'price') {
|
||||||
|
try {
|
||||||
|
let price = parseFloat(value);
|
||||||
|
// 应用价格调整
|
||||||
|
if (priceConfig.configType === 1) { // 折扣
|
||||||
|
price *= (priceConfig.value / 100);
|
||||||
|
} else if (priceConfig.configType === 2) { // 加减值
|
||||||
|
price += priceConfig.value; // priceConfig.value已经包含了正负号
|
||||||
|
} else if (priceConfig.configType === 3) { // 直接赋值
|
||||||
|
price = priceConfig.value;
|
||||||
|
}
|
||||||
|
formData[key] = price.toFixed(2);
|
||||||
|
} catch (e) {
|
||||||
|
formData[key] = String(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 添加到表单数据
|
||||||
|
formData[key] = String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加物流信息
|
||||||
|
const shippingSection = (itemData.data && itemData.data.shippingSection) || [];
|
||||||
|
for (const field of shippingSection) {
|
||||||
|
const key = field.key;
|
||||||
|
const value = field.value;
|
||||||
|
|
||||||
|
if (key && value !== null && value !== undefined) {
|
||||||
|
formData[key] = String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加交付信息
|
||||||
|
const deliverSection = (itemData.data && itemData.data.deliverSection) || [];
|
||||||
|
for (const field of deliverSection) {
|
||||||
|
const key = field.key;
|
||||||
|
const value = field.value;
|
||||||
|
|
||||||
|
if (key && value !== null && value !== undefined) {
|
||||||
|
formData[key] = String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加分类ID
|
||||||
|
const categorySection = (itemData.data && itemData.data.categorySection) || {};
|
||||||
|
if (categorySection.value !== null && categorySection.value !== undefined) {
|
||||||
|
formData.catId = String(categorySection.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = 'https://seller.kongfz.com/pc/itemInfo/add';
|
||||||
|
console.log("formData1111111111", formData)
|
||||||
|
// 发送请求
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'POST',
|
||||||
|
data: formData,
|
||||||
|
header: {
|
||||||
|
'Cookie': `PHPSESSID=${token}`,
|
||||||
|
// 'User-Agent' 头在浏览器环境中无法设置,会被拒绝
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'Referer': 'https://seller.kongfz.com/',
|
||||||
|
'Origin': 'https://seller.kongfz.com'
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
console.log("处理后的res", res)
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
reject(new Error(`HTTP错误: ${res.statusCode}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = res.data;
|
||||||
|
if (res.statusCode === 200 && data.status === 1) {
|
||||||
|
// 保存新商品ID到本地存储,同时保存对应的旧商品ID
|
||||||
|
if (data.data) {
|
||||||
|
try {
|
||||||
|
const newId = String(data.data); // 确保newId为字符串
|
||||||
|
const oldId = String(formData.itemId); // 确保oldId为字符串
|
||||||
|
|
||||||
|
// 严格校验oldId和newId都不为空
|
||||||
|
const existingNewIds = uni.getStorageSync('kongfz_new_ids') || [];
|
||||||
|
const newIds = Array.isArray(existingNewIds) ? existingNewIds : [];
|
||||||
|
if (oldId && newId && oldId.trim() !== '' && newId.trim() !== '') {
|
||||||
|
newIds.push({
|
||||||
|
oldId: oldId,
|
||||||
|
newId: newId,
|
||||||
|
createTime: new Date().toISOString()
|
||||||
|
});
|
||||||
|
uni.setStorageSync('kongfz_new_ids', newIds);
|
||||||
|
console.log('新商品ID已保存:', newId, '对应旧ID:', oldId);
|
||||||
|
console.log('存储的ids', newIds);
|
||||||
|
} else {
|
||||||
|
console.warn('跳过保存无效的商品ID:', {
|
||||||
|
oldId,
|
||||||
|
newId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('保存新商品ID失败:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(new Error(`提交表单失败: ${err.errMsg}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新孔网平台商品ID
|
||||||
|
* @param {Array} items - 商品ID对应关系数组,格式:[{oldPlatformId: "旧ID", newPlatformId: "新ID"}]
|
||||||
|
* @returns {Promise<{success: boolean, message: string}>} - 处理结果
|
||||||
|
*/
|
||||||
|
export function batchUpdatePddPlatformId(items) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!items || !Array.isArray(items) || items.length === 0) {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: '请提供有效的商品ID对应关系'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = 'https://api.buzhiyushu.cn/zhishu/shopGoodsPublished/batchUpdateKfzPlatformId';
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'POST',
|
||||||
|
data: items,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode === 200) {
|
||||||
|
const data = res.data;
|
||||||
|
if (data.code === 200) {
|
||||||
|
resolve({
|
||||||
|
success: true,
|
||||||
|
message: data.msg || '操作成功'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: data.msg || '操作失败'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
message: `HTTP错误: ${res.statusCode}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(new Error(`请求失败: ${err.errMsg}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除商品
|
||||||
|
* @param {string} token - 登录令牌
|
||||||
|
* @param {string} itemId - 商品ID
|
||||||
|
* @returns {Promise<boolean>} - 是否成功
|
||||||
|
*/
|
||||||
|
export function deleteItem(token, itemId) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!token) {
|
||||||
|
reject(new Error('请先登录获取Token'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = 'https://seller.kongfz.com/pc-gw/book-manage-service/client/pc/goods/quickUpdate';
|
||||||
|
|
||||||
|
// 准备JSON数据
|
||||||
|
const payload = {
|
||||||
|
"itemId": String(itemId),
|
||||||
|
"updateType": "delete",
|
||||||
|
"value": "1"
|
||||||
|
};
|
||||||
|
|
||||||
|
uni.request({
|
||||||
|
url: url,
|
||||||
|
method: 'POST',
|
||||||
|
data: payload,
|
||||||
|
header: {
|
||||||
|
'Cookie': `PHPSESSID=${token}`,
|
||||||
|
// 'User-Agent' 头在浏览器环境中无法设置,会被拒绝
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
'Referer': 'https://seller.kongfz.com/',
|
||||||
|
'Origin': 'https://seller.kongfz.com'
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
console.log("delect", res)
|
||||||
|
if (res.statusCode !== 200) {
|
||||||
|
reject(new Error(`HTTP错误: ${res.statusCode}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = res.data;
|
||||||
|
if (result.status === true || result.status === 1) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(new Error(`删除商品时出错: ${err.errMsg}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
247
components/BookConditionSelect.vue
Normal file
247
components/BookConditionSelect.vue
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
<template>
|
||||||
|
<view class="view-container">
|
||||||
|
<view class="view-item horizontal">
|
||||||
|
<!-- 品相标签 -->
|
||||||
|
<view class="label-horizontal">品相</view>
|
||||||
|
<!-- 横向滑动选择区 -->
|
||||||
|
<scroll-view class="tag-scroll-group" scroll-x>
|
||||||
|
<view class="tag-input-group">
|
||||||
|
<view v-for="(item, index) in internalConditions" :key="index"
|
||||||
|
:class="['custom-tag', { 'custom-tag-checked': item.checked }]"
|
||||||
|
@click="handleSelect(index)">
|
||||||
|
<text class="custom-tag-text">{{ item.name }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'BookConditionSelect',
|
||||||
|
|
||||||
|
data() {
|
||||||
|
// 组件内部维护品相数据
|
||||||
|
return {
|
||||||
|
internalConditions: [
|
||||||
|
{ name: '八品', checked: false },
|
||||||
|
{ name: '八五品', checked: false },
|
||||||
|
{ name: '九品', checked: false },
|
||||||
|
{ name: '九五品', checked: false },
|
||||||
|
{ name: '全新', checked: false },
|
||||||
|
{ name: '七品', checked: false },
|
||||||
|
{ name: '六品', checked: false }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
// 处理选择
|
||||||
|
handleSelect(index) {
|
||||||
|
// 更新选中状态
|
||||||
|
this.internalConditions = this.internalConditions.map((item, i) => ({
|
||||||
|
...item,
|
||||||
|
checked: i === index
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 向父组件发送事件 - 只传递索引和名称,避免复杂对象
|
||||||
|
this.$emit('change', index, this.internalConditions[index].name);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取当前选中的品相
|
||||||
|
getSelectedCondition() {
|
||||||
|
const selectedCondition = this.internalConditions.find(item => item.checked);
|
||||||
|
if (selectedCondition) {
|
||||||
|
return {
|
||||||
|
name: selectedCondition.name,
|
||||||
|
index: this.internalConditions.findIndex(item => item.checked)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 外部调用,重置选择
|
||||||
|
resetSelection() {
|
||||||
|
this.internalConditions = this.internalConditions.map(item => ({
|
||||||
|
...item,
|
||||||
|
checked: false
|
||||||
|
}));
|
||||||
|
this.$forceUpdate(); // 强制更新视图
|
||||||
|
},
|
||||||
|
|
||||||
|
// 外部调用,设置选中项
|
||||||
|
setSelection(conditionName) {
|
||||||
|
if (!conditionName) return;
|
||||||
|
|
||||||
|
console.log('设置品相:', conditionName);
|
||||||
|
const index = this.internalConditions.findIndex(item => item.name === conditionName);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
this.internalConditions = this.internalConditions.map((item, i) => ({
|
||||||
|
...item,
|
||||||
|
checked: i === index
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 强制更新视图
|
||||||
|
this.$forceUpdate();
|
||||||
|
|
||||||
|
// 触发change事件
|
||||||
|
this.$emit('change', index, conditionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 添加immediate watch以确保组件能够响应外部更新
|
||||||
|
watch: {
|
||||||
|
internalConditions: {
|
||||||
|
handler(newVal) {
|
||||||
|
console.log('品相数据更新:', newVal);
|
||||||
|
this.$forceUpdate(); // 强制更新视图
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.view-container {
|
||||||
|
display: flex;
|
||||||
|
background-color: #fff;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
padding: 4rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
position: relative;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
display: inline;
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
height: 40rpx;
|
||||||
|
line-height: 40rpx;
|
||||||
|
color: #000;
|
||||||
|
font-size: 29rpx;
|
||||||
|
background-color: #ccc;
|
||||||
|
border-top-left-radius: 10rpx;
|
||||||
|
border-bottom-left-radius: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-input-group {
|
||||||
|
display: inline-flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
margin-top: 8rpx;
|
||||||
|
min-width: max-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-container {
|
||||||
|
display: flex;
|
||||||
|
background-color: #fff;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item {
|
||||||
|
flex: 1;
|
||||||
|
/* padding: rpx 10rpx; */
|
||||||
|
color: #666;
|
||||||
|
position: relative;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 水平布局样式 */
|
||||||
|
.view-item.horizontal {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 品相标签横向样式 */
|
||||||
|
.label-horizontal {
|
||||||
|
padding: 0rpx 15rpx;
|
||||||
|
text-align: center;
|
||||||
|
height: 60rpx;
|
||||||
|
line-height: 60rpx;
|
||||||
|
color: #000;
|
||||||
|
font-size: 28rpx;
|
||||||
|
background-color: #ccc;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .tag-input-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 15rpx;
|
||||||
|
align-items: center;
|
||||||
|
} */
|
||||||
|
|
||||||
|
/* 调整u-tag组件样式,适应水平布局 */
|
||||||
|
/* 调整u-tag组件样式,适应水平布局 */
|
||||||
|
/* 调整u-tag组件样式,适应水平布局 */
|
||||||
|
::v-deep .u-tag--large {
|
||||||
|
height: 60rpx !important;
|
||||||
|
line-height: 60rpx !important;
|
||||||
|
padding: 0 40rpx !important;
|
||||||
|
min-width: 120rpx !important;
|
||||||
|
font-size: 36rpx !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep .u-tag__text--large {
|
||||||
|
font-size: 36rpx !important;
|
||||||
|
line-height: 60rpx !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 横向滑动容器 */
|
||||||
|
.tag-scroll-group {
|
||||||
|
flex: 1;
|
||||||
|
width: 0;
|
||||||
|
min-width: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow-x: scroll;
|
||||||
|
padding-bottom: 2rpx;
|
||||||
|
}
|
||||||
|
.tag-input-group {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: nowrap;
|
||||||
|
margin-top: 8rpx;
|
||||||
|
}
|
||||||
|
.custom-tag {
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 110rpx;
|
||||||
|
height: 54rpx;
|
||||||
|
padding: 0 32rpx;
|
||||||
|
margin: 0 8rpx;
|
||||||
|
font-size: 32rpx;
|
||||||
|
border: 2rpx solid #e0e0e0;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
background: #f7f7f7;
|
||||||
|
color: #888;
|
||||||
|
transition: all 0.2s;
|
||||||
|
box-sizing: border-box;
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 54rpx;
|
||||||
|
}
|
||||||
|
.custom-tag-checked {
|
||||||
|
background: #1976d2;
|
||||||
|
color: #fff;
|
||||||
|
border-color: #1976d2;
|
||||||
|
}
|
||||||
|
.custom-tag-text {
|
||||||
|
font-size: 32rpx;
|
||||||
|
line-height: 54rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
552
components/BookFilterDisplay.vue
Normal file
552
components/BookFilterDisplay.vue
Normal file
@ -0,0 +1,552 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 筛选按钮 -->
|
||||||
|
<view class="button-group">
|
||||||
|
<u-popup :show="popupShow" @close="close" @open="open" mode="bottom" round="10">
|
||||||
|
<view class="filter-popup">
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">出版社</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in publisherOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.publisher" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="togglePublisherFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">作者</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in authorOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.author" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="toggleAuthorFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-buttons">
|
||||||
|
<u-button text="重置" type="info" plain @click="resetFilters" />
|
||||||
|
<u-button text="确定" type="primary" @click="applyFilters" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</u-popup>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="book-list">
|
||||||
|
<view class="label">
|
||||||
|
<view style="display: inline-block;width: 380rpx;text-align: left;">
|
||||||
|
在售商品(总价/书价/运费)
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="btn" @click="onSwitchCompareType">
|
||||||
|
{{ compareType === 'isbn' ? '书名比价' : 'ISBN比价' }}
|
||||||
|
</view>
|
||||||
|
<view class="btn" @click="popupShow = true">更多筛序</view>
|
||||||
|
</view>
|
||||||
|
<!-- 在售商品展示区域 -->
|
||||||
|
<view class="container" v-if="(isFiltered ? filteredOnSaleProducts : displayOnSaleProducts).length > 0">
|
||||||
|
<view class="product-grid">
|
||||||
|
<view class="product-card"
|
||||||
|
v-for="(product, index) in isFiltered ? filteredOnSaleProducts : displayOnSaleProducts"
|
||||||
|
:key="index">
|
||||||
|
<view class="product-image-container">
|
||||||
|
<image class="product-image" :src="product.imageUrl" mode="aspectFit"
|
||||||
|
@click="previewImage(product.imageUrl, isFiltered ? filteredOnSaleProducts : displayOnSaleProducts)">
|
||||||
|
</image>
|
||||||
|
<view class="price-details">
|
||||||
|
<text>{{product.totalPrice}}/{{product.bookPrice}}/{{product.shippingFee}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="product-info">
|
||||||
|
<text class="product-price"
|
||||||
|
style="font-size: 26rpx;">{{product.totalPrice}}/{{product.qualityText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'book-filter-display',
|
||||||
|
props: {
|
||||||
|
// 接收父组件传递的数据
|
||||||
|
onSaleProducts: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
compareType: {
|
||||||
|
type: String,
|
||||||
|
default: 'isbn'
|
||||||
|
},
|
||||||
|
publisherAuthorMap: {
|
||||||
|
type: Map,
|
||||||
|
default: () => new Map()
|
||||||
|
},
|
||||||
|
authorPublisherMap: {
|
||||||
|
type: Map,
|
||||||
|
default: () => new Map()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
popupShow: false,
|
||||||
|
isFiltered: false,
|
||||||
|
publisherOptions: [],
|
||||||
|
authorOptions: [],
|
||||||
|
displayOnSaleProducts: [],
|
||||||
|
filteredOnSaleProducts: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
onSaleProducts: {
|
||||||
|
handler(newProducts) {
|
||||||
|
if (newProducts && newProducts.length > 0) {
|
||||||
|
// 对商品数据按照总价从低到高排序
|
||||||
|
const sortedData = [...newProducts].sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a.totalPrice) || 0;
|
||||||
|
const priceB = parseFloat(b.totalPrice) || 0;
|
||||||
|
return priceA - priceB; // 从低到高排序
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前12条数据用于展示
|
||||||
|
this.displayOnSaleProducts = sortedData.slice(0, 12);
|
||||||
|
|
||||||
|
// 提取出版社和作者信息
|
||||||
|
this.extractPublishersAndAuthors();
|
||||||
|
} else {
|
||||||
|
this.displayOnSaleProducts = [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
open() {
|
||||||
|
this.popupShow = true;
|
||||||
|
this.$emit('popup-open');
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.popupShow = false;
|
||||||
|
this.$emit('popup-close');
|
||||||
|
},
|
||||||
|
onSwitchCompareType() {
|
||||||
|
const newType = this.compareType === 'isbn' ? 'title' : 'isbn';
|
||||||
|
this.$emit('switch-compare-type', newType);
|
||||||
|
},
|
||||||
|
previewImage(currentUrl, productList) {
|
||||||
|
// 检查productList是否存在且是数组
|
||||||
|
let urls = [];
|
||||||
|
|
||||||
|
if (productList && Array.isArray(productList)) {
|
||||||
|
// 提取所有图片 URL
|
||||||
|
urls = productList.map(item => item.imageUrl);
|
||||||
|
} else {
|
||||||
|
// 如果productList不存在或不是数组,则只使用当前URL
|
||||||
|
urls = [currentUrl];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保urls中至少有一个有效的URL
|
||||||
|
if (!urls.length || !urls[0]) {
|
||||||
|
console.error('没有有效的图片URL可预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用 UniApp 预览接口,添加长按操作
|
||||||
|
uni.previewImage({
|
||||||
|
current: currentUrl, // 当前显示图片
|
||||||
|
urls: urls, // 所有图片列表
|
||||||
|
longPressActions: {
|
||||||
|
itemList: ['保存图片', '分享图片'],
|
||||||
|
success: function(data) {
|
||||||
|
console.log('选择了第' + (data.tapIndex + 1) + '个按钮');
|
||||||
|
},
|
||||||
|
fail: function(err) {
|
||||||
|
console.log(err.errMsg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: () => {},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('预览失败:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 从商品数据中提取出版社和作者信息
|
||||||
|
extractPublishersAndAuthors() {
|
||||||
|
// 提取出版社
|
||||||
|
const publishers = new Set();
|
||||||
|
this.onSaleProducts.forEach(product => {
|
||||||
|
if (product.publisher) {
|
||||||
|
publishers.add(product.publisher);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取作者
|
||||||
|
const authors = new Set();
|
||||||
|
this.onSaleProducts.forEach(product => {
|
||||||
|
if (product.author) {
|
||||||
|
authors.add(product.author);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 转换为选项数组
|
||||||
|
this.publisherOptions = Array.from(publishers).map(publisher => ({
|
||||||
|
publisher,
|
||||||
|
checked: false,
|
||||||
|
visible: true // 添加可见性属性
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.authorOptions = Array.from(authors).map(author => ({
|
||||||
|
author,
|
||||||
|
checked: false,
|
||||||
|
visible: true // 添加可见性属性
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
// 切换出版社筛选
|
||||||
|
togglePublisherFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.publisherOptions[index].checked = !this.publisherOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的出版社
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
// 如果没有选中任何出版社,显示所有作者
|
||||||
|
if (selectedPublishers.length === 0) {
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的出版社
|
||||||
|
const currentPublisher = this.publisherOptions[index].publisher;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的作者
|
||||||
|
if (!this.publisherOptions[index].checked) {
|
||||||
|
// 重置所有作者的可见性
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的出版社更新作者可见性
|
||||||
|
selectedPublishers.forEach(publisher => {
|
||||||
|
if (this.publisherAuthorMap.has(publisher)) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap.get(publisher);
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (relatedAuthors.has(item.author)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该出版社相关的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
// 检查该作者是否与当前选中的出版社相关
|
||||||
|
if (this.publisherAuthorMap.has(currentPublisher)) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap.get(currentPublisher);
|
||||||
|
item.visible = relatedAuthors.has(item.author);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 切换作者筛选
|
||||||
|
toggleAuthorFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.authorOptions[index].checked = !this.authorOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的作者
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选中任何作者,显示所有出版社
|
||||||
|
if (selectedAuthors.length === 0) {
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的作者
|
||||||
|
const currentAuthor = this.authorOptions[index].author;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的出版社
|
||||||
|
if (!this.authorOptions[index].checked) {
|
||||||
|
// 重置所有出版社的可见性
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的作者更新出版社可见性
|
||||||
|
selectedAuthors.forEach(author => {
|
||||||
|
if (this.authorPublisherMap.has(author)) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap.get(author);
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (relatedPublishers.has(item.publisher)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该作者相关的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
// 检查该出版社是否与当前选中的作者相关
|
||||||
|
if (this.authorPublisherMap.has(currentAuthor)) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap.get(currentAuthor);
|
||||||
|
item.visible = relatedPublishers.has(item.publisher);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 重置筛选
|
||||||
|
resetFilters() {
|
||||||
|
// 重置出版社选项
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true; // 确保所有出版社选项可见
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置作者选项
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true; // 确保所有作者选项可见
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置筛选状态
|
||||||
|
this.isFiltered = false;
|
||||||
|
|
||||||
|
// 恢复排序后的前十条数据
|
||||||
|
this.filteredOnSaleProducts = [];
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 触发重置事件
|
||||||
|
this.$emit('reset-filters');
|
||||||
|
},
|
||||||
|
// 应用筛选
|
||||||
|
applyFilters() {
|
||||||
|
// 获取选中的出版社
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
// 获取选中的作者
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选择任何筛选条件,则显示排序后的前十条数据
|
||||||
|
if (selectedPublishers.length === 0 && selectedAuthors.length === 0) {
|
||||||
|
this.filteredOnSaleProducts = [];
|
||||||
|
this.isFiltered = false;
|
||||||
|
} else {
|
||||||
|
// 筛选在售商品
|
||||||
|
let filteredProducts = this.onSaleProducts.filter(product => {
|
||||||
|
const matchPublisher = selectedPublishers.length === 0 ||
|
||||||
|
(product.publisher && selectedPublishers.includes(product.publisher));
|
||||||
|
const matchAuthor = selectedAuthors.length === 0 ||
|
||||||
|
(product.author && selectedAuthors.includes(product.author));
|
||||||
|
return matchPublisher && matchAuthor;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 对筛选后的结果按总价从低到高排序
|
||||||
|
filteredProducts = filteredProducts.sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a.totalPrice) || 0;
|
||||||
|
const priceB = parseFloat(b.totalPrice) || 0;
|
||||||
|
return priceA - priceB; // 从低到高排序
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前10条数据
|
||||||
|
this.filteredOnSaleProducts = filteredProducts.slice(0, 10);
|
||||||
|
this.isFiltered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 触发应用筛选事件
|
||||||
|
this.$emit('apply-filters', {
|
||||||
|
filteredProducts: this.filteredOnSaleProducts,
|
||||||
|
selectedPublishers,
|
||||||
|
selectedAuthors
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.book-list {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label {
|
||||||
|
padding: 10rpx;
|
||||||
|
display: block;
|
||||||
|
width: calc(100% - 20rpx);
|
||||||
|
height: 40rpx;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2rpx solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label>.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 120rpx;
|
||||||
|
height: 30rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #3c9cff;
|
||||||
|
border-radius: 10%;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 7rpx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(50% - 5rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image {
|
||||||
|
height: 200rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 8rpx);
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 180rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 140rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info {
|
||||||
|
padding: 8rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info>.product-price {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #ff6b00;
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 4rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.price-details {
|
||||||
|
font-size: 22rpx;
|
||||||
|
line-height: 1.2;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
color: #ffffff;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 4rpx 0;
|
||||||
|
border-radius: 0 0 8rpx 8rpx;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20rpx;
|
||||||
|
margin: 10rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-section {
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-popup {
|
||||||
|
padding: 30rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 40rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
865
components/BookProductList.vue
Normal file
865
components/BookProductList.vue
Normal file
@ -0,0 +1,865 @@
|
|||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<!-- 比价和筛选按钮 -->
|
||||||
|
<view class="button-group">
|
||||||
|
<u-popup :show="popupShow" @close="close" @open="open" mode="bottom" round="10">
|
||||||
|
<view class="filter-popup">
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">出版社</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in publisherOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.publisher" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="togglePublisherFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">作者</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in authorOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.author" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="toggleAuthorFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-buttons">
|
||||||
|
<u-button text="重置" type="info" plain @click="resetFilters" />
|
||||||
|
<u-button text="确定" type="primary" @click="applyFilters" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</u-popup>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="book-list">
|
||||||
|
<view class="product-header">
|
||||||
|
<view class="blue-block"></view>
|
||||||
|
<view class="title-text">
|
||||||
|
在售商品(总价/书价/运费)
|
||||||
|
</view>
|
||||||
|
<view class="header-buttons">
|
||||||
|
<view class="btn" :class="{ 'btn-loading': isLoading }" @click="switchCompareType"
|
||||||
|
v-if="showCompareButton">
|
||||||
|
<u-loading-icon v-if="isLoading" mode="circle" size="20" color="#ffffff"></u-loading-icon>
|
||||||
|
<text v-else>{{ compareType === 'isbn' ? '书名比价' : 'ISBN比价' }}</text>
|
||||||
|
</view>
|
||||||
|
<view class="btn" :class="{ 'btn-loading': isLoading }" @click="handleCopyrightCompare"
|
||||||
|
v-if="showCopyrightButton">
|
||||||
|
<u-loading-icon v-if="isLoading" mode="circle" size="20" color="#ffffff"></u-loading-icon>
|
||||||
|
<text v-else>版权页比价</text>
|
||||||
|
</view>
|
||||||
|
<view class="btn" @click="popupShow = true" v-if="showFilterButton">更多筛选</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- 在售商品展示区域 -->
|
||||||
|
<view class="container" v-if="(isFiltered ? filteredOnSaleProducts : displayOnSaleProducts).length > 0">
|
||||||
|
<view class="product-grid">
|
||||||
|
<view class="product-card"
|
||||||
|
v-for="(product, index) in isFiltered ? filteredOnSaleProducts : displayOnSaleProducts"
|
||||||
|
:key="index">
|
||||||
|
<view class="product-image-container">
|
||||||
|
<image class="product-image" :src="product.imageUrl" mode="aspectFit"
|
||||||
|
@click="previewImage(product.imageUrl, isFiltered ? filteredOnSaleProducts : displayOnSaleProducts)">
|
||||||
|
</image>
|
||||||
|
<view class="price-details">
|
||||||
|
<text>{{product.totalPrice}}/{{product.bookPrice}}/{{product.shippingFee}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="product-info">
|
||||||
|
<text class="product-price"
|
||||||
|
style="font-size: 26rpx;">{{product.totalPrice}}/{{product.qualityText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="empty-products" v-else>
|
||||||
|
<text>暂无在售商品信息</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { checkMemberBooksCount } from '@/components/MemberBookCheck.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'BookProductList',
|
||||||
|
props: {
|
||||||
|
// 接收初始数据
|
||||||
|
initialOnSaleProducts: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
initialDisplayOnSaleProducts: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
initialCompareType: {
|
||||||
|
type: String,
|
||||||
|
default: 'isbn'
|
||||||
|
},
|
||||||
|
isbn: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
bookName: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
showCompareButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true // 默认显示比价按钮
|
||||||
|
},
|
||||||
|
showCopyrightButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
publisher: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
author: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
showFilterButton: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 筛选相关
|
||||||
|
popupShow: false,
|
||||||
|
compareType: this.initialCompareType,
|
||||||
|
isLoading: false,
|
||||||
|
// 数据相关
|
||||||
|
onSaleProducts: this.initialOnSaleProducts,
|
||||||
|
displayOnSaleProducts: this.initialDisplayOnSaleProducts,
|
||||||
|
filteredOnSaleProducts: [],
|
||||||
|
// 筛选选项
|
||||||
|
publisherOptions: [],
|
||||||
|
authorOptions: [],
|
||||||
|
isFiltered: false,
|
||||||
|
// 关联映射
|
||||||
|
publisherAuthorMap: new Map(),
|
||||||
|
authorPublisherMap: new Map(),
|
||||||
|
// 添加排序类型
|
||||||
|
currentSortType: uni.getStorageSync('sortType') || '7', // 默认按总价排序
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
initialOnSaleProducts: {
|
||||||
|
handler(newValue) {
|
||||||
|
this.onSaleProducts = newValue;
|
||||||
|
this.extractPublishersAndAuthors();
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
initialDisplayOnSaleProducts: {
|
||||||
|
handler(newValue) {
|
||||||
|
this.displayOnSaleProducts = newValue;
|
||||||
|
this.filteredOnSaleProducts = [...newValue];
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
initialCompareType: {
|
||||||
|
handler(newValue) {
|
||||||
|
this.compareType = newValue;
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
// 添加对排序类型的监听
|
||||||
|
currentSortType: {
|
||||||
|
handler(newSortType) {
|
||||||
|
if (this.onSaleProducts && this.onSaleProducts.length > 0) {
|
||||||
|
this.sortProducts(newSortType);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
// 组件挂载时提取出版社和作者信息
|
||||||
|
this.extractPublishersAndAuthors();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setCompareType(type) {
|
||||||
|
this.compareType = type;
|
||||||
|
},
|
||||||
|
// 打开和关闭筛选弹窗
|
||||||
|
open() {
|
||||||
|
this.popupShow = true;
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.popupShow = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 切换比价类型
|
||||||
|
async switchCompareType() {
|
||||||
|
// 检查用户是否可以上传书籍
|
||||||
|
const canUpload = await checkMemberBooksCount();
|
||||||
|
if (!canUpload) {
|
||||||
|
// 如果不能上传,则直接返回,不继续执行
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 如果正在加载中,直接返回
|
||||||
|
if (this.isLoading) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 设置加载状态
|
||||||
|
this.isLoading = true;
|
||||||
|
|
||||||
|
const newType = this.compareType === 'isbn' ? 'title' : 'isbn';
|
||||||
|
this.compareType = newType;
|
||||||
|
|
||||||
|
// 发出类型切换事件
|
||||||
|
await this.$emit('compare-type-change', {
|
||||||
|
type: newType,
|
||||||
|
value: newType === 'isbn' ? this.isbn : this.bookName
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('切换比价类型失败:', error);
|
||||||
|
|
||||||
|
// 检查是否是重复提交错误
|
||||||
|
if (error.responseData && error.responseData.code === 500 &&
|
||||||
|
error.responseData.msg === "Repeat submit is not allowed, please try again later") {
|
||||||
|
uni.showToast({
|
||||||
|
title: '操作太频繁,请稍后再试',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '切换失败,请稍后重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// 延迟关闭加载状态,避免闪烁
|
||||||
|
setTimeout(() => {
|
||||||
|
this.isLoading = false;
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 提取出版社和作者
|
||||||
|
extractPublishersAndAuthors() {
|
||||||
|
if (!this.onSaleProducts || this.onSaleProducts.length === 0) return;
|
||||||
|
|
||||||
|
// 创建出版社-作者关联映射
|
||||||
|
const publisherAuthorMap = new Map();
|
||||||
|
const authorPublisherMap = new Map();
|
||||||
|
|
||||||
|
// 遍历商品数据,建立关联关系
|
||||||
|
this.onSaleProducts.forEach(product => {
|
||||||
|
if (product.publisher && product.author) {
|
||||||
|
// 添加出版社-作者关联
|
||||||
|
if (!publisherAuthorMap.has(product.publisher)) {
|
||||||
|
publisherAuthorMap.set(product.publisher, new Set());
|
||||||
|
}
|
||||||
|
publisherAuthorMap.get(product.publisher).add(product.author);
|
||||||
|
|
||||||
|
// 添加作者-出版社关联
|
||||||
|
if (!authorPublisherMap.has(product.author)) {
|
||||||
|
authorPublisherMap.set(product.author, new Set());
|
||||||
|
}
|
||||||
|
authorPublisherMap.get(product.author).add(product.publisher);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 保存关联映射
|
||||||
|
this.publisherAuthorMap = publisherAuthorMap;
|
||||||
|
this.authorPublisherMap = authorPublisherMap;
|
||||||
|
|
||||||
|
// 提取出版社
|
||||||
|
const publishers = new Set();
|
||||||
|
this.onSaleProducts.forEach(product => {
|
||||||
|
if (product.publisher) {
|
||||||
|
publishers.add(product.publisher);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取作者
|
||||||
|
const authors = new Set();
|
||||||
|
this.onSaleProducts.forEach(product => {
|
||||||
|
if (product.author) {
|
||||||
|
authors.add(product.author);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 转换为选项数组
|
||||||
|
this.publisherOptions = Array.from(publishers).map(publisher => ({
|
||||||
|
publisher,
|
||||||
|
checked: false,
|
||||||
|
visible: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.authorOptions = Array.from(authors).map(author => ({
|
||||||
|
author,
|
||||||
|
checked: false,
|
||||||
|
visible: true
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 切换出版社筛选
|
||||||
|
togglePublisherFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.publisherOptions[index].checked = !this.publisherOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的出版社
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
// 如果没有选中任何出版社,显示所有作者
|
||||||
|
if (selectedPublishers.length === 0) {
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的出版社
|
||||||
|
const currentPublisher = this.publisherOptions[index].publisher;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的作者
|
||||||
|
if (!this.publisherOptions[index].checked) {
|
||||||
|
// 重置所有作者的可见性
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的出版社更新作者可见性
|
||||||
|
selectedPublishers.forEach(publisher => {
|
||||||
|
if (this.publisherAuthorMap.has(publisher)) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap.get(publisher);
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (relatedAuthors.has(item.author)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该出版社相关的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
// 检查该作者是否与当前选中的出版社相关
|
||||||
|
if (this.publisherAuthorMap.has(currentPublisher)) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap.get(currentPublisher);
|
||||||
|
item.visible = relatedAuthors.has(item.author);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 切换作者筛选
|
||||||
|
toggleAuthorFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.authorOptions[index].checked = !this.authorOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的作者
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选中任何作者,显示所有出版社
|
||||||
|
if (selectedAuthors.length === 0) {
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的作者
|
||||||
|
const currentAuthor = this.authorOptions[index].author;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的出版社
|
||||||
|
if (!this.authorOptions[index].checked) {
|
||||||
|
// 重置所有出版社的可见性
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的作者更新出版社可见性
|
||||||
|
selectedAuthors.forEach(author => {
|
||||||
|
if (this.authorPublisherMap.has(author)) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap.get(author);
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (relatedPublishers.has(item.publisher)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该作者相关的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
// 检查该出版社是否与当前选中的作者相关
|
||||||
|
if (this.authorPublisherMap.has(currentAuthor)) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap.get(currentAuthor);
|
||||||
|
item.visible = relatedPublishers.has(item.publisher);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 重置筛选
|
||||||
|
resetFilters() {
|
||||||
|
// 重置出版社选项
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置作者选项
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置筛选状态
|
||||||
|
this.isFiltered = false;
|
||||||
|
|
||||||
|
// 恢复排序后的数据
|
||||||
|
this.filteredOnSaleProducts = [...this.displayOnSaleProducts];
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 发出重置事件
|
||||||
|
this.$emit('filters-reset');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 应用筛选
|
||||||
|
applyFilters() {
|
||||||
|
// 获取选中的出版社
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
// 获取选中的作者
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选择任何筛选条件,则显示原始数据
|
||||||
|
if (selectedPublishers.length === 0 && selectedAuthors.length === 0) {
|
||||||
|
this.filteredOnSaleProducts = [...this.displayOnSaleProducts];
|
||||||
|
this.isFiltered = false;
|
||||||
|
} else {
|
||||||
|
// 筛选在售商品
|
||||||
|
let filteredProducts = this.onSaleProducts.filter(product => {
|
||||||
|
const matchPublisher = selectedPublishers.length === 0 ||
|
||||||
|
(product.publisher && selectedPublishers.includes(product.publisher));
|
||||||
|
const matchAuthor = selectedAuthors.length === 0 ||
|
||||||
|
(product.author && selectedAuthors.includes(product.author));
|
||||||
|
return matchPublisher && matchAuthor;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 对筛选后的结果按总价从低到高排序
|
||||||
|
filteredProducts = filteredProducts.sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a.totalPrice) || 0;
|
||||||
|
const priceB = parseFloat(b.totalPrice) || 0;
|
||||||
|
return priceA - priceB;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前10条数据
|
||||||
|
this.filteredOnSaleProducts = filteredProducts.slice(0, 10);
|
||||||
|
this.isFiltered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 发出筛选结果事件
|
||||||
|
this.$emit('filters-applied', this.filteredOnSaleProducts);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 预览图片
|
||||||
|
previewImage(currentUrl, productList) {
|
||||||
|
// 检查productList是否存在且是数组
|
||||||
|
let urls = [];
|
||||||
|
|
||||||
|
if (productList && Array.isArray(productList)) {
|
||||||
|
// 提取所有图片 URL
|
||||||
|
urls = productList.map(item => item.imageUrl);
|
||||||
|
} else {
|
||||||
|
// 如果productList不存在或不是数组,则只使用当前URL
|
||||||
|
urls = [currentUrl];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保urls中至少有一个有效的URL
|
||||||
|
if (!urls.length || !urls[0]) {
|
||||||
|
console.error('没有有效的图片URL可预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用 UniApp 预览接口,添加长按操作
|
||||||
|
uni.previewImage({
|
||||||
|
current: currentUrl, // 当前显示图片
|
||||||
|
urls: urls, // 所有图片列表
|
||||||
|
longPressActions: {
|
||||||
|
itemList: ['保存图片', '分享图片'],
|
||||||
|
success: function(data) {
|
||||||
|
console.log('选择了第' + (data.tapIndex + 1) + '个按钮');
|
||||||
|
},
|
||||||
|
fail: function(err) {
|
||||||
|
console.log(err.errMsg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: () => {},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('预览失败:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改 updateProducts 方法
|
||||||
|
updateProducts(products) {
|
||||||
|
this.onSaleProducts = products;
|
||||||
|
this.sortProducts(this.currentSortType);
|
||||||
|
this.extractPublishersAndAuthors();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 添加更新排序类型的方法
|
||||||
|
updateSortType(sortType) {
|
||||||
|
console.log('更新排序类型:', sortType);
|
||||||
|
this.currentSortType = sortType;
|
||||||
|
// 直接对现有数据进行排序
|
||||||
|
if (this.onSaleProducts && this.onSaleProducts.length > 0) {
|
||||||
|
this.sortProducts(sortType);
|
||||||
|
}
|
||||||
|
// 触发父组件重新获取数据
|
||||||
|
this.$emit('compare-type-change', {
|
||||||
|
type: this.compareType,
|
||||||
|
value: this.compareType === 'isbn' ? this.isbn : this.bookName,
|
||||||
|
sortType: sortType
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改 sortProducts 方法
|
||||||
|
sortProducts(sortType) {
|
||||||
|
console.log("123131231", sortType)
|
||||||
|
if (!this.onSaleProducts || this.onSaleProducts.length === 0) return;
|
||||||
|
|
||||||
|
// 根据排序方式选择排序字段
|
||||||
|
const sortField = sortType === '5' ? 'bookPrice' : 'totalPrice';
|
||||||
|
|
||||||
|
// 对商品数据按照选择的字段从低到高排序
|
||||||
|
const sortedData = [...this.onSaleProducts].sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a[sortField]) || 0;
|
||||||
|
const priceB = parseFloat(b[sortField]) || 0;
|
||||||
|
return priceA - priceB;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前12条数据用于展示
|
||||||
|
this.displayOnSaleProducts = sortedData.slice(0, 12);
|
||||||
|
this.filteredOnSaleProducts = [...this.displayOnSaleProducts];
|
||||||
|
this.isFiltered = false;
|
||||||
|
|
||||||
|
// 发出数据更新事件
|
||||||
|
this.$emit('products-updated', this.displayOnSaleProducts);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取当前显示的商品数据
|
||||||
|
getCurrentProducts() {
|
||||||
|
return this.isFiltered ? this.filteredOnSaleProducts : this.displayOnSaleProducts;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取筛选状态
|
||||||
|
getFilterStatus() {
|
||||||
|
return {
|
||||||
|
isFiltered: this.isFiltered,
|
||||||
|
selectedPublishers: this.publisherOptions.filter(item => item.checked).map(item => item.publisher),
|
||||||
|
selectedAuthors: this.authorOptions.filter(item => item.checked).map(item => item.author)
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
// 添加版权页比价方法
|
||||||
|
async handleCopyrightCompare() {
|
||||||
|
if (this.isLoading) return;
|
||||||
|
try {
|
||||||
|
this.isLoading = true;
|
||||||
|
// 打印传递参数日志
|
||||||
|
console.log('【版权页比价按钮参数】', {
|
||||||
|
bookName: this.bookName,
|
||||||
|
publisher: this.publisher,
|
||||||
|
author: this.author
|
||||||
|
});
|
||||||
|
// 发出版权页比价事件,传递出版社和作者信息
|
||||||
|
await this.$emit('copyright-compare', {
|
||||||
|
type: 'copyright',
|
||||||
|
bookName: this.bookName,
|
||||||
|
publisher: this.publisher,
|
||||||
|
author: this.author
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('版权页比价失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: '比价失败,请稍后重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.isLoading = false;
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.book-list {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label {
|
||||||
|
padding: 10rpx;
|
||||||
|
display: block;
|
||||||
|
width: calc(100% - 20rpx);
|
||||||
|
height: 40rpx;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2rpx solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label>.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 120rpx;
|
||||||
|
height: 30rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #3c9cff;
|
||||||
|
border-radius: 10%;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 8rpx);
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 180rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 140rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info {
|
||||||
|
padding: 8rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info>.product-price {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #ff6b00;
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 4rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.price-details {
|
||||||
|
font-size: 22rpx;
|
||||||
|
line-height: 1.2;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
color: #ffffff;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 4rpx 0;
|
||||||
|
border-radius: 0 0 8rpx 8rpx;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20rpx;
|
||||||
|
margin: 10rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-section {
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-popup {
|
||||||
|
padding: 30rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-products {
|
||||||
|
padding: 40rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 28rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 响应式布局 */
|
||||||
|
@media screen and (max-width: 768rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 7rpx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(50% - 5rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container {
|
||||||
|
height: 200rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 新增商品列表标题栏样式 */
|
||||||
|
.product-header {
|
||||||
|
padding: 10rpx;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
width: calc(100% - 20rpx);
|
||||||
|
height: 40rpx;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2rpx solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
flex: 1;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-buttons .btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 6rpx 14rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 120rpx;
|
||||||
|
height: 30rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #3c9cff;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-buttons .btn {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 6rpx 14rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 120rpx;
|
||||||
|
height: 30rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #3c9cff;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加加载状态的样式 */
|
||||||
|
.btn-loading {
|
||||||
|
opacity: 0.7;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保加载图标居中显示 */
|
||||||
|
.header-buttons .btn .u-loading-icon {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blue-block {
|
||||||
|
width: 8rpx;
|
||||||
|
height: 32rpx;
|
||||||
|
background-color: #007AFF;
|
||||||
|
margin-right: 16rpx;
|
||||||
|
border-radius: 4rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
681
components/CameraUpload.vue
Normal file
681
components/CameraUpload.vue
Normal file
@ -0,0 +1,681 @@
|
|||||||
|
<template>
|
||||||
|
<view class="update">
|
||||||
|
<view class="upload-container">
|
||||||
|
<view class="image-list">
|
||||||
|
<!-- 已拍摄图片预览 - 不显示hidden的图片 -->
|
||||||
|
<view v-for="(file, index) in visibleFileList" :key="index" class="image-item" @click="previewImage(index)">
|
||||||
|
<image :src="file.url" class="preview-img" mode="aspectFill" />
|
||||||
|
<view class="delete-btn" @click.stop="handleDelete(index)">×</view>
|
||||||
|
<!-- 添加上传状态指示器 -->
|
||||||
|
<view v-if="file.status === 'uploading'" class="upload-status uploading">上传中...</view>
|
||||||
|
<view v-if="file.status === 'error'" class="upload-status error">上传失败</view>
|
||||||
|
</view>
|
||||||
|
<!-- 拍照图标,未达上限时显示 -->
|
||||||
|
<view v-if="fileList.length < maxCount" class="camera-icon" @click="handleOpenCamera"
|
||||||
|
hover-class="none">
|
||||||
|
<image src="/static/camera.png" class="icon-img" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- bcode-camera组件 -->
|
||||||
|
<bcode-camera v-if="showCamera" :tipsText="tipsText" :currentCount="visibleFileList.length" :fileList="visibleFileList"
|
||||||
|
@onConfirm="handleCameraConfirm" @onCancel="handleCameraCancel" @onUpload="onUpload"
|
||||||
|
@onDeleteImage="handleDeleteImage"></bcode-camera>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 导入会员书籍数量检查工具
|
||||||
|
import { checkMemberBooksCount } from '@/components/MemberBookCheck.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'CameraUpload',
|
||||||
|
props: {
|
||||||
|
// 初始文件列表
|
||||||
|
value: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
// 最大上传数量
|
||||||
|
maxCount: {
|
||||||
|
type: Number,
|
||||||
|
default: 9
|
||||||
|
},
|
||||||
|
uploadUrl: {
|
||||||
|
type: String,
|
||||||
|
required: true, // 必须传递有效 URL(如 https://xxx.com)
|
||||||
|
default: '' // 可选默认值
|
||||||
|
},
|
||||||
|
// 新增的ISBN和书名props
|
||||||
|
isbn: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
bookName: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showCamera: false,
|
||||||
|
fileList: this.value,
|
||||||
|
uploadQueue: [], // 上传队列
|
||||||
|
isUploading: false, // 是否正在上传
|
||||||
|
processedUrls: new Set() // 新增:用于记录已处理的图片URL
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
tipsText() {
|
||||||
|
return `已拍摄 ${this.fileList.length} 张,最多可拍 ${this.maxCount} 张`;
|
||||||
|
},
|
||||||
|
visibleFileList() {
|
||||||
|
return this.fileList.filter(file => !file.hidden);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value(newVal) {
|
||||||
|
this.fileList = newVal;
|
||||||
|
},
|
||||||
|
// 新增:监听上传队列变化
|
||||||
|
uploadQueue: {
|
||||||
|
handler(newQueue) {
|
||||||
|
if (newQueue.length > 0 && !this.isUploading) {
|
||||||
|
this.processUploadQueue();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
},
|
||||||
|
// 监听文件列表变化,检查上传状态
|
||||||
|
fileList: {
|
||||||
|
handler(newFileList) {
|
||||||
|
// 检查是否有文件正在上传中
|
||||||
|
const isUploading = newFileList.some(file => file.status === 'uploading');
|
||||||
|
// 通知父组件上传状态
|
||||||
|
this.$emit('upload-status-change', isUploading);
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 新增:检查文件是否已处理
|
||||||
|
isProcessed(url) {
|
||||||
|
return this.processedUrls.has(url);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增:标记文件为已处理
|
||||||
|
markAsProcessed(url) {
|
||||||
|
this.processedUrls.add(url);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增:检查是否有文件正在上传中
|
||||||
|
checkUploadingStatus() {
|
||||||
|
const isUploading = this.fileList.some(file => file.status === 'uploading');
|
||||||
|
// 通知父组件上传状态
|
||||||
|
this.$emit('upload-status-change', isUploading);
|
||||||
|
return isUploading;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改:处理新图片
|
||||||
|
async processNewImage(imageUrl) {
|
||||||
|
if (this.isProcessed(imageUrl)) {
|
||||||
|
console.log('图片已处理过,跳过:', imageUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取已使用的编号(包括2,因为它预留给识图照片)
|
||||||
|
const usedNums = new Set(["2"]);
|
||||||
|
|
||||||
|
// 收集当前文件列表中已使用的编号,并确保不会重复使用已上传文件的编号
|
||||||
|
this.fileList.forEach(file => {
|
||||||
|
if (file.num) {
|
||||||
|
usedNums.add(file.num);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 找到下一个可用的编号(从1开始)
|
||||||
|
let nextNum = 1;
|
||||||
|
while (usedNums.has(nextNum.toString())) {
|
||||||
|
nextNum++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加到文件列表
|
||||||
|
const newFile = {
|
||||||
|
url: imageUrl,
|
||||||
|
status: "ready",
|
||||||
|
message: "待上传",
|
||||||
|
num: nextNum.toString()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 在添加新文件之前,检查是否存在相同编号的文件
|
||||||
|
const existingFileIndex = this.fileList.findIndex(f => f.num === nextNum.toString());
|
||||||
|
if (existingFileIndex !== -1) {
|
||||||
|
// 如果存在相同编号的文件,为新文件找一个新的编号
|
||||||
|
nextNum = Math.max(...Array.from(this.fileList.map(f => parseInt(f.num) || 0))) + 1;
|
||||||
|
newFile.num = nextNum.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fileList.push(newFile);
|
||||||
|
|
||||||
|
// 重新排序文件列表,但保持识图照片的位置
|
||||||
|
this.fileList.sort((a, b) => {
|
||||||
|
// 如果其中一个是识图照片,保持其位置
|
||||||
|
if (a.name?.startsWith('识图-')) return 1;
|
||||||
|
if (b.name?.startsWith('识图-')) return -1;
|
||||||
|
|
||||||
|
const numA = parseInt(a.num) || 999;
|
||||||
|
const numB = parseInt(b.num) || 999;
|
||||||
|
return numA - numB;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加到上传队列
|
||||||
|
await this.addToUploadQueue(newFile, this.fileList.indexOf(newFile));
|
||||||
|
|
||||||
|
// 如果这是第一张普通照片(num="1"),检查并上传识图照片
|
||||||
|
if (newFile.num === "1") {
|
||||||
|
const ocrPhoto = this.fileList.find(file =>
|
||||||
|
file.name?.startsWith('识图-') &&
|
||||||
|
file.status === 'ready' &&
|
||||||
|
file.url.startsWith('wxfile://tmp') || file.url.startsWith('http://tmp') // 检查是否为临时路径
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ocrPhoto) {
|
||||||
|
console.log('发现待上传的识图照片,准备上传:', ocrPhoto);
|
||||||
|
// 更新识图照片的hidden属性为false
|
||||||
|
const ocrIndex = this.fileList.indexOf(ocrPhoto);
|
||||||
|
const updatedOcrPhoto = {
|
||||||
|
...ocrPhoto,
|
||||||
|
hidden: false,
|
||||||
|
num: "2" // 确保编号为2
|
||||||
|
};
|
||||||
|
|
||||||
|
this.fileList.splice(ocrIndex, 1, updatedOcrPhoto);
|
||||||
|
|
||||||
|
// 立即上传识图照片
|
||||||
|
await this.addToUploadQueue(updatedOcrPhoto, ocrIndex);
|
||||||
|
|
||||||
|
// 通知父组件更新
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
console.log('已将识图照片设置为第二张并添加到上传队列');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记为已处理
|
||||||
|
this.markAsProcessed(imageUrl);
|
||||||
|
|
||||||
|
// 通知父组件更新
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
|
||||||
|
console.log(`新照片已添加,编号为: ${nextNum}`);
|
||||||
|
console.log('当前文件列表:', this.fileList.map(f => ({
|
||||||
|
url: f.url,
|
||||||
|
num: f.num,
|
||||||
|
name: f.name,
|
||||||
|
hidden: f.hidden,
|
||||||
|
status: f.status
|
||||||
|
})));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改:onUpload 处理程序
|
||||||
|
async onUpload(data) {
|
||||||
|
if (!data || !data.url) {
|
||||||
|
console.error('无效的图片URL');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('接收到新拍摄的照片:', data);
|
||||||
|
await this.processNewImage(data.url);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改:handleCameraConfirm 处理程序
|
||||||
|
async handleCameraConfirm(data) {
|
||||||
|
console.log('相机确认完成,接收到数据:', data);
|
||||||
|
|
||||||
|
// 关闭相机
|
||||||
|
this.showCamera = false;
|
||||||
|
this.$emit('camera-status-change', false);
|
||||||
|
|
||||||
|
// 检查是否有图片数据
|
||||||
|
if (!data || (!data.images && !data.url)) {
|
||||||
|
console.log('没有新的图片需要处理');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 处理图片数组
|
||||||
|
if (data.images && data.images.length > 0) {
|
||||||
|
console.log(`处理${data.images.length}张新图片`);
|
||||||
|
for (const imageUrl of data.images) {
|
||||||
|
await this.processNewImage(imageUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 处理单张图片
|
||||||
|
else if (data.url) {
|
||||||
|
await this.processNewImage(data.url);
|
||||||
|
|
||||||
|
// 检查是否有识图照片需要上传
|
||||||
|
const ocrPhoto = this.fileList.find(file => file.name?.startsWith('识图-') && file.status === 'ready');
|
||||||
|
if (ocrPhoto) {
|
||||||
|
console.log('发现待上传的识图照片,准备上传');
|
||||||
|
// 更新识图照片的hidden属性为false,使其显示出来
|
||||||
|
const ocrIndex = this.fileList.indexOf(ocrPhoto);
|
||||||
|
this.fileList.splice(ocrIndex, 1, {
|
||||||
|
...ocrPhoto,
|
||||||
|
hidden: false,
|
||||||
|
num: "2" // 设置为第二张照片
|
||||||
|
});
|
||||||
|
|
||||||
|
// 将识图照片添加到上传队列
|
||||||
|
this.addToUploadQueue(ocrPhoto, ocrIndex);
|
||||||
|
|
||||||
|
// 通知父组件更新
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理照片失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: '处理照片失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改:handleCameraCancel 处理程序(处理识图照片)
|
||||||
|
async handleCameraCancel(data) {
|
||||||
|
if (!data || !data.url) {
|
||||||
|
this.showCamera = false;
|
||||||
|
this.$emit('camera-status-change', false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('收到识图照片数据:', data);
|
||||||
|
|
||||||
|
// 添加识图照片(hidden为true,等待第一张照片上传后再显示)
|
||||||
|
const file = {
|
||||||
|
url: data.url,
|
||||||
|
status: "ready",
|
||||||
|
message: "待上传",
|
||||||
|
name: `识图-${Date.now()}.jpg`,
|
||||||
|
num: "2", // 预设为第二张照片
|
||||||
|
hidden: true // 初始设置为隐藏
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!this.isProcessed(data.url)) {
|
||||||
|
// 如果已经有识图照片,替换它
|
||||||
|
const existingOcrIndex = this.fileList.findIndex(f => f.name?.startsWith('识图-'));
|
||||||
|
if (existingOcrIndex !== -1) {
|
||||||
|
this.fileList.splice(existingOcrIndex, 1, file);
|
||||||
|
} else {
|
||||||
|
this.fileList.push(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标记为已处理
|
||||||
|
this.markAsProcessed(data.url);
|
||||||
|
|
||||||
|
// 通知父组件更新
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
|
||||||
|
console.log('识图照片已保存,等待第一张照片上传后再显示');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('处理识图照片失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: '处理照片失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
this.showCamera = false;
|
||||||
|
this.$emit('camera-status-change', false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增:单个文件上传方法
|
||||||
|
async uploadSingleFile(file, index) {
|
||||||
|
const parentPage = this.getParentPage();
|
||||||
|
if (!parentPage || typeof parentPage.uploadFilePromise !== 'function') {
|
||||||
|
throw new Error('上传功能不可用');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 更新状态为上传中
|
||||||
|
this.updateFileStatus(index, 'uploading', '上传中');
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const result = await parentPage.uploadFilePromise(file.url, index);
|
||||||
|
|
||||||
|
// 更新状态为成功
|
||||||
|
this.updateFileStatus(index, 'success', '', result);
|
||||||
|
|
||||||
|
console.log(`图片 ${index + 1} 上传成功:`, result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`图片 ${index + 1} 上传失败:`, error);
|
||||||
|
this.updateFileStatus(index, 'error', '上传失败');
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增:更新文件状态的辅助方法
|
||||||
|
updateFileStatus(index, status, message, newUrl = null) {
|
||||||
|
const file = this.fileList[index];
|
||||||
|
if (file) {
|
||||||
|
const updatedFile = {
|
||||||
|
...file,
|
||||||
|
status: status,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
if (newUrl) {
|
||||||
|
updatedFile.url = newUrl;
|
||||||
|
// 保留原有的num和name属性
|
||||||
|
updatedFile.num = file.num;
|
||||||
|
updatedFile.name = file.name;
|
||||||
|
}
|
||||||
|
this.fileList.splice(index, 1, updatedFile);
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 新增:检查文件是否已存在
|
||||||
|
isFileExists(url) {
|
||||||
|
return this.fileList.some(file => file.url === url);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 修改:添加到上传队列的方法
|
||||||
|
async addToUploadQueue(file, index) {
|
||||||
|
// 检查是否已在队列中
|
||||||
|
const isInQueue = this.uploadQueue.some(item => item.file.url === file.url);
|
||||||
|
if (!isInQueue) {
|
||||||
|
console.log('添加新文件到上传队列:', file.url);
|
||||||
|
|
||||||
|
// 获取父页面实例
|
||||||
|
const parentPage = this.getParentPage();
|
||||||
|
if (!parentPage || typeof parentPage.uploadFilePromise !== 'function') {
|
||||||
|
console.error('上传功能不可用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 更新状态为上传中
|
||||||
|
const fileIndex = this.fileList.indexOf(file);
|
||||||
|
if (fileIndex !== -1) {
|
||||||
|
this.fileList.splice(fileIndex, 1, {
|
||||||
|
...file,
|
||||||
|
status: 'uploading',
|
||||||
|
message: '上传中'
|
||||||
|
});
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
// 检查上传状态并通知父组件
|
||||||
|
this.checkUploadingStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传文件
|
||||||
|
const result = await parentPage.uploadFilePromise(file.url, index);
|
||||||
|
|
||||||
|
// 更新状态为成功
|
||||||
|
if (fileIndex !== -1) {
|
||||||
|
this.fileList.splice(fileIndex, 1, {
|
||||||
|
...file,
|
||||||
|
status: 'success',
|
||||||
|
message: '上传成功',
|
||||||
|
url: result, // 使用服务器返回的URL
|
||||||
|
num: file.num, // 保留原有编号
|
||||||
|
name: file.name // 保留原有名称
|
||||||
|
});
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
// 检查上传状态并通知父组件
|
||||||
|
this.checkUploadingStatus();
|
||||||
|
|
||||||
|
// 如果是识图照片,确保保留name属性
|
||||||
|
if (file.name && file.name.startsWith('识图-')) {
|
||||||
|
console.log(`识图照片上传成功,保留name属性: ${file.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`文件上传成功: ${file.url} -> ${result}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('文件上传失败:', error);
|
||||||
|
// 更新状态为失败
|
||||||
|
const fileIndex = this.fileList.indexOf(file);
|
||||||
|
if (fileIndex !== -1) {
|
||||||
|
this.fileList.splice(fileIndex, 1, {
|
||||||
|
...file,
|
||||||
|
status: 'error',
|
||||||
|
message: '上传失败'
|
||||||
|
});
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
// 检查上传状态并通知父组件
|
||||||
|
this.checkUploadingStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('文件已在上传队列中,跳过:', file.url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
previewImage(index) {
|
||||||
|
// 获取可见文件的URL列表
|
||||||
|
const visibleUrls = this.visibleFileList.map(item => item.url);
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
current: this.visibleFileList[index].url,
|
||||||
|
urls: visibleUrls,
|
||||||
|
indicator: 'number', // 显示数字指示器
|
||||||
|
loop: true
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleOpenCamera() {
|
||||||
|
|
||||||
|
// 检查用户是否可以上传书籍
|
||||||
|
const canUpload = await checkMemberBooksCount();
|
||||||
|
if (!canUpload) {
|
||||||
|
// 如果不能上传,则直接返回,不继续执行
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查ISBN和书名是否存在
|
||||||
|
if (!this.isbn || !this.bookName) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '请先填写ISBN和书名',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.fileList.length >= this.maxCount) {
|
||||||
|
uni.showToast({
|
||||||
|
title: `最多只能上传 ${this.maxCount} 张照片`,
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showCamera = true;
|
||||||
|
this.$emit('camera-status-change', true);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取父组件实例的方法
|
||||||
|
getParentPage() {
|
||||||
|
let parent = this.$parent;
|
||||||
|
while (parent) {
|
||||||
|
if (parent.uploadFilePromise) {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
parent = parent.$parent;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
handleDelete(index) {
|
||||||
|
// 获取要删除的可见文件
|
||||||
|
const fileToDelete = this.visibleFileList[index];
|
||||||
|
|
||||||
|
// 在完整fileList中找到对应索引并删除
|
||||||
|
const actualIndex = this.fileList.findIndex(file => file === fileToDelete);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
this.fileList.splice(actualIndex, 1);
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handleDeleteImage(event) {
|
||||||
|
const index = event.index;
|
||||||
|
// 获取可见文件列表中的文件
|
||||||
|
if (index >= 0 && index < this.visibleFileList.length) {
|
||||||
|
const fileToDelete = this.visibleFileList[index];
|
||||||
|
|
||||||
|
// 在完整fileList中找到对应索引并删除
|
||||||
|
const actualIndex = this.fileList.findIndex(file => file === fileToDelete);
|
||||||
|
if (actualIndex !== -1) {
|
||||||
|
this.fileList.splice(actualIndex, 1);
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
uni.showToast({
|
||||||
|
title: '已删除图片',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 1000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 添加一个新方法,专门用于处理文件变化
|
||||||
|
handleFileChange(newFileList) {
|
||||||
|
console.log('CameraUpload组件收到文件变化:', newFileList);
|
||||||
|
|
||||||
|
// 检查是否有识图照片
|
||||||
|
const ocrPhoto = newFileList.find(file => file.name && file.name.startsWith('识图-'));
|
||||||
|
|
||||||
|
if (ocrPhoto) {
|
||||||
|
console.log('发现识图照片:', ocrPhoto);
|
||||||
|
|
||||||
|
// 确保识图照片的num为2
|
||||||
|
const updatedOcrPhoto = {
|
||||||
|
...ocrPhoto,
|
||||||
|
num: "2"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 找出识图照片在列表中的位置
|
||||||
|
const ocrIndex = newFileList.findIndex(file => file.name && file.name.startsWith('识图-'));
|
||||||
|
|
||||||
|
// 更新列表中的识图照片
|
||||||
|
if (ocrIndex !== -1) {
|
||||||
|
newFileList.splice(ocrIndex, 1, updatedOcrPhoto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新文件列表
|
||||||
|
this.fileList = [...newFileList];
|
||||||
|
|
||||||
|
// 触发输入事件
|
||||||
|
this.$emit('input', this.fileList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.update {
|
||||||
|
margin-top: 2rpx;
|
||||||
|
background-color: #3f51b530;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
padding: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-item {
|
||||||
|
position: relative;
|
||||||
|
width: 150rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.delete-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 50rpx;
|
||||||
|
height: 50rpx;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 50rpx;
|
||||||
|
font-size: 50rpx;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.camera-icon {
|
||||||
|
width: 150rpx;
|
||||||
|
height: 150rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none !important;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-img {
|
||||||
|
width: 60rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
outline: none !important;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 新增:上传状态样式 */
|
||||||
|
.upload-status {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
padding: 4rpx;
|
||||||
|
font-size: 20rpx;
|
||||||
|
color: #fff;
|
||||||
|
text-align: center;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploading {
|
||||||
|
background-color: rgba(0, 122, 255, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background-color: rgba(255, 59, 48, 0.7);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加提示文字样式 */
|
||||||
|
.photo-tip {
|
||||||
|
position: fixed;
|
||||||
|
top: 20rpx;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 10000;
|
||||||
|
text-align: center;
|
||||||
|
padding: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.photo-tip text {
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
color: #fff;
|
||||||
|
padding: 10rpx 30rpx;
|
||||||
|
border-radius: 30rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
338
components/CategoryDropdown.vue
Normal file
338
components/CategoryDropdown.vue
Normal file
@ -0,0 +1,338 @@
|
|||||||
|
<!-- components/CategoryDropdown.vue -->
|
||||||
|
<template>
|
||||||
|
<view class="category-dropdown">
|
||||||
|
<view class="select-box" @click="toggleDropdown">
|
||||||
|
<text class="selected-text">{{ displayText }}</text>
|
||||||
|
<view class="arrow" :class="{ 'arrow-up': showDropdown }"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="dropdown-list" v-if="showDropdown">
|
||||||
|
<scroll-view scroll-y style="max-height: 400rpx;">
|
||||||
|
<!-- 调试信息 -->
|
||||||
|
<view v-if="categories.length === 0" class="dropdown-item">
|
||||||
|
<text>加载中或无数据({{loading ? '加载中' : '无数据'}})</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 一级分类 -->
|
||||||
|
<view v-if="currentLevel === 1">
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in categories"
|
||||||
|
:key="index"
|
||||||
|
class="dropdown-item"
|
||||||
|
@click="selectLevel1(item)"
|
||||||
|
>
|
||||||
|
<text>{{ item.name }}</text>
|
||||||
|
<text v-if="item.children && item.children.length" class="arrow-right">›</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 二级分类 -->
|
||||||
|
<view v-else-if="currentLevel === 2">
|
||||||
|
<view class="dropdown-header" @click="backToLevel1">
|
||||||
|
<text class="back-icon">‹</text>
|
||||||
|
<text>返回</text>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in currentParent.children"
|
||||||
|
:key="index"
|
||||||
|
class="dropdown-item"
|
||||||
|
@click="selectLevel2(item)"
|
||||||
|
>
|
||||||
|
<text>{{ item.name }}</text>
|
||||||
|
<text v-if="item.children && item.children.length" class="arrow-right">›</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 三级分类 -->
|
||||||
|
<view v-else-if="currentLevel === 3">
|
||||||
|
<view class="dropdown-header" @click="backToLevel2">
|
||||||
|
<text class="back-icon">‹</text>
|
||||||
|
<text>返回</text>
|
||||||
|
</view>
|
||||||
|
<view
|
||||||
|
v-for="(item, index) in currentParent.children"
|
||||||
|
:key="index"
|
||||||
|
class="dropdown-item"
|
||||||
|
@click="selectCategory(item)"
|
||||||
|
>
|
||||||
|
<text>{{ item.name }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getCategory } from '@/service/categoryService.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'CategoryDropdown',
|
||||||
|
props: {
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择分类'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [Object, String, Number],
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
externalCategories: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
categories: [],
|
||||||
|
selectedCategory: null,
|
||||||
|
showDropdown: false,
|
||||||
|
loading: false,
|
||||||
|
currentLevel: 1,
|
||||||
|
currentParent: null,
|
||||||
|
level1Selection: null,
|
||||||
|
level2Selection: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
displayText() {
|
||||||
|
if (this.selectedCategory) {
|
||||||
|
let text = this.selectedCategory.name;
|
||||||
|
// 如果有上级分类,添加路径
|
||||||
|
if (this.level2Selection) {
|
||||||
|
text = `${this.level2Selection.name} > ${text}`;
|
||||||
|
}
|
||||||
|
if (this.level1Selection) {
|
||||||
|
text = `${this.level1Selection.name} > ${text}`;
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return this.placeholder;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 监听外部传入的分类数据变化
|
||||||
|
externalCategories: {
|
||||||
|
handler(newVal) {
|
||||||
|
if (newVal && newVal.length > 0) {
|
||||||
|
console.log('从外部接收到分类数据:', newVal);
|
||||||
|
this.categories = newVal;
|
||||||
|
console.log('设置分类数据完成,当前categories:', this.categories);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true,
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// 如果没有外部传入的分类数据,才自动获取
|
||||||
|
if (!this.externalCategories || this.externalCategories.length === 0) {
|
||||||
|
this.fetchCategories();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果有初始值,设置选中项
|
||||||
|
if (this.value) {
|
||||||
|
this.selectedCategory = this.value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchCategories(cookiesParam) {
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
// 如果没有传入cookies,从本地存储获取
|
||||||
|
const cookies = cookiesParam || uni.getStorageSync('cookies');
|
||||||
|
console.log('正在获取分类数据,cookies:', cookies);
|
||||||
|
|
||||||
|
const result = await getCategory(cookies);
|
||||||
|
console.log('获取到的分类数据:', result);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// 处理不同的数据格式情况
|
||||||
|
if (result.successResponse && Array.isArray(result.successResponse)) {
|
||||||
|
this.categories = result.successResponse;
|
||||||
|
console.log('成功解析分类数据,数量:', this.categories);
|
||||||
|
} else if (Array.isArray(result)) {
|
||||||
|
this.categories = result;
|
||||||
|
console.log('成功解析分类数据(数组格式),数量:', this.categories.length);
|
||||||
|
} else {
|
||||||
|
console.error('分类数据格式不正确:', result);
|
||||||
|
uni.showToast({
|
||||||
|
title: '分类数据格式不正确',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('未获取到分类数据');
|
||||||
|
uni.showToast({
|
||||||
|
title: '获取分类列表失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取分类失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: '获取分类列表失败',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleDropdown() {
|
||||||
|
if (this.loading || this.disabled) return;
|
||||||
|
|
||||||
|
// 添加调试信息
|
||||||
|
console.log('toggleDropdown被触发,当前categories:', this.categories);
|
||||||
|
console.log('当前categories长度:', this.categories.length);
|
||||||
|
|
||||||
|
if (!this.showDropdown) {
|
||||||
|
// 重置当前级别为1
|
||||||
|
this.currentLevel = 1;
|
||||||
|
this.currentParent = null;
|
||||||
|
}
|
||||||
|
this.showDropdown = !this.showDropdown;
|
||||||
|
},
|
||||||
|
selectLevel1(category) {
|
||||||
|
if (category.children && category.children.length) {
|
||||||
|
this.level1Selection = category;
|
||||||
|
this.currentParent = category;
|
||||||
|
this.currentLevel = 2;
|
||||||
|
} else {
|
||||||
|
this.selectCategory(category);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selectLevel2(category) {
|
||||||
|
if (category.children && category.children.length) {
|
||||||
|
this.level2Selection = category;
|
||||||
|
this.currentParent = category;
|
||||||
|
this.currentLevel = 3;
|
||||||
|
} else {
|
||||||
|
this.selectCategory(category);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selectCategory(category) {
|
||||||
|
this.selectedCategory = category;
|
||||||
|
this.showDropdown = false;
|
||||||
|
// 向父组件发送选中的值
|
||||||
|
this.$emit('input', category);
|
||||||
|
this.$emit('change', category);
|
||||||
|
},
|
||||||
|
backToLevel1() {
|
||||||
|
this.currentLevel = 1;
|
||||||
|
this.currentParent = null;
|
||||||
|
this.level2Selection = null;
|
||||||
|
},
|
||||||
|
backToLevel2() {
|
||||||
|
this.currentLevel = 2;
|
||||||
|
this.currentParent = this.level1Selection;
|
||||||
|
},
|
||||||
|
// 关闭下拉框,用于点击外部区域时调用
|
||||||
|
closeDropdown() {
|
||||||
|
this.showDropdown = false;
|
||||||
|
},
|
||||||
|
// 添加一个手动刷新分类数据的方法
|
||||||
|
refreshCategories(cookies) {
|
||||||
|
console.log('手动刷新分类数据,cookies:', cookies);
|
||||||
|
this.fetchCategories(cookies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.category-dropdown {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.select-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
height: 80rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: 1px solid #e5e5e5;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 90%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-left: 12rpx solid transparent;
|
||||||
|
border-right: 12rpx solid transparent;
|
||||||
|
border-top: 12rpx solid #666;
|
||||||
|
transition: transform 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-up {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-list {
|
||||||
|
position: absolute;
|
||||||
|
top: 90rpx;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #e5e5e5;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
|
||||||
|
z-index: 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
padding: 20rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 1px solid #f5f5f5;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item:active {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-right {
|
||||||
|
font-size: 36rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-header {
|
||||||
|
padding: 20rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #007AFF;
|
||||||
|
border-bottom: 1px solid #f5f5f5;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-icon {
|
||||||
|
font-size: 36rpx;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
71
components/FormInput.vue
Normal file
71
components/FormInput.vue
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<template>
|
||||||
|
<view class="input-group">
|
||||||
|
<view class="general-label">{{ label }}</view>
|
||||||
|
<input
|
||||||
|
class="scan-input"
|
||||||
|
:value="value"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="disabled"
|
||||||
|
@input="$emit('input', $event.target.value)"
|
||||||
|
/>
|
||||||
|
<view v-if="showScanBtn" class="scan-btn" @click="$emit('scan')">
|
||||||
|
<text>{{ scanBtnText }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
label: String,
|
||||||
|
value: [String, Number],
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
showScanBtn: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
scanBtnText: {
|
||||||
|
type: String,
|
||||||
|
default: '扫码'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.input-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.general-label {
|
||||||
|
width: 150rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.scan-input {
|
||||||
|
flex: 1;
|
||||||
|
height: 80rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
.scan-btn {
|
||||||
|
margin-left: 20rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
height: 80rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
background-color: #2979ff;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
112
components/LocationPicker.vue
Normal file
112
components/LocationPicker.vue
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<template>
|
||||||
|
<view class="input-group">
|
||||||
|
<view class="general-label">{{ label }}</view>
|
||||||
|
<view class="select-label" @click="showPicker = true">
|
||||||
|
{{ selectedText || placeholder }}
|
||||||
|
</view>
|
||||||
|
<u-picker
|
||||||
|
:show="showPicker"
|
||||||
|
ref="uPicker"
|
||||||
|
:columns="columns"
|
||||||
|
@confirm="handleConfirm"
|
||||||
|
@change="handleChange"
|
||||||
|
></u-picker>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: '仓库'
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择仓库/货架/货位'
|
||||||
|
},
|
||||||
|
warehouses: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
warehouseShelvesData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
|
shelfLocationsData: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showPicker: false,
|
||||||
|
columns: [[], [], []],
|
||||||
|
selectedText: '',
|
||||||
|
selectedWarehouse: null,
|
||||||
|
selectedShelf: null,
|
||||||
|
selectedLocation: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
warehouses: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal) {
|
||||||
|
if (newVal.length > 0) {
|
||||||
|
this.columns[0] = newVal.map(item => item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleConfirm(e) {
|
||||||
|
this.showPicker = false;
|
||||||
|
const [warehouse, shelf, location] = e.value;
|
||||||
|
this.selectedText = `${warehouse}/${shelf}/${location}`;
|
||||||
|
this.$emit('confirm', {
|
||||||
|
warehouse,
|
||||||
|
shelf,
|
||||||
|
location
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleChange(e) {
|
||||||
|
const { columnIndex, value } = e;
|
||||||
|
if (columnIndex === 0) {
|
||||||
|
const selectedWarehouse = this.warehouses.find(item => item.name === value);
|
||||||
|
if (selectedWarehouse && this.warehouseShelvesData[selectedWarehouse.id]) {
|
||||||
|
this.columns[1] = this.warehouseShelvesData[selectedWarehouse.id].map(item => item.code);
|
||||||
|
this.columns[2] = [];
|
||||||
|
}
|
||||||
|
} else if (columnIndex === 1) {
|
||||||
|
const selectedShelf = this.warehouseShelvesData[this.selectedWarehouse.id].find(item => item.code === value);
|
||||||
|
if (selectedShelf && this.shelfLocationsData[selectedShelf.id]) {
|
||||||
|
this.columns[2] = this.shelfLocationsData[selectedShelf.id].map(item => item.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.input-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.general-label {
|
||||||
|
width: 150rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
.select-label {
|
||||||
|
flex: 1;
|
||||||
|
height: 80rpx;
|
||||||
|
line-height: 80rpx;
|
||||||
|
padding: 0 20rpx;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
892
components/MemberBookCheck.js
Normal file
892
components/MemberBookCheck.js
Normal file
@ -0,0 +1,892 @@
|
|||||||
|
/**
|
||||||
|
* 获取用户业务信息的公共方法
|
||||||
|
* @param {Number} userId - 用户ID
|
||||||
|
* @returns {Promise<Object>} - 返回Promise,包含请求结果
|
||||||
|
*/
|
||||||
|
export const getUserRecbusiness = async (userId) => {
|
||||||
|
const [err, response] = await uni.request({
|
||||||
|
// url: 'https://newadmin.buzhiyushu.cn/settledMember/record/queryMemberBooksCount',
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/user/getUserRecbusiness',
|
||||||
|
// method: 'POST',
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
userId: userId // 确保转换为数字类型
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// console.log('查询会员书籍数量结果:', response);
|
||||||
|
|
||||||
|
// 检查是否有错误
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查孔网翻新会员状态的公共方法
|
||||||
|
* @param {Number} userId - 用户ID
|
||||||
|
* @returns {Promise<Object>} - 返回Promise,包含请求结果
|
||||||
|
*/
|
||||||
|
export const checkKwfwMemberStatus = async (userId) => {
|
||||||
|
const res = await uni.request({
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/orders/checkStatus',
|
||||||
|
method: 'POST',
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
userId: userId,
|
||||||
|
type: 3
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('查询孔网翻新会员结果:', res);
|
||||||
|
return res[1] || res; // 兼容数组结构(H5/小程序不同返回)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查用户是否可以上传书籍
|
||||||
|
* @param {Object} options - 配置选项
|
||||||
|
* @param {Boolean} options.showToast - 是否显示未登录提示,默认为true
|
||||||
|
* @param {Boolean} options.showModal - 是否显示上传达到上限的提示,默认为true
|
||||||
|
* @param {String} options.modalTitle - 提示弹窗的标题,默认为"提示"
|
||||||
|
* @param {String} options.rechargeUrl - 充值页面的URL,默认为"/pages/user/recharge"
|
||||||
|
* @returns {Promise<Boolean>} - 返回Promise,resolve为true表示可以上传,false表示不可上传
|
||||||
|
*/
|
||||||
|
export const checkMemberBooksCount = async (options = {}) => {
|
||||||
|
// 默认选项
|
||||||
|
const defaultOptions = {
|
||||||
|
showToast: true,
|
||||||
|
showModal: true,
|
||||||
|
modalTitle: '提示',
|
||||||
|
rechargeUrl: '/pages/user/recharge',
|
||||||
|
amount: 1 // 默认充值金额,单位元
|
||||||
|
};
|
||||||
|
|
||||||
|
// 合并选项
|
||||||
|
const mergedOptions = {
|
||||||
|
...defaultOptions,
|
||||||
|
...options
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取用户ID
|
||||||
|
const userId = uni.getStorageSync('userId');
|
||||||
|
console.log('获取到的userId:', userId);
|
||||||
|
|
||||||
|
// 检查用户是否已登录
|
||||||
|
if (!userId) {
|
||||||
|
if (mergedOptions.showToast) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '用户未登录,请先登录',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2500
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用查询接口
|
||||||
|
const response = await getUserRecbusiness(userId);
|
||||||
|
console.log("响应",response)
|
||||||
|
// 判断接口返回值
|
||||||
|
if (response.statusCode === 200 && response.data.data.isVip === false) {
|
||||||
|
// 如果返回false,提示用户去充值
|
||||||
|
if (mergedOptions.showModal) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
uni.showModal({
|
||||||
|
title: mergedOptions.modalTitle,
|
||||||
|
content: '您的上传数量已达上限,请充值后继续使用',
|
||||||
|
confirmText: '去充值',
|
||||||
|
cancelText: '取消',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
// 跳转到会员选择页面,指定只显示xcx上书会员
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/user/memberSelect?from=memberCheck&type=xcx'
|
||||||
|
});
|
||||||
|
|
||||||
|
// 返回一个Promise,在用户返回时重新检查
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// 设置一个全局回调函数,供会员选择页面调用
|
||||||
|
getApp().memberSelectCallback = (success) => {
|
||||||
|
if (success) {
|
||||||
|
// 充值成功,重新检查权限
|
||||||
|
checkMemberBooksCount(mergedOptions)
|
||||||
|
.then(canUpload => {
|
||||||
|
if (canUpload) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '现在您可以上传书籍了',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 用户取消,返回false表示不能上传
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果返回true,表示可以上传
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('查询会员书籍数量失败:', error);
|
||||||
|
// 接口调用失败时,默认允许上传,避免阻断用户使用
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 保存当前的settledId,用于支付通知
|
||||||
|
let currentSettledId = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用微信支付
|
||||||
|
* @param {Number} amount - 充值金额
|
||||||
|
* @param {Number} settledId - 会员等级ID
|
||||||
|
* @param {String} paymentType - 支付类型,'normal' 为普通会员,'kwfw' 为孔网翻新会员
|
||||||
|
* @param {String} orderId - 订单id
|
||||||
|
* @returns {Promise<Object>} - 返回支付结果
|
||||||
|
*/
|
||||||
|
export const callWxPay = async (amount, settledId, paymentType = 'normal', orderId) => {
|
||||||
|
try {
|
||||||
|
// 保存settledId到模块变量,供后续调用使用
|
||||||
|
currentSettledId = settledId;
|
||||||
|
console.log('当前的settledId1:', currentSettledId);
|
||||||
|
// 获取用户openid
|
||||||
|
const openid = uni.getStorageSync('openId');
|
||||||
|
if (!openid) {
|
||||||
|
throw new Error('未获取到openid');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取用户ID
|
||||||
|
const userId = uni.getStorageSync('userId');
|
||||||
|
if (!userId) {
|
||||||
|
throw new Error('未获取到userId');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造支付请求参数
|
||||||
|
const payData = {
|
||||||
|
openid: openid,
|
||||||
|
taskId: userId, // 使用用户ID作为任务ID
|
||||||
|
total: amount * 1, // 金额转为分
|
||||||
|
totalStr: amount.toString(),
|
||||||
|
description: `充值金额:${amount}元`,
|
||||||
|
settledId: settledId
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('发起支付请求参数:', payData);
|
||||||
|
|
||||||
|
// 调用后端支付接口
|
||||||
|
const [err, res] = await uni.request({
|
||||||
|
url: 'https://api.buzhiyushu.cn/xcx/jsapiPay',
|
||||||
|
method: 'POST',
|
||||||
|
data: payData,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('支付接口返回:', res);
|
||||||
|
|
||||||
|
if (res.statusCode === 200 && res.data.code === 200) {
|
||||||
|
// 获取支付参数
|
||||||
|
const payParams = res.data.data;
|
||||||
|
console.log('支付参数:', payParams);
|
||||||
|
console.log('支付参数完整数据:', JSON.stringify(payParams));
|
||||||
|
|
||||||
|
// 调起微信支付
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// 在小程序环境中使用wx.requestPayment
|
||||||
|
wx.requestPayment({
|
||||||
|
appId: payParams.appId,
|
||||||
|
timeStamp: payParams.timeStamp,
|
||||||
|
nonceStr: payParams.nonceStr,
|
||||||
|
package: payParams.package,
|
||||||
|
signType: 'RSA',
|
||||||
|
paySign: payParams.paySign,
|
||||||
|
success: function(res) {
|
||||||
|
console.log('支付成功', res);
|
||||||
|
// 支付成功后,调用订单查询接口确认支付状态
|
||||||
|
checkPayStatus(payParams.outTradeNo, currentSettledId, paymentType,
|
||||||
|
orderId).then(orderResult => {
|
||||||
|
if (orderResult.success) {
|
||||||
|
resolve({
|
||||||
|
success: true,
|
||||||
|
data: res,
|
||||||
|
orderResult
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
error: '支付状态确认失败'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('订单查询失败', err);
|
||||||
|
// 即使订单查询失败,也认为支付成功,因为用户已经完成了支付流程
|
||||||
|
resolve({
|
||||||
|
success: true,
|
||||||
|
data: res,
|
||||||
|
orderQueryFailed: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: function(err) {
|
||||||
|
console.error('支付失败', err);
|
||||||
|
resolve({
|
||||||
|
success: false,
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
},
|
||||||
|
complete: function(res) {
|
||||||
|
console.log('支付完成', res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error(res.data.msg || '支付接口调用失败');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('微信支付失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: '支付失败:' + error.message,
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询支付订单状态
|
||||||
|
* @param {String} outTradeNo - 商户订单号
|
||||||
|
* @param {Number} [settledId] - 会员等级ID,可选
|
||||||
|
* @param {String} paymentType - 支付类型,'normal' 为普通会员,'kwfw' 为孔网翻新会员
|
||||||
|
* @returns {Promise<Object>} - 返回订单查询结果
|
||||||
|
*/
|
||||||
|
export const checkPayStatus = async (outTradeNo, currentSettledId, paymentType = 'normal', orderId) => {
|
||||||
|
try {
|
||||||
|
console.log('查询订单号:', outTradeNo); // 添加日志确认订单号
|
||||||
|
console.log('当前的settledId2:', currentSettledId);
|
||||||
|
console.log("订单号", orderId);
|
||||||
|
// 如果未提供settledId参数,使用模块变量
|
||||||
|
const finalSettledId = currentSettledId;
|
||||||
|
if (finalSettledId) {
|
||||||
|
console.log('使用会员等级ID:', finalSettledId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [err, res] = await uni.request({
|
||||||
|
url: 'https://api.buzhiyushu.cn/xcx/queryOrder',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
outTradeNo: outTradeNo
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('订单查询结果:', res);
|
||||||
|
|
||||||
|
if (res.statusCode === 200 && res.data.code === 200) {
|
||||||
|
// 根据支付类型执行不同的处理逻辑
|
||||||
|
if (paymentType === 'normal') {
|
||||||
|
// 普通会员支付:调用通知接口保存支付记录
|
||||||
|
try {
|
||||||
|
获取用户ID
|
||||||
|
const userId = uni.getStorageSync('userId');
|
||||||
|
|
||||||
|
// 准备通知数据
|
||||||
|
const notifyData = {
|
||||||
|
...res.data.data, // 将查询到的订单数据传递给通知接口
|
||||||
|
userId: userId // 添加用户ID
|
||||||
|
};
|
||||||
|
|
||||||
|
// 如果有会员等级ID,添加到通知数据中
|
||||||
|
if (finalSettledId) {
|
||||||
|
notifyData.settledId = finalSettledId;
|
||||||
|
console.log('添加会员等级ID到通知数据:', finalSettledId);
|
||||||
|
}
|
||||||
|
console.log("当前的settledId3:", notifyData.settledId);
|
||||||
|
console.log("通知数据:", notifyData);
|
||||||
|
|
||||||
|
const [notifyErr, notifyRes] = await uni.request({
|
||||||
|
url: 'https://newadmin.buzhiyushu.cn/wechatPay/notification',
|
||||||
|
method: 'POST',
|
||||||
|
data: notifyData,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (notifyErr) {
|
||||||
|
console.error('保存支付记录失败:', notifyErr);
|
||||||
|
} else {
|
||||||
|
console.log('保存支付记录结果:', notifyRes);
|
||||||
|
}
|
||||||
|
} catch (notifyError) {
|
||||||
|
console.error('调用支付通知接口失败:', notifyError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: res.data.data,
|
||||||
|
isPaid: res.data.data.trade_state === 'SUCCESS'
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: res.data.msg || '订单查询失败'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('查询订单状态失败:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会员等级列表
|
||||||
|
* @returns {Promise<Array>} - 返回会员等级列表
|
||||||
|
*/
|
||||||
|
export const getMemberLevelList = async () => {
|
||||||
|
try {
|
||||||
|
const [err, res] = await uni.request({
|
||||||
|
url: 'https://newadmin.buzhiyushu.cn/settledCostConfig/list',
|
||||||
|
// url: 'http://localhost:8089/settledCostConfig/list',
|
||||||
|
method: 'GET',
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('获取会员等级列表结果:', res);
|
||||||
|
|
||||||
|
if (res.data.code === 200 && res.data.data && res.data.data.length > 0) {
|
||||||
|
return res.data.data;
|
||||||
|
} else {
|
||||||
|
throw new Error('获取会员等级列表失败');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取会员等级列表失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示会员等级选择器
|
||||||
|
* @param {Array} levelList - 会员等级列表
|
||||||
|
* @returns {Promise<Object>} - 返回用户选择的会员等级
|
||||||
|
*/
|
||||||
|
export const showMemberLevelSelector = (levelList) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
// 构建选择项
|
||||||
|
const items = levelList.map(level => ({
|
||||||
|
text: `${level.name || '会员等级'} (${level.price}元)`,
|
||||||
|
value: level
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 显示操作菜单让用户选择
|
||||||
|
uni.showActionSheet({
|
||||||
|
itemList: items.map(item => item.text),
|
||||||
|
success: function(res) {
|
||||||
|
const selectedIndex = res.tapIndex;
|
||||||
|
if (selectedIndex >= 0 && selectedIndex < items.length) {
|
||||||
|
resolve(items[selectedIndex].value);
|
||||||
|
} else {
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: function() {
|
||||||
|
resolve(null); // 用户取消选择
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查用户是否为孔网翻新会员
|
||||||
|
* @param {Object} options - 配置选项
|
||||||
|
* @param {Boolean} options.showToast - 是否显示未登录提示,默认为true
|
||||||
|
* @param {Boolean} options.showModal - 是否显示非会员提示,默认为true
|
||||||
|
* @param {String} options.modalTitle - 提示弹窗的标题,默认为"提示"
|
||||||
|
* @returns {Promise<Boolean>} - 返回Promise,resolve为true表示是会员,false表示不是会员
|
||||||
|
*/
|
||||||
|
export const checkKwfwMember = async (options = {}) => {
|
||||||
|
const defaultOptions = {
|
||||||
|
showToast: true,
|
||||||
|
showModal: true,
|
||||||
|
modalTitle: '提示'
|
||||||
|
};
|
||||||
|
|
||||||
|
const mergedOptions = { ...defaultOptions, ...options };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = uni.getStorageSync('userId');
|
||||||
|
console.log('检查孔网翻新会员,获取到的userId:', userId);
|
||||||
|
|
||||||
|
if (!userId) {
|
||||||
|
if (mergedOptions.showToast) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '用户未登录,请先登录',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 2500
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 调用公共方法
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await checkKwfwMemberStatus(userId);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('请求出错:', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 确保返回结构存在
|
||||||
|
if (!response || !response.data) {
|
||||||
|
throw new Error('接口调用失败');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { code, data, message } = response.data;
|
||||||
|
console.log('会员检查结果:', code, data);
|
||||||
|
|
||||||
|
// ✅ 1. 情况一:接口返回用户不存在
|
||||||
|
if (code === 40001) {
|
||||||
|
return await handleNotMemberModal(mergedOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 2. 情况二:接口正常返回,但 isVip 为 false
|
||||||
|
if (code === 200 && data && data.isVip === false) {
|
||||||
|
return await handleNotMemberModal(mergedOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ 3. 情况三:是会员
|
||||||
|
if (code === 200 && data && data.isVip === true) {
|
||||||
|
console.log('当前用户是孔网翻新会员 ✅');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他异常情况
|
||||||
|
console.warn('接口返回未知状态:', code, message);
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('查询孔网翻新会员失败:', error);
|
||||||
|
if (mergedOptions.showToast) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '网络错误,请稍后重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ✅ 单独提取弹窗逻辑,便于多处调用
|
||||||
|
const handleNotMemberModal = (mergedOptions) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (!mergedOptions.showModal) return resolve(false);
|
||||||
|
|
||||||
|
uni.showModal({
|
||||||
|
title: mergedOptions.modalTitle,
|
||||||
|
content: '您还不是孔网翻新会员,需要开通会员才能使用此功能',
|
||||||
|
confirmText: '开通会员',
|
||||||
|
cancelText: '取消',
|
||||||
|
success: (res) => {
|
||||||
|
if (res.confirm) {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/user/memberSelect?from=kwfw&type=kwfw'
|
||||||
|
});
|
||||||
|
|
||||||
|
getApp().kwfwMemberCallback = (success) => {
|
||||||
|
if (success) {
|
||||||
|
checkKwfwMember(mergedOptions).then((isMember) => {
|
||||||
|
if (isMember) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '开通成功,现在您可以使用孔网翻新功能了',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 2000
|
||||||
|
});
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 孔网翻新会员订单插入接口(预留)
|
||||||
|
* @param {Object} orderData - 订单数据
|
||||||
|
* @returns {Promise<Object>} - 返回订单插入结果
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 支付前插入孔网翻新会员订单记录(预留接口)
|
||||||
|
* @param {Object} orderData 订单数据
|
||||||
|
* @returns {Object} 插入结果,包含orderId
|
||||||
|
*/
|
||||||
|
export const createKwfwMemberOrder = async (orderData) => {
|
||||||
|
try {
|
||||||
|
console.log('支付前创建孔网翻新会员订单:', orderData);
|
||||||
|
|
||||||
|
// 获取并验证用户ID
|
||||||
|
let userId = orderData.userId || uni.getStorageSync('userId');
|
||||||
|
if (!userId || userId === 'undefined') {
|
||||||
|
console.error('用户未登录或userId无效');
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '用户未登录,请先登录'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第一步:创建服务
|
||||||
|
// 确保所有参数都有有效值
|
||||||
|
const serviceName = orderData.serviceName || 'xcx翻新会员';
|
||||||
|
const price = orderData.originalPrice || orderData.price || '1';
|
||||||
|
const unit = orderData.unit || '月';
|
||||||
|
const length = orderData.length || '1';
|
||||||
|
const sort = orderData.sort || '1'
|
||||||
|
let vipType = '';
|
||||||
|
if (orderData.memberType == 'kwfw') {
|
||||||
|
vipType = 'xcxRenovate';
|
||||||
|
} else {
|
||||||
|
vipType = 'xcxLetter';
|
||||||
|
};
|
||||||
|
const createServiceData = {
|
||||||
|
service_name: String(serviceName),
|
||||||
|
price: String(price),
|
||||||
|
unit: String(unit),
|
||||||
|
length: String(length),
|
||||||
|
type: String(vipType),
|
||||||
|
sort: String(sort)
|
||||||
|
};
|
||||||
|
console.log('createServiceData:', createServiceData);
|
||||||
|
|
||||||
|
// 验证所有必需参数
|
||||||
|
if (!createServiceData.service_name || createServiceData.service_name === 'undefined' ||
|
||||||
|
!createServiceData.price || createServiceData.price === 'undefined' ||
|
||||||
|
!createServiceData.unit || createServiceData.unit === 'undefined' ||
|
||||||
|
!createServiceData.length || createServiceData.length === 'undefined') {
|
||||||
|
console.error('参数验证失败:', createServiceData);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '参数不完整,请检查orderData中的serviceName、originalPrice、unit、length字段'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const [serviceErr, serviceResponse] = await uni.request({
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/createService',
|
||||||
|
method: 'POST',
|
||||||
|
data: createServiceData,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (serviceErr) {
|
||||||
|
console.error('创建服务失败:', serviceErr);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '创建服务失败: ' + serviceErr.errMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('创建服务成功:', serviceResponse);
|
||||||
|
const serviceId = serviceResponse.data.data
|
||||||
|
if (!serviceId) {
|
||||||
|
console.error('服务创建成功但未返回服务ID');
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '服务创建成功但未返回服务ID'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第二步:创建订单
|
||||||
|
const createOrderData = {
|
||||||
|
orderType: String(vipType),
|
||||||
|
userId: String(userId),
|
||||||
|
goodsId: String(serviceId),
|
||||||
|
count: String(1),
|
||||||
|
note: orderData.note || '孔网翻新会员订单'
|
||||||
|
};
|
||||||
|
console.log('createOrderData:', createOrderData);
|
||||||
|
const [orderErr, orderResponse] = await uni.request({
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/orders/createOrder',
|
||||||
|
method: 'POST',
|
||||||
|
data: createOrderData,
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
// 'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (orderErr) {
|
||||||
|
console.error('创建订单失败:', orderErr);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '创建订单失败: ' + orderErr.errMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('创建订单成功:', orderResponse.data);
|
||||||
|
const orderId = orderResponse.data.data
|
||||||
|
|
||||||
|
if (!orderId) {
|
||||||
|
console.error('订单创建成功但未返回订单ID');
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '订单创建成功但未返回订单ID'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
orderId: orderId,
|
||||||
|
serviceId: serviceId,
|
||||||
|
message: '订单创建成功',
|
||||||
|
serviceData: serviceResponse.data,
|
||||||
|
orderData: orderResponse.data
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('创建孔网翻新会员订单失败:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付后更新孔网翻新会员订单记录
|
||||||
|
* @param {String} orderId 订单ID
|
||||||
|
* @param {Object} payResult 支付结果
|
||||||
|
* @returns {Object} 更新结果
|
||||||
|
*/
|
||||||
|
export const updateKwfwMemberOrder = async (orderId, payResult, userId) => {
|
||||||
|
try {
|
||||||
|
console.log('支付后更新孔网翻新会员订单:', {
|
||||||
|
orderId,
|
||||||
|
payResult,
|
||||||
|
userId
|
||||||
|
});
|
||||||
|
// orderId 参数已经是实际的订单ID数字,不需要再次提取
|
||||||
|
const actualOrderId = String(orderId)
|
||||||
|
console.log("actualOrderId", actualOrderId)
|
||||||
|
|
||||||
|
// 调用订单更新接口
|
||||||
|
const [err, response] = await uni.request({
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/orders/orderForPay',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
orderId: String(actualOrderId),
|
||||||
|
orderInfo: JSON.stringify(payResult),
|
||||||
|
userId: String(userId),
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.error('更新订单失败:', err);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '更新订单失败: ' + err.errMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('订单更新接口返回:', response);
|
||||||
|
|
||||||
|
if (response.statusCode === 200) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: '订单更新成功',
|
||||||
|
data: response.data
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '订单更新失败: ' + (response.data?.message || '未知错误')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新孔网翻新会员订单失败:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户书籍数量限制
|
||||||
|
* @param {Object} payResult 支付结果
|
||||||
|
* @param {String} orderId 订单ID
|
||||||
|
* @param {String} userId 用户ID
|
||||||
|
* @param {String} settledId 会员等级ID
|
||||||
|
* @returns {Promise<Object>} 返回更新结果
|
||||||
|
*/
|
||||||
|
export const updateUserBooksCountLimit = async (payResult, orderId, userId, settledId) => {
|
||||||
|
try {
|
||||||
|
console.log('更新用户书籍数量限制:', {
|
||||||
|
payResult,
|
||||||
|
orderId,
|
||||||
|
userId,
|
||||||
|
settledId
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用后端接口更新用户书籍数量限制
|
||||||
|
const [err, response] = await uni.request({
|
||||||
|
url: 'https://newadmin.buzhiyushu.cn/updateUserBooksCountLimit',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
payResult: JSON.stringify(payResult),
|
||||||
|
orderId: orderId,
|
||||||
|
userId: userId,
|
||||||
|
settledId: settledId
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.error('更新用户书籍数量限制失败:', err);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '更新用户书籍数量限制失败: ' + err.errMsg
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('更新用户书籍数量限制接口返回:', response);
|
||||||
|
|
||||||
|
if (response.statusCode === 200 && response.data.code === 200) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: '用户书籍数量限制更新成功',
|
||||||
|
data: response.data.data
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: '更新用户书籍数量限制失败: ' + (response.data?.msg || '未知错误')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('更新用户书籍数量限制失败:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有服务列表
|
||||||
|
* @param {String} type - 服务类型
|
||||||
|
* @returns {Promise<Array>} - 返回服务列表
|
||||||
|
*/
|
||||||
|
export const getAllServices = async (type) => {
|
||||||
|
try {
|
||||||
|
const [err, response] = await uni.request({
|
||||||
|
url: 'https://go.order.service.buzhiyushu.cn/api/getAllServices',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
type: type
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('获取所有服务列表结果:', response);
|
||||||
|
|
||||||
|
// 检查响应状态
|
||||||
|
if (response.statusCode === 200 && response.data.code === 200) {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
data: response.data.data,
|
||||||
|
message: response.data.message
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
throw new Error(response.data.message || '获取服务列表失败');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取所有服务列表失败:', error);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: error.message || '网络请求失败'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getUserRecbusiness,
|
||||||
|
checkKwfwMemberStatus,
|
||||||
|
checkMemberBooksCount,
|
||||||
|
callWxPay,
|
||||||
|
checkPayStatus,
|
||||||
|
getMemberLevelList,
|
||||||
|
showMemberLevelSelector,
|
||||||
|
checkKwfwMember,
|
||||||
|
createKwfwMemberOrder,
|
||||||
|
updateKwfwMemberOrder,
|
||||||
|
updateUserBooksCountLimit,
|
||||||
|
getAllServices
|
||||||
|
};
|
||||||
716
components/PriceComparison.vue
Normal file
716
components/PriceComparison.vue
Normal file
@ -0,0 +1,716 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 比价和筛选按钮 -->
|
||||||
|
<view class="button-group">
|
||||||
|
<u-popup :show="popupShow" @close="close" @open="open" mode="bottom" round="10">
|
||||||
|
<view class="filter-popup">
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">出版社</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in publisherOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.publisher" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="togglePublisherFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-section">
|
||||||
|
<view class="section-title">作者</view>
|
||||||
|
<view class="tag-group">
|
||||||
|
<u-tag v-for="(item, index) in authorOptions" :key="index" v-if="item.visible"
|
||||||
|
:text="item.author" :plain="!item.checked" size="large" :name="index"
|
||||||
|
@click="toggleAuthorFilter(index)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="filter-buttons">
|
||||||
|
<u-button text="重置" type="info" plain @click="resetFilters" />
|
||||||
|
<u-button text="确定" type="primary" @click="applyFilters" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</u-popup>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="book-list">
|
||||||
|
<view class="label">
|
||||||
|
<view style="display: inline-block;width: 380rpx;text-align: left;">
|
||||||
|
在售商品(总价/书价/运费)
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="btn" @click="handleSwitchCompareType">
|
||||||
|
{{ compareType === 'isbn' ? '书名比价' : 'ISBN比价' }}
|
||||||
|
</view>
|
||||||
|
<view class="btn" @click="popupShow = true">更多筛序</view>
|
||||||
|
</view>
|
||||||
|
<!-- 在售商品展示区域 -->
|
||||||
|
<view class="container" v-if="showProducts.length > 0">
|
||||||
|
<view class="product-grid">
|
||||||
|
<view class="product-card" v-for="(product, index) in showProducts" :key="index">
|
||||||
|
<view class="product-image-container">
|
||||||
|
<image class="product-image" :src="product.imageUrl" mode="aspectFit"
|
||||||
|
@click="previewImage(product.imageUrl, showProducts)">
|
||||||
|
</image>
|
||||||
|
<view class="price-details">
|
||||||
|
<text>{{product.totalPrice}}/{{product.bookPrice}}/{{product.shippingFee}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="product-info">
|
||||||
|
<text class="product-price"
|
||||||
|
style="font-size: 26rpx;">{{product.totalPrice}}/{{product.qualityText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="empty-products" v-else>
|
||||||
|
<text>暂无在售商品信息</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'price-comparison',
|
||||||
|
props: {
|
||||||
|
// 当前比价类型
|
||||||
|
compareType: {
|
||||||
|
type: String,
|
||||||
|
default: 'isbn'
|
||||||
|
},
|
||||||
|
// 书籍标识符(ISBN或书名)
|
||||||
|
keyword: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 品相值
|
||||||
|
conditionValue: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 排序类型
|
||||||
|
sortType: {
|
||||||
|
type: String,
|
||||||
|
default: 'price' // 默认按价格排序
|
||||||
|
},
|
||||||
|
// 阻止自动加载
|
||||||
|
preventAutoLoad: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
popupShow: false,
|
||||||
|
isFiltered: false,
|
||||||
|
publisherOptions: [],
|
||||||
|
authorOptions: [],
|
||||||
|
allProducts: [], // 存储所有在售商品
|
||||||
|
displayProducts: [], // 展示的商品
|
||||||
|
filteredProducts: [], // 筛选后的商品
|
||||||
|
publisherAuthorMap: {}, // 出版社-作者关系映射
|
||||||
|
authorPublisherMap: {}, // 作者-出版社关系映射
|
||||||
|
loading: false,
|
||||||
|
loadError: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// 根据筛选状态决定展示哪些商品
|
||||||
|
showProducts() {
|
||||||
|
return this.isFiltered ? this.filteredProducts : this.displayProducts;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
keyword: {
|
||||||
|
handler(newVal) {
|
||||||
|
if (newVal && !this.preventAutoLoad) {
|
||||||
|
this.loadProducts();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
compareType: {
|
||||||
|
handler(newVal) {
|
||||||
|
if (this.keyword && !this.preventAutoLoad) {
|
||||||
|
this.loadProducts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 加载在售商品数据
|
||||||
|
async loadProducts() {
|
||||||
|
if (!this.keyword) return;
|
||||||
|
|
||||||
|
this.loading = true;
|
||||||
|
this.loadError = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取cookies,可以从缓存中读取
|
||||||
|
const cookies = uni.getStorageSync('cookies');
|
||||||
|
|
||||||
|
// 调用API获取在售商品数据
|
||||||
|
const response = await this.fetchProductData(this.keyword, this.sortType, this.conditionValue, cookies);
|
||||||
|
|
||||||
|
// 处理数据
|
||||||
|
this.processProductData(response);
|
||||||
|
|
||||||
|
// 发出加载完成事件
|
||||||
|
this.$emit('loaded', {
|
||||||
|
products: this.allProducts,
|
||||||
|
displayProducts: this.displayProducts
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取在售商品信息失败:', error);
|
||||||
|
this.loadError = error.message || '加载失败';
|
||||||
|
this.$emit('error', error);
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 调用API获取数据
|
||||||
|
async fetchProductData(keyword, sortType, conditionValue, cookies) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.request({
|
||||||
|
url: 'https://api.buzhiyushu.cn/zhishu/baseInfo/getBookList',
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
keyword,
|
||||||
|
sortType,
|
||||||
|
conditionValue,
|
||||||
|
compareType: this.compareType
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
'Cookie': cookies || ''
|
||||||
|
},
|
||||||
|
success: (res) => {
|
||||||
|
if (res.statusCode === 200 && res.data) {
|
||||||
|
resolve(res.data);
|
||||||
|
} else {
|
||||||
|
reject(new Error('请求失败: ' + res.statusCode));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 处理获取到的数据
|
||||||
|
processProductData(data) {
|
||||||
|
// 获取屏蔽店铺列表
|
||||||
|
const blockedShopsStr = uni.getStorageSync('blockedShops') || '';
|
||||||
|
const blockedShops = blockedShopsStr.split(';').filter(shop => shop.trim() !== '');
|
||||||
|
|
||||||
|
// 过滤掉屏蔽的店铺
|
||||||
|
const filteredData = Array.isArray(data) ? data.filter(product => {
|
||||||
|
return !blockedShops.some(shop => product.shopName && product.shopName.includes(shop.trim()));
|
||||||
|
}) : [];
|
||||||
|
|
||||||
|
// 保存所有数据用于筛选
|
||||||
|
this.allProducts = [...filteredData];
|
||||||
|
|
||||||
|
// 对商品数据按照总价从低到高排序
|
||||||
|
const sortedData = [...filteredData].sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a.totalPrice) || 0;
|
||||||
|
const priceB = parseFloat(b.totalPrice) || 0;
|
||||||
|
return priceA - priceB; // 从低到高排序
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前12条数据用于展示
|
||||||
|
this.displayProducts = sortedData.slice(0, 12);
|
||||||
|
|
||||||
|
// 提取出版社和作者信息,用于筛选选项
|
||||||
|
this.extractPublishersAndAuthors();
|
||||||
|
|
||||||
|
// 计算参考价格
|
||||||
|
this.calculateReferencePrice();
|
||||||
|
},
|
||||||
|
|
||||||
|
// 提取出版社和作者信息
|
||||||
|
extractPublishersAndAuthors() {
|
||||||
|
// 创建映射对象
|
||||||
|
const publisherAuthorMap = {};
|
||||||
|
const authorPublisherMap = {};
|
||||||
|
|
||||||
|
// 遍历商品数据,建立关联关系
|
||||||
|
this.allProducts.forEach(product => {
|
||||||
|
if (product.publisher && product.author) {
|
||||||
|
// 添加出版社-作者关联
|
||||||
|
if (!publisherAuthorMap[product.publisher]) {
|
||||||
|
publisherAuthorMap[product.publisher] = [];
|
||||||
|
}
|
||||||
|
if (!publisherAuthorMap[product.publisher].includes(product.author)) {
|
||||||
|
publisherAuthorMap[product.publisher].push(product.author);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加作者-出版社关联
|
||||||
|
if (!authorPublisherMap[product.author]) {
|
||||||
|
authorPublisherMap[product.author] = [];
|
||||||
|
}
|
||||||
|
if (!authorPublisherMap[product.author].includes(product.publisher)) {
|
||||||
|
authorPublisherMap[product.author].push(product.publisher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 保存关联映射
|
||||||
|
this.publisherAuthorMap = publisherAuthorMap;
|
||||||
|
this.authorPublisherMap = authorPublisherMap;
|
||||||
|
|
||||||
|
// 提取出版社
|
||||||
|
const publishers = new Set();
|
||||||
|
this.allProducts.forEach(product => {
|
||||||
|
if (product.publisher) {
|
||||||
|
publishers.add(product.publisher);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 提取作者
|
||||||
|
const authors = new Set();
|
||||||
|
this.allProducts.forEach(product => {
|
||||||
|
if (product.author) {
|
||||||
|
authors.add(product.author);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 转换为选项数组
|
||||||
|
this.publisherOptions = Array.from(publishers).map(publisher => ({
|
||||||
|
publisher,
|
||||||
|
checked: false,
|
||||||
|
visible: true
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.authorOptions = Array.from(authors).map(author => ({
|
||||||
|
author,
|
||||||
|
checked: false,
|
||||||
|
visible: true
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 计算参考价格
|
||||||
|
calculateReferencePrice() {
|
||||||
|
if (!this.displayProducts || this.displayProducts.length === 0) return;
|
||||||
|
|
||||||
|
// 获取最低价格
|
||||||
|
const lowestBookPrice = Math.min(...this.displayProducts.map(p => parseFloat(p.bookPrice) || 0));
|
||||||
|
const lowestTotalPrice = Math.min(...this.displayProducts.map(p => parseFloat(p.totalPrice) || 0));
|
||||||
|
|
||||||
|
// 发出价格计算事件
|
||||||
|
this.$emit('price-calculated', {
|
||||||
|
lowestBookPrice,
|
||||||
|
lowestTotalPrice,
|
||||||
|
products: this.displayProducts
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 打开和关闭筛选弹窗
|
||||||
|
open() {
|
||||||
|
this.popupShow = true;
|
||||||
|
this.$emit('popup-open');
|
||||||
|
},
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.popupShow = false;
|
||||||
|
this.$emit('popup-close');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 切换比价类型
|
||||||
|
handleSwitchCompareType() {
|
||||||
|
const newType = this.compareType === 'isbn' ? 'title' : 'isbn';
|
||||||
|
this.$emit('compare-type-change', newType);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 图片预览
|
||||||
|
previewImage(currentUrl, productList) {
|
||||||
|
// 检查productList是否存在且是数组
|
||||||
|
let urls = [];
|
||||||
|
|
||||||
|
if (productList && Array.isArray(productList)) {
|
||||||
|
// 提取所有图片 URL
|
||||||
|
urls = productList.map(item => item.imageUrl);
|
||||||
|
} else {
|
||||||
|
urls = [currentUrl];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保urls中至少有一个有效的URL
|
||||||
|
if (!urls.length || !urls[0]) {
|
||||||
|
console.error('没有有效的图片URL可预览');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用预览接口
|
||||||
|
uni.previewImage({
|
||||||
|
current: currentUrl,
|
||||||
|
urls: urls,
|
||||||
|
longPressActions: {
|
||||||
|
itemList: ['保存图片', '分享图片'],
|
||||||
|
success: function(data) {
|
||||||
|
console.log('选择了第' + (data.tapIndex + 1) + '个按钮');
|
||||||
|
},
|
||||||
|
fail: function(err) {
|
||||||
|
console.log(err.errMsg);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: () => {},
|
||||||
|
fail: (err) => {
|
||||||
|
console.error('预览失败:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 筛选相关方法
|
||||||
|
togglePublisherFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.publisherOptions[index].checked = !this.publisherOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的出版社
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
// 如果没有选中任何出版社,显示所有作者
|
||||||
|
if (selectedPublishers.length === 0) {
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的出版社
|
||||||
|
const currentPublisher = this.publisherOptions[index].publisher;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的作者
|
||||||
|
if (!this.publisherOptions[index].checked) {
|
||||||
|
// 重置所有作者的可见性
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的出版社更新作者可见性
|
||||||
|
selectedPublishers.forEach(publisher => {
|
||||||
|
if (this.publisherAuthorMap[publisher]) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap[publisher];
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (relatedAuthors.includes(item.author)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该出版社相关的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
// 检查该作者是否与当前选中的出版社相关
|
||||||
|
if (this.publisherAuthorMap[currentPublisher]) {
|
||||||
|
const relatedAuthors = this.publisherAuthorMap[currentPublisher];
|
||||||
|
item.visible = relatedAuthors.includes(item.author);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的作者
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleAuthorFilter(index) {
|
||||||
|
// 切换选中状态
|
||||||
|
this.authorOptions[index].checked = !this.authorOptions[index].checked;
|
||||||
|
|
||||||
|
// 获取所有选中的作者
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选中任何作者,显示所有出版社
|
||||||
|
if (selectedAuthors.length === 0) {
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取当前选中的作者
|
||||||
|
const currentAuthor = this.authorOptions[index].author;
|
||||||
|
|
||||||
|
// 如果取消选中,需要重新计算可见的出版社
|
||||||
|
if (!this.authorOptions[index].checked) {
|
||||||
|
// 重置所有出版社的可见性
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.visible = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 根据剩余选中的作者更新出版社可见性
|
||||||
|
selectedAuthors.forEach(author => {
|
||||||
|
if (this.authorPublisherMap[author]) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap[author];
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (relatedPublishers.includes(item.publisher)) {
|
||||||
|
item.visible = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果是新选中,只显示与该作者相关的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
// 检查该出版社是否与当前选中的作者相关
|
||||||
|
if (this.authorPublisherMap[currentAuthor]) {
|
||||||
|
const relatedPublishers = this.authorPublisherMap[currentAuthor];
|
||||||
|
item.visible = relatedPublishers.includes(item.publisher);
|
||||||
|
} else {
|
||||||
|
item.visible = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消选中不可见的出版社
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
if (!item.visible) {
|
||||||
|
item.checked = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
resetFilters() {
|
||||||
|
// 重置出版社选项
|
||||||
|
this.publisherOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置作者选项
|
||||||
|
this.authorOptions.forEach(item => {
|
||||||
|
item.checked = false;
|
||||||
|
item.visible = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 重置筛选状态
|
||||||
|
this.isFiltered = false;
|
||||||
|
this.filteredProducts = [];
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 触发事件
|
||||||
|
this.$emit('filters-reset');
|
||||||
|
},
|
||||||
|
|
||||||
|
applyFilters() {
|
||||||
|
// 获取选中的出版社和作者
|
||||||
|
const selectedPublishers = this.publisherOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.publisher);
|
||||||
|
|
||||||
|
const selectedAuthors = this.authorOptions
|
||||||
|
.filter(item => item.checked)
|
||||||
|
.map(item => item.author);
|
||||||
|
|
||||||
|
// 如果没有选择任何筛选条件,则显示排序后的前十条数据
|
||||||
|
if (selectedPublishers.length === 0 && selectedAuthors.length === 0) {
|
||||||
|
this.filteredProducts = [];
|
||||||
|
this.isFiltered = false;
|
||||||
|
} else {
|
||||||
|
// 筛选在售商品
|
||||||
|
let filteredProducts = this.allProducts.filter(product => {
|
||||||
|
const matchPublisher = selectedPublishers.length === 0 ||
|
||||||
|
(product.publisher && selectedPublishers.includes(product.publisher));
|
||||||
|
const matchAuthor = selectedAuthors.length === 0 ||
|
||||||
|
(product.author && selectedAuthors.includes(product.author));
|
||||||
|
return matchPublisher && matchAuthor;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 对筛选后的结果按总价从低到高排序
|
||||||
|
filteredProducts = filteredProducts.sort((a, b) => {
|
||||||
|
const priceA = parseFloat(a.totalPrice) || 0;
|
||||||
|
const priceB = parseFloat(b.totalPrice) || 0;
|
||||||
|
return priceA - priceB; // 从低到高排序
|
||||||
|
});
|
||||||
|
|
||||||
|
// 只保留前10条数据
|
||||||
|
this.filteredProducts = filteredProducts.slice(0, 10);
|
||||||
|
this.isFiltered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭弹窗
|
||||||
|
this.popupShow = false;
|
||||||
|
|
||||||
|
// 触发事件
|
||||||
|
this.$emit('filters-applied', {
|
||||||
|
filteredProducts: this.filteredProducts,
|
||||||
|
selectedPublishers,
|
||||||
|
selectedAuthors
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 手动刷新数据
|
||||||
|
refresh() {
|
||||||
|
this.loadProducts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.book-list {
|
||||||
|
margin-top: 20rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label {
|
||||||
|
padding: 10rpx;
|
||||||
|
display: block;
|
||||||
|
width: calc(100% - 20rpx);
|
||||||
|
height: 40rpx;
|
||||||
|
color: #333;
|
||||||
|
border-bottom: 2rpx solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.label>.btn {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 120rpx;
|
||||||
|
height: 30rpx;
|
||||||
|
line-height: 30rpx;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #3c9cff;
|
||||||
|
border-radius: 10%;
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 7rpx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 480rpx) {
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(50% - 5rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image {
|
||||||
|
height: 200rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card {
|
||||||
|
width: calc(25% - 8rpx);
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
height: 180rpx;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 140rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info {
|
||||||
|
padding: 8rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.product-info>.product-price {
|
||||||
|
font-size: 28rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #ff6b00;
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 4rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.book-list>.container>.product-grid>.product-card>.product-image-container>.price-details {
|
||||||
|
font-size: 22rpx;
|
||||||
|
line-height: 1.2;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
color: #ffffff;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 4rpx 0;
|
||||||
|
border-radius: 0 0 8rpx 8rpx;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-products {
|
||||||
|
padding: 30rpx;
|
||||||
|
text-align: center;
|
||||||
|
color: #999;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 20rpx;
|
||||||
|
margin: 10rpx 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-section {
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag-group {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 10rpx;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-popup {
|
||||||
|
padding: 30rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-buttons {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 40rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
227
components/PriceStockControl.vue
Normal file
227
components/PriceStockControl.vue
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
<template>
|
||||||
|
<view class="price-stock-container">
|
||||||
|
<!-- 价格控制 -->
|
||||||
|
<view class="control-item">
|
||||||
|
<view class="section-header">
|
||||||
|
<text class="section-title">价格</text>
|
||||||
|
</view>
|
||||||
|
<view class="number-control-wrapper">
|
||||||
|
<text class="number-control-btn minus-btn" @click="decreasePrice">-</text>
|
||||||
|
<input type="digit" v-model="priceValue" class="custom-input-box" @blur="validatePrice"
|
||||||
|
:disabled="disabled" />
|
||||||
|
<text class="number-control-btn plus-btn" @click="increasePrice">+</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 库存控制 -->
|
||||||
|
<view class="control-item">
|
||||||
|
<view class="section-header">
|
||||||
|
<text class="section-title">库存</text>
|
||||||
|
</view>
|
||||||
|
<view class="number-control-wrapper">
|
||||||
|
<text class="number-control-btn minus-btn" @click="decreaseStock">-</text>
|
||||||
|
<input type="digit" v-model="stockValue" class="custom-input-box" @blur="validateStock"
|
||||||
|
:disabled="disabled" />
|
||||||
|
<text class="number-control-btn plus-btn" @click="increaseStock">+</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'PriceStockControl',
|
||||||
|
props: {
|
||||||
|
// 价格值
|
||||||
|
price: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 1.00
|
||||||
|
},
|
||||||
|
// 库存值
|
||||||
|
stock: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 1
|
||||||
|
},
|
||||||
|
// 是否禁用
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
// 价格变化步长
|
||||||
|
priceStep: {
|
||||||
|
type: Number,
|
||||||
|
default: 0.01
|
||||||
|
},
|
||||||
|
// 库存变化步长
|
||||||
|
stockStep: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
priceValue: this.price,
|
||||||
|
stockValue: this.stock
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 监听外部价格变化
|
||||||
|
price(newVal) {
|
||||||
|
this.priceValue = newVal;
|
||||||
|
},
|
||||||
|
// 监听外部库存变化
|
||||||
|
stock(newVal) {
|
||||||
|
this.stockValue = newVal;
|
||||||
|
},
|
||||||
|
// 监听内部价格变化,触发父组件更新
|
||||||
|
priceValue(newVal) {
|
||||||
|
this.$emit('update:price', newVal);
|
||||||
|
},
|
||||||
|
// 监听内部库存变化,触发父组件更新
|
||||||
|
stockValue(newVal) {
|
||||||
|
this.$emit('update:stock', newVal);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 增加价格值
|
||||||
|
increasePrice() {
|
||||||
|
if (parseFloat(this.priceValue) < 999) {
|
||||||
|
this.priceValue = parseFloat((parseFloat(this.priceValue) + this.priceStep).toFixed(2));
|
||||||
|
this.$emit('priceChange', this.priceValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 减少价格值
|
||||||
|
decreasePrice() {
|
||||||
|
if (parseFloat(this.priceValue) > this.priceStep) {
|
||||||
|
this.priceValue = parseFloat((parseFloat(this.priceValue) - this.priceStep).toFixed(2));
|
||||||
|
this.$emit('priceChange', this.priceValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 验证价格值
|
||||||
|
validatePrice() {
|
||||||
|
let val = parseFloat(this.priceValue);
|
||||||
|
if (isNaN(val)) {
|
||||||
|
this.priceValue = 0;
|
||||||
|
} else if (val > 99999) {
|
||||||
|
this.priceValue = 99999;
|
||||||
|
} else if (val < 0) {
|
||||||
|
this.priceValue = 0;
|
||||||
|
} else {
|
||||||
|
this.priceValue = parseFloat(val.toFixed(2));
|
||||||
|
}
|
||||||
|
this.$emit('priceChange', this.priceValue);
|
||||||
|
},
|
||||||
|
// 增加库存值
|
||||||
|
increaseStock() {
|
||||||
|
if (parseFloat(this.stockValue) < 99) {
|
||||||
|
this.stockValue = parseFloat((parseFloat(this.stockValue) + this.stockStep).toFixed(0));
|
||||||
|
this.$emit('stockChange', this.stockValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 减少库存值
|
||||||
|
decreaseStock() {
|
||||||
|
if (parseFloat(this.stockValue) > this.stockStep) {
|
||||||
|
this.stockValue = parseFloat((parseFloat(this.stockValue) - this.stockStep).toFixed(0));
|
||||||
|
this.$emit('stockChange', this.stockValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 验证库存值
|
||||||
|
validateStock() {
|
||||||
|
let val = parseFloat(this.stockValue);
|
||||||
|
if (isNaN(val)) {
|
||||||
|
this.stockValue = 0;
|
||||||
|
} else if (val > 99999) {
|
||||||
|
this.stockValue = 99999;
|
||||||
|
} else if (val < 0) {
|
||||||
|
this.stockValue = 0;
|
||||||
|
} else {
|
||||||
|
this.stockValue = parseInt(val);
|
||||||
|
}
|
||||||
|
this.$emit('stockChange', this.stockValue);
|
||||||
|
},
|
||||||
|
// 重置价格和库存到默认值
|
||||||
|
reset() {
|
||||||
|
console.log('PriceStockControl组件重置');
|
||||||
|
this.priceValue = 1.00;
|
||||||
|
this.stockValue = 1;
|
||||||
|
this.$emit('priceChange', this.priceValue);
|
||||||
|
this.$emit('stockChange', this.stockValue);
|
||||||
|
this.$emit('update:price', this.priceValue);
|
||||||
|
this.$emit('update:stock', this.stockValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
/* 价格和库存容器 */
|
||||||
|
.price-stock-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10rpx;
|
||||||
|
gap: 60rpx;
|
||||||
|
/* gap: 20rpx; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-header {
|
||||||
|
margin-right: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 控制按钮基础样式 */
|
||||||
|
.number-control-btn {
|
||||||
|
width: 36rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
border-radius: 4rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 22rpx;
|
||||||
|
color: #666;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.number-control-wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.minus-btn,
|
||||||
|
.plus-btn {
|
||||||
|
padding: 0 10rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
border: 1rpx solid #ccc;
|
||||||
|
border-radius: 4rpx;
|
||||||
|
background: #fff;
|
||||||
|
height: 36rpx;
|
||||||
|
line-height: 36rpx;
|
||||||
|
min-width: 32rpx;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-input-box {
|
||||||
|
width: 120rpx;
|
||||||
|
text-align: center;
|
||||||
|
border: 1rpx solid #eee;
|
||||||
|
border-radius: 4rpx;
|
||||||
|
height: 36rpx;
|
||||||
|
line-height: 36rpx;
|
||||||
|
margin: 0 5rpx;
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
font-size: 30rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
235
components/StoragePicker.vue
Normal file
235
components/StoragePicker.vue
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 三级联动选择器 -->
|
||||||
|
<view class="view-item view-item-3">
|
||||||
|
<view class="label" @click="navigateBack">货区</view>
|
||||||
|
<view class="select" @click="show = true">{{ selectedStorage || '请选择货区' }}</view>
|
||||||
|
<u-picker :show="show" ref="uPicker" :columns="columns" @cancel="cancel" @confirm="confirm"
|
||||||
|
@change="changeHandler"></u-picker>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
selectedStorage: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showPicker: false,
|
||||||
|
columns: [
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
], // 仓库、货架、货位
|
||||||
|
warehouseShelvesData: {},
|
||||||
|
shelfLocationsData: {}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
confirm(e) {
|
||||||
|
const [warehouse, shelf, location] = e.value;
|
||||||
|
this.$emit('select', {
|
||||||
|
warehouse,
|
||||||
|
shelf,
|
||||||
|
location
|
||||||
|
});
|
||||||
|
this.showPicker = false;
|
||||||
|
},
|
||||||
|
// 返回上一页并清除缓存
|
||||||
|
navigateBack() {
|
||||||
|
// 清除相关缓存数据
|
||||||
|
uni.removeStorageSync('lastSelectedStorage');
|
||||||
|
uni.removeStorageSync('selectedWarehouse');
|
||||||
|
uni.removeStorageSync('lastSelectedShelf');
|
||||||
|
uni.removeStorageSync('lastSelectedLocation');
|
||||||
|
|
||||||
|
// 重置相关数据
|
||||||
|
this.selectedStorage = '';
|
||||||
|
this.warehouse = '';
|
||||||
|
this.shelf = '';
|
||||||
|
this.location = '';
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/warehouse/warehouse-select'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
cancel() {
|
||||||
|
this.show = false;
|
||||||
|
},
|
||||||
|
changeHandler(e) {
|
||||||
|
// 防御性检查,确保e和必要的属性存在
|
||||||
|
if (!e) {
|
||||||
|
console.warn('changeHandler: 事件对象为空');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('changeHandler 事件:', JSON.stringify(e));
|
||||||
|
|
||||||
|
// 获取列索引和选中的索引数组
|
||||||
|
const {
|
||||||
|
columnIndex,
|
||||||
|
index,
|
||||||
|
indexes = []
|
||||||
|
} = e;
|
||||||
|
console.log('列索引:', columnIndex, '选中索引:', index, 'indexes数组:',
|
||||||
|
indexes);
|
||||||
|
|
||||||
|
// 如果是选择了仓库(第0列)
|
||||||
|
if (columnIndex === 0) {
|
||||||
|
// 获取选中的仓库
|
||||||
|
const warehouseName = this.columns[0][index];
|
||||||
|
const warehouse = this.selectedWarehouse || {
|
||||||
|
id: null,
|
||||||
|
name: warehouseName
|
||||||
|
};
|
||||||
|
console.log('选中的仓库:', warehouseName, '仓库对象:', warehouse);
|
||||||
|
|
||||||
|
// 如果有仓库ID,获取对应的货架
|
||||||
|
if (warehouse.id) {
|
||||||
|
console.log('开始获取货架数据,仓库ID:', warehouse.id);
|
||||||
|
this.fetchShelves(warehouse.id).then(shelves => {
|
||||||
|
console.log('获取到货架数据:', shelves);
|
||||||
|
// 清空货位列
|
||||||
|
this.columns[2] = [];
|
||||||
|
// 更新UI
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker
|
||||||
|
.setColumnValues(2, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是选择了货架(第1列)
|
||||||
|
if (columnIndex === 1) {
|
||||||
|
// 获取选中的货架索引
|
||||||
|
const shelfIndex = index;
|
||||||
|
console.log('选中的货架索引:', shelfIndex);
|
||||||
|
|
||||||
|
// 确保货架数据有效
|
||||||
|
if (Array.isArray(this.shelves) && this.shelves.length > 0 &&
|
||||||
|
shelfIndex >= 0 && shelfIndex < this
|
||||||
|
.shelves.length) {
|
||||||
|
const selectedShelf = this.shelves[shelfIndex];
|
||||||
|
console.log("选中的货架对象:", selectedShelf);
|
||||||
|
|
||||||
|
// 保存选中的货架ID
|
||||||
|
this.selectedSheId = selectedShelf.id;
|
||||||
|
|
||||||
|
// 如果货架有ID,获取对应的货位
|
||||||
|
if (selectedShelf?.id) {
|
||||||
|
console.log('开始获取货位数据,货架ID:', selectedShelf.id);
|
||||||
|
this.fetchLocations(selectedShelf.id).then(
|
||||||
|
locations => {
|
||||||
|
console.log('获取到货位数据:', locations);
|
||||||
|
|
||||||
|
// 确保locations是数组且有数据
|
||||||
|
if (Array.isArray(locations) && locations
|
||||||
|
.length > 0) {
|
||||||
|
// 更新货位列
|
||||||
|
this.columns[2] = locations.map(item =>
|
||||||
|
item.code || '未知货位');
|
||||||
|
console.log('更新后的货位列:', this.columns[
|
||||||
|
2]);
|
||||||
|
|
||||||
|
// 更新UI
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
console.log(
|
||||||
|
'更新货位选择器UI');
|
||||||
|
this.$refs.uPicker
|
||||||
|
.setColumnValues(2,
|
||||||
|
this.columns[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('获取到的货位数据为空');
|
||||||
|
// 清空货位列
|
||||||
|
this.columns[2] = ['暂无货位'];
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker
|
||||||
|
.setColumnValues(2,
|
||||||
|
this.columns[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('获取货位数据失败:', error);
|
||||||
|
// 显示错误提示
|
||||||
|
this.columns[2] = ['获取失败'];
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker
|
||||||
|
.setColumnValues(2,
|
||||||
|
this.columns[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn('货架ID无效');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('无效的货架索引或数据未准备好', {
|
||||||
|
shelfIndex,
|
||||||
|
shelvesLength: this.shelves?.length
|
||||||
|
});
|
||||||
|
// 清空货位列
|
||||||
|
this.columns[2] = ['请先选择有效货架'];
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker.setColumnValues(2, this.columns[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.view-item-3 {
|
||||||
|
flex: 3 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-4 {
|
||||||
|
flex: 4 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-6 {
|
||||||
|
flex: 6 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-7 {
|
||||||
|
flex: 7 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item>.label {
|
||||||
|
display: inline;
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
height: 40rpx;
|
||||||
|
line-height: 40rpx;
|
||||||
|
color: #000;
|
||||||
|
font-size: 29rpx;
|
||||||
|
background-color: #ccc;
|
||||||
|
border-top-left-radius: 10rpx;
|
||||||
|
border-bottom-left-radius: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item>.select {
|
||||||
|
padding: 10rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 40rpx;
|
||||||
|
font-size: 18rpx;
|
||||||
|
line-height: 40rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
47
components/TabBar.vue
Normal file
47
components/TabBar.vue
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<template>
|
||||||
|
<!-- 选项卡切换 -->
|
||||||
|
<view class="tab-bar">
|
||||||
|
<view class="tab-item" :class="{ active: activeTab === 'isbn' }" @click="$emit('change', 'isbn')" key="isbn-tab">
|
||||||
|
ISBN-上传
|
||||||
|
</view>
|
||||||
|
<view class="tab-item" :class="{ active: activeTab === 'title' }" @click="$emit('change', 'title')" key="title-tab">
|
||||||
|
仅书名-上传
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name:"tab-bar",
|
||||||
|
props: {
|
||||||
|
activeTab: {
|
||||||
|
type: String,
|
||||||
|
default: 'isbn',
|
||||||
|
validator: value => ['isbn', 'title'].includes(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.tab-bar {
|
||||||
|
display: flex;
|
||||||
|
background-color: #fff;
|
||||||
|
margin-bottom: 30rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-item {
|
||||||
|
flex: 1;
|
||||||
|
padding: 10rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 29rpx;
|
||||||
|
color: #666;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-item.active {
|
||||||
|
color: #03A9F4;
|
||||||
|
background-color: rgba(0, 122, 255, 0.1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
508
components/WarehouserSelector.vue
Normal file
508
components/WarehouserSelector.vue
Normal file
@ -0,0 +1,508 @@
|
|||||||
|
<template>
|
||||||
|
<!-- <view class="form-container"> -->
|
||||||
|
<!-- <view class="view-container"> -->
|
||||||
|
<view class="view-item view-item-3">
|
||||||
|
<view class="label" @click="onLabelClick">货区</view>
|
||||||
|
<view class="select" @click="openPicker">
|
||||||
|
{{ selectedStorage || '请选择货区' }}
|
||||||
|
</view>
|
||||||
|
<u-picker :show="showPicker" ref="uPicker" :columns="columns" @cancel="cancelPicker" @confirm="confirmPicker"
|
||||||
|
@change="changeHandler"></u-picker>
|
||||||
|
</view>
|
||||||
|
<!-- </view> -->
|
||||||
|
<!-- </view> -->
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'WarehouseSelector',
|
||||||
|
props: {
|
||||||
|
// 初始选中的货区
|
||||||
|
initialStorage: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 原始warehouse对象
|
||||||
|
initialWarehouse: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showPicker: false,
|
||||||
|
selectedStorage: this.initialStorage,
|
||||||
|
warehouse: '',
|
||||||
|
shelf: '',
|
||||||
|
location: '',
|
||||||
|
columns: [
|
||||||
|
[], // 仓库列表
|
||||||
|
[], // 货架列表
|
||||||
|
[] // 货位列表
|
||||||
|
],
|
||||||
|
shelves: [], // 货架列表
|
||||||
|
locations: [], // 货位列表
|
||||||
|
selectedWarehouse: null,
|
||||||
|
selectedSheId: null,
|
||||||
|
selectedFreId: null
|
||||||
|
};
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.initData();
|
||||||
|
this.loadStorageSelection();
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 监听initialWarehouse变化,重新初始化
|
||||||
|
initialWarehouse: {
|
||||||
|
handler(newValue) {
|
||||||
|
if (newValue) {
|
||||||
|
this.selectedWarehouse = newValue;
|
||||||
|
this.initData();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
selectedWarehouse: {
|
||||||
|
handler(newVal, oldVal) {
|
||||||
|
if (newVal) {
|
||||||
|
// 重新拉取货架和货位数据
|
||||||
|
this.columns[0] = [newVal.name];
|
||||||
|
this.fetchShelves(newVal.id).then(shelves => {
|
||||||
|
if (shelves.length > 0) {
|
||||||
|
this.columns[1] = shelves.map(item => item.code);
|
||||||
|
this.fetchLocations(shelves[0].id).then(locations => {
|
||||||
|
this.columns[2] = locations.map(item => item.code);
|
||||||
|
|
||||||
|
// 在数据加载完成后,尝试加载该仓库的货区状态
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.loadStorageSelection();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.columns[1] = [];
|
||||||
|
this.columns[2] = [];
|
||||||
|
// 没有货架数据时也要尝试加载货区状态(可能会清空)
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.loadStorageSelection();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 如果是仓库切换(不是初始化),先清空当前状态
|
||||||
|
if (oldVal && oldVal.id !== newVal.id) {
|
||||||
|
console.log(`仓库从${oldVal.id}切换到${newVal.id},清空当前货区状态`);
|
||||||
|
this.clearStorageSelection();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 没有选择仓库时清空状态
|
||||||
|
this.clearStorageSelection();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 保存货区选择状态到本地存储
|
||||||
|
saveStorageSelection() {
|
||||||
|
// 只有在选择了仓库的情况下才保存货区状态
|
||||||
|
if (!this.selectedWarehouse || !this.selectedWarehouse.id) {
|
||||||
|
console.log('未选择仓库,不保存货区状态');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const storageData = {
|
||||||
|
selectedStorage: this.selectedStorage,
|
||||||
|
warehouse: this.warehouse,
|
||||||
|
shelf: this.shelf,
|
||||||
|
location: this.location,
|
||||||
|
selectedSheId: this.selectedSheId,
|
||||||
|
selectedFreId: this.selectedFreId
|
||||||
|
};
|
||||||
|
|
||||||
|
// 使用仓库ID作为键的一部分,为每个仓库单独保存货区状态
|
||||||
|
const storageKey = `selectedStorageData_${this.selectedWarehouse.id}`;
|
||||||
|
uni.setStorageSync(storageKey, storageData);
|
||||||
|
console.log(`保存仓库${this.selectedWarehouse.id}的货区选择状态:`, storageData);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 从本地存储加载货区选择状态
|
||||||
|
loadStorageSelection() {
|
||||||
|
try {
|
||||||
|
// 只有在选择了仓库的情况下才加载货区状态
|
||||||
|
if (!this.selectedWarehouse || !this.selectedWarehouse.id) {
|
||||||
|
console.log('未选择仓库,清空货区状态');
|
||||||
|
this.clearStorageSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据仓库ID加载对应的货区状态
|
||||||
|
const storageKey = `selectedStorageData_${this.selectedWarehouse.id}`;
|
||||||
|
const storageData = uni.getStorageSync(storageKey);
|
||||||
|
|
||||||
|
if (storageData) {
|
||||||
|
console.log(`加载仓库${this.selectedWarehouse.id}的货区选择状态:`, storageData);
|
||||||
|
this.selectedStorage = storageData.selectedStorage || '';
|
||||||
|
this.warehouse = storageData.warehouse || '';
|
||||||
|
this.shelf = storageData.shelf || '';
|
||||||
|
this.location = storageData.location || '';
|
||||||
|
this.selectedSheId = storageData.selectedSheId || null;
|
||||||
|
this.selectedFreId = storageData.selectedFreId || null;
|
||||||
|
|
||||||
|
// 强制更新视图
|
||||||
|
this.$forceUpdate();
|
||||||
|
} else {
|
||||||
|
console.log(`仓库${this.selectedWarehouse.id}没有保存的货区状态,清空当前状态`);
|
||||||
|
this.clearStorageSelection();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载货区选择状态失败:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 清空货区选择状态
|
||||||
|
clearStorageSelection() {
|
||||||
|
this.selectedStorage = '';
|
||||||
|
this.warehouse = '';
|
||||||
|
this.shelf = '';
|
||||||
|
this.location = '';
|
||||||
|
this.selectedSheId = null;
|
||||||
|
this.selectedFreId = null;
|
||||||
|
|
||||||
|
// 重置选择器的值
|
||||||
|
this.selectedValues = ['', '', ''];
|
||||||
|
|
||||||
|
// 强制更新视图
|
||||||
|
this.$forceUpdate();
|
||||||
|
console.log('已清空货区选择状态');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 初始化数据
|
||||||
|
async initData() {
|
||||||
|
if (this.initialWarehouse) {
|
||||||
|
this.selectedWarehouse = this.initialWarehouse;
|
||||||
|
|
||||||
|
// 设置仓库列
|
||||||
|
this.columns[0] = [this.initialWarehouse.name];
|
||||||
|
|
||||||
|
// 加载货架数据
|
||||||
|
if (this.initialWarehouse.id) {
|
||||||
|
const shelves = await this.fetchShelves(this.initialWarehouse.id);
|
||||||
|
// console.log('初始化货架数据:', shelves);
|
||||||
|
|
||||||
|
// 如果存在货架数据,加载第一个货架的货位数据
|
||||||
|
if (shelves && shelves.length > 0) {
|
||||||
|
await this.fetchLocations(shelves[0].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 更新选中的货区数据
|
||||||
|
updateSelectedStorage(data) {
|
||||||
|
// console.log('更新货区数据:', data);
|
||||||
|
if (data) {
|
||||||
|
this.selectedStorage = data.storage;
|
||||||
|
this.warehouse = data.warehouse;
|
||||||
|
this.shelf = data.shelf;
|
||||||
|
this.location = data.location;
|
||||||
|
this.selectedSheId = data.shelfId;
|
||||||
|
this.selectedFreId = data.locationId;
|
||||||
|
|
||||||
|
// 强制更新视图
|
||||||
|
this.$forceUpdate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 打开选择器
|
||||||
|
openPicker() {
|
||||||
|
// 在打开选择器前确保数据已加载
|
||||||
|
if (this.columns[0].length === 0 && this.selectedWarehouse) {
|
||||||
|
this.columns[0] = [this.selectedWarehouse.name];
|
||||||
|
}
|
||||||
|
this.showPicker = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 点击标签
|
||||||
|
onLabelClick() {
|
||||||
|
this.$emit('label-click');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 取消选择
|
||||||
|
cancelPicker() {
|
||||||
|
this.showPicker = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 确认选择
|
||||||
|
confirmPicker(e) {
|
||||||
|
const {
|
||||||
|
value
|
||||||
|
} = e;
|
||||||
|
const [warehouse, shelf, location] = value;
|
||||||
|
|
||||||
|
// 只有当三个值都存在时才保存选中的值
|
||||||
|
if (warehouse && shelf && location) {
|
||||||
|
this.warehouse = warehouse;
|
||||||
|
this.shelf = shelf;
|
||||||
|
this.location = location;
|
||||||
|
|
||||||
|
// 更新显示文本
|
||||||
|
this.selectedStorage = `${warehouse} / ${shelf} / ${location}`;
|
||||||
|
|
||||||
|
// 查找选中项的ID
|
||||||
|
const selectedShelf = this.shelves.find(item => item.code === shelf);
|
||||||
|
const selectedLocation = this.locations.find(item => item.code === location);
|
||||||
|
|
||||||
|
// 保存选中ID
|
||||||
|
this.selectedSheId = selectedShelf?.id;
|
||||||
|
this.selectedFreId = selectedLocation?.id;
|
||||||
|
|
||||||
|
// 保存选择状态到本地存储
|
||||||
|
this.saveStorageSelection();
|
||||||
|
|
||||||
|
// 向父组件发送选中数据
|
||||||
|
this.$emit('storage-selected', {
|
||||||
|
storage: this.selectedStorage,
|
||||||
|
warehouse: this.warehouse,
|
||||||
|
shelf: this.shelf,
|
||||||
|
location: this.location,
|
||||||
|
shelfId: this.selectedSheId,
|
||||||
|
locationId: this.selectedFreId
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 如果不完整,提示用户
|
||||||
|
uni.showToast({
|
||||||
|
title: '请完整选择仓库、货架和货位',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.showPicker = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 处理picker列变化
|
||||||
|
async changeHandler(e) {
|
||||||
|
// 防御性检查,确保e和必要的属性存在
|
||||||
|
if (!e) {
|
||||||
|
console.warn('changeHandler: 事件对象为空');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('选择器变化:', e);
|
||||||
|
|
||||||
|
// 获取列索引和选中的索引数组
|
||||||
|
const {
|
||||||
|
columnIndex,
|
||||||
|
index
|
||||||
|
} = e;
|
||||||
|
|
||||||
|
// 如果是选择了仓库(第0列)
|
||||||
|
if (columnIndex === 0) {
|
||||||
|
// 获取选中的仓库
|
||||||
|
const warehouseName = this.columns[0][index];
|
||||||
|
|
||||||
|
// 使用仓库ID获取货架数据
|
||||||
|
if (this.selectedWarehouse && this.selectedWarehouse.id) {
|
||||||
|
await this.fetchShelves(this.selectedWarehouse.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是选择了货架(第1列)
|
||||||
|
if (columnIndex === 1 && this.shelves.length > 0) {
|
||||||
|
// 获取选中的货架
|
||||||
|
const selectedShelf = this.shelves[index];
|
||||||
|
// console.log('选中货架:', selectedShelf);
|
||||||
|
|
||||||
|
// 保存选中的货架ID
|
||||||
|
if (selectedShelf && selectedShelf.id) {
|
||||||
|
this.selectedSheId = selectedShelf.id;
|
||||||
|
await this.fetchLocations(selectedShelf.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取货架列表
|
||||||
|
async fetchShelves(depotId) {
|
||||||
|
try {
|
||||||
|
// console.log('获取货架数据,仓库ID:', depotId);
|
||||||
|
|
||||||
|
const response = await uni.request({
|
||||||
|
url: 'https://api.buzhiyushu.cn/shelves/shelves/sheNamelist',
|
||||||
|
data: {
|
||||||
|
depotId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 使用数组解构获取响应结果
|
||||||
|
const [err, res] = Array.isArray(response) ? response : [null, response];
|
||||||
|
|
||||||
|
if (!res?.data?.rows) {
|
||||||
|
console.error('获取货架数据失败,返回空数据');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.shelves = res.data.rows; // 保存货架列表
|
||||||
|
this.columns[1] = this.shelves.map(item => item.code || '未知货架');
|
||||||
|
|
||||||
|
// console.log('获取到货架数据:', this.shelves);
|
||||||
|
// console.log('货架选项:', this.columns[1]);
|
||||||
|
|
||||||
|
// 更新UI
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker.setColumnValues(1, this.columns[1]);
|
||||||
|
// 清空货位列
|
||||||
|
this.$refs.uPicker.setColumnValues(2, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.shelves;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取货架失败:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取货位列表
|
||||||
|
async fetchLocations(sheId) {
|
||||||
|
if (!sheId) {
|
||||||
|
console.error('获取货位列表失败:未提供货架ID');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// console.log('获取货位数据,货架ID:', sheId);
|
||||||
|
|
||||||
|
const response = await uni.request({
|
||||||
|
url: 'https://api.buzhiyushu.cn/shelves/shelves/freNamelist',
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
sheId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 使用数组解构获取响应结果
|
||||||
|
const [err, res] = Array.isArray(response) ? response : [null, response];
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
console.error('获取货位请求错误:', err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!res || !res.data || !res.data.rows) {
|
||||||
|
console.error('货位响应数据格式不正确');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const locations = res.data.rows;
|
||||||
|
// console.log('获取到货位数据:', locations);
|
||||||
|
|
||||||
|
// 保存货位数据
|
||||||
|
this.locations = locations;
|
||||||
|
|
||||||
|
// 更新货位列
|
||||||
|
this.columns[2] = locations.map(item => item.code || '未知货位');
|
||||||
|
// console.log('货位选项:', this.columns[2]);
|
||||||
|
|
||||||
|
// 更新UI
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.uPicker) {
|
||||||
|
this.$refs.uPicker.setColumnValues(2, this.columns[2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return locations;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取货位列表失败:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// 监听外部更新事件
|
||||||
|
this.$on('storage-selected', this.updateSelectedStorage);
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
// 移除事件监听
|
||||||
|
this.$off('storage-selected', this.updateSelectedStorage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.view-container {
|
||||||
|
display: flex;
|
||||||
|
background-color: #fff;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
/* 垂直居中 */
|
||||||
|
padding: 3rpx 0;
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
position: relative;
|
||||||
|
/* border-bottom: 1px solid #ccc; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-3 {
|
||||||
|
flex: 3 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-4 {
|
||||||
|
flex: 4 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-6 {
|
||||||
|
flex: 6 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item-7 {
|
||||||
|
flex: 7 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item>.label {
|
||||||
|
padding: 0rpx 15rpx;
|
||||||
|
text-align: center;
|
||||||
|
height: 60rpx;
|
||||||
|
line-height: 60rpx;
|
||||||
|
color: #000;
|
||||||
|
font-size: 28rpx;
|
||||||
|
background-color: #ccc;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-item>.select {
|
||||||
|
padding: 16rpx 0rpx;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 40rpx;
|
||||||
|
font-size: 18rpx;
|
||||||
|
line-height: 45rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-container {
|
||||||
|
padding-left: 10rpx;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep .u-picker__view__column__item[class*="data-v-"] {
|
||||||
|
font-size: 30rpx !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 确保选择器文本也使用相同大小 */
|
||||||
|
.view-item>.select {
|
||||||
|
font-size: 23rpx !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
::v-deep .data-v-55c89db1 .u-toolbar__wrapper__confirm.data-v-55c89db1 {
|
||||||
|
color: #3c9cff;
|
||||||
|
font-size: 45rpx;
|
||||||
|
padding: 0 15rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
20
index.html
Normal file
20
index.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<script>
|
||||||
|
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||||
|
CSS.supports('top: constant(a)'))
|
||||||
|
document.write(
|
||||||
|
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||||
|
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||||
|
</script>
|
||||||
|
<title></title>
|
||||||
|
<!--preload-links-->
|
||||||
|
<!--app-context-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"><!--app-html--></div>
|
||||||
|
<script type="module" src="/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
22
main.js
Normal file
22
main.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import App from './App'
|
||||||
|
import store from './store'
|
||||||
|
import uniAjax from '@/utils/request.js'
|
||||||
|
import uView from '@/uni_modules/uview-ui'
|
||||||
|
import CryptoJS from 'crypto-js'
|
||||||
|
import share from './static/share'
|
||||||
|
|
||||||
|
Vue.prototype.$http = uniAjax
|
||||||
|
Vue.prototype.$store = store
|
||||||
|
Vue.use(uView)
|
||||||
|
Vue.config.productionTip = false
|
||||||
|
Vue.mixin(share);
|
||||||
|
|
||||||
|
App.mpType = 'app'
|
||||||
|
|
||||||
|
const app = new Vue({
|
||||||
|
store,
|
||||||
|
...App,
|
||||||
|
share
|
||||||
|
})
|
||||||
|
app.$mount()
|
||||||
45
manifest.json
Normal file
45
manifest.json
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"name" : "zhizhu",
|
||||||
|
"appid" : "__UNI__CAA2B01",
|
||||||
|
"description" : "",
|
||||||
|
"versionName" : "1.0.0",
|
||||||
|
"versionCode" : "100",
|
||||||
|
"mp-weixin" : {
|
||||||
|
"appid" : "wx703b8fb6c3da692a",
|
||||||
|
"setting" : {
|
||||||
|
"urlCheck" : false,
|
||||||
|
"es6" : true,
|
||||||
|
"postcss" : true,
|
||||||
|
"minified" : true
|
||||||
|
},
|
||||||
|
"usingComponents" : true,
|
||||||
|
"lazyCodeLoading" : "requiredComponents"
|
||||||
|
},
|
||||||
|
"mp-alipay" : {
|
||||||
|
// ← 这是支付宝小程序配置
|
||||||
|
"usingComponents" : true
|
||||||
|
}, // ← 最后一个配置项不需要逗号
|
||||||
|
"vueOptions" : {
|
||||||
|
"runtimeCompiler" : true // 确保开启运行时编译
|
||||||
|
},
|
||||||
|
"request" : {
|
||||||
|
"domain" : [
|
||||||
|
"`https://api.buzhiyushu.cn" // 替换为你后端项目的域名或 IP 地址
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"app-plus" : {
|
||||||
|
"modules" : {
|
||||||
|
"OAuth" : {}
|
||||||
|
},
|
||||||
|
"distribute" : {
|
||||||
|
"sdkConfigs" : {
|
||||||
|
"oauth" : {
|
||||||
|
"weixin" : {
|
||||||
|
"appid" : "wx703b8fb6c3da692a",
|
||||||
|
"UniversalLinks" : ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
node_modules/.bin/detect-libc
generated
vendored
Normal file
16
node_modules/.bin/detect-libc
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../detect-libc/bin/detect-libc.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../detect-libc/bin/detect-libc.js" "$@"
|
||||||
|
fi
|
||||||
17
node_modules/.bin/detect-libc.cmd
generated
vendored
Normal file
17
node_modules/.bin/detect-libc.cmd
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
@ECHO off
|
||||||
|
GOTO start
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
|
:start
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\detect-libc\bin\detect-libc.js" %*
|
||||||
28
node_modules/.bin/detect-libc.ps1
generated
vendored
Normal file
28
node_modules/.bin/detect-libc.ps1
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "$basedir/node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
|
||||||
|
} else {
|
||||||
|
& "$basedir/node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../detect-libc/bin/detect-libc.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
16
node_modules/.bin/sass
generated
vendored
Normal file
16
node_modules/.bin/sass
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../sass/sass.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../sass/sass.js" "$@"
|
||||||
|
fi
|
||||||
17
node_modules/.bin/sass.cmd
generated
vendored
Normal file
17
node_modules/.bin/sass.cmd
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
@ECHO off
|
||||||
|
GOTO start
|
||||||
|
:find_dp0
|
||||||
|
SET dp0=%~dp0
|
||||||
|
EXIT /b
|
||||||
|
:start
|
||||||
|
SETLOCAL
|
||||||
|
CALL :find_dp0
|
||||||
|
|
||||||
|
IF EXIST "%dp0%\node.exe" (
|
||||||
|
SET "_prog=%dp0%\node.exe"
|
||||||
|
) ELSE (
|
||||||
|
SET "_prog=node"
|
||||||
|
SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||||
|
)
|
||||||
|
|
||||||
|
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\sass\sass.js" %*
|
||||||
28
node_modules/.bin/sass.ps1
generated
vendored
Normal file
28
node_modules/.bin/sass.ps1
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env pwsh
|
||||||
|
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||||
|
|
||||||
|
$exe=""
|
||||||
|
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||||
|
# Fix case when both the Windows and Linux builds of Node
|
||||||
|
# are installed in the same directory
|
||||||
|
$exe=".exe"
|
||||||
|
}
|
||||||
|
$ret=0
|
||||||
|
if (Test-Path "$basedir/node$exe") {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "$basedir/node$exe" "$basedir/../sass/sass.js" $args
|
||||||
|
} else {
|
||||||
|
& "$basedir/node$exe" "$basedir/../sass/sass.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
} else {
|
||||||
|
# Support pipeline input
|
||||||
|
if ($MyInvocation.ExpectingInput) {
|
||||||
|
$input | & "node$exe" "$basedir/../sass/sass.js" $args
|
||||||
|
} else {
|
||||||
|
& "node$exe" "$basedir/../sass/sass.js" $args
|
||||||
|
}
|
||||||
|
$ret=$LASTEXITCODE
|
||||||
|
}
|
||||||
|
exit $ret
|
||||||
282
node_modules/.package-lock.json
generated
vendored
Normal file
282
node_modules/.package-lock.json
generated
vendored
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
{
|
||||||
|
"name": "zhizhu",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"node_modules/@dcloudio/uni-ui": {
|
||||||
|
"version": "1.5.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@dcloudio/uni-ui/-/uni-ui-1.5.7.tgz",
|
||||||
|
"integrity": "sha512-DugxSIrQrze1FLdUOj9a+JEQ0bHGjnJTcGUK1mN/MivKg7nuKJBRWk5Ipa9sUdoBznX6ndz5h2e7Uao6x1CdCw==",
|
||||||
|
"license": "Apache-2.0"
|
||||||
|
},
|
||||||
|
"node_modules/@parcel/watcher": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-dfUnCxiN9H4ap84DvD2ubjw+3vUNpstxa0TneY/Paat8a3R4uQZDLSvWjmznAY/DoahqTHl9V46HF/Zs3F29pg==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"detect-libc": "^1.0.3",
|
||||||
|
"is-glob": "^4.0.3",
|
||||||
|
"micromatch": "^4.0.5",
|
||||||
|
"node-addon-api": "^7.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/parcel"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@parcel/watcher-android-arm64": "2.5.1",
|
||||||
|
"@parcel/watcher-darwin-arm64": "2.5.1",
|
||||||
|
"@parcel/watcher-darwin-x64": "2.5.1",
|
||||||
|
"@parcel/watcher-freebsd-x64": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-arm-glibc": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-arm-musl": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-arm64-glibc": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-arm64-musl": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-x64-glibc": "2.5.1",
|
||||||
|
"@parcel/watcher-linux-x64-musl": "2.5.1",
|
||||||
|
"@parcel/watcher-win32-arm64": "2.5.1",
|
||||||
|
"@parcel/watcher-win32-ia32": "2.5.1",
|
||||||
|
"@parcel/watcher-win32-x64": "2.5.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@parcel/watcher-win32-x64": {
|
||||||
|
"version": "2.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.5.1.tgz",
|
||||||
|
"integrity": "sha512-9lHBdJITeNR++EvSQVUcaZoWupyHfXe1jZvGZ06O/5MflPcuPLtEphScIBL+AiCWBO46tDSHzWyD0uDmmZqsgA==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10.0.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/parcel"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/braces": {
|
||||||
|
"version": "3.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"fill-range": "^7.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/chokidar": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"readdirp": "^4.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.16.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://paulmillr.com/funding/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/crypto-js": {
|
||||||
|
"version": "4.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
|
||||||
|
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/detect-libc": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"optional": true,
|
||||||
|
"bin": {
|
||||||
|
"detect-libc": "bin/detect-libc.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/fill-range": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"to-regex-range": "^5.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/immutable": {
|
||||||
|
"version": "5.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/immutable/-/immutable-5.1.1.tgz",
|
||||||
|
"integrity": "sha512-3jatXi9ObIsPGr3N5hGw/vWWcTkq6hUYhpQz4k0wLC+owqWi/LiugIw9x0EdNZ2yGedKN/HzePiBvaJRXa0Ujg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/is-extglob": {
|
||||||
|
"version": "2.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||||
|
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/is-glob": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"is-extglob": "^2.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/is-number": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/micromatch": {
|
||||||
|
"version": "4.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||||
|
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"braces": "^3.0.3",
|
||||||
|
"picomatch": "^2.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/node-addon-api": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"node_modules/picomatch": {
|
||||||
|
"version": "2.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
|
||||||
|
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/jonschlinkert"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/readdirp": {
|
||||||
|
"version": "4.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
|
||||||
|
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.18.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://paulmillr.com/funding/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/sass": {
|
||||||
|
"version": "1.86.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/sass/-/sass-1.86.3.tgz",
|
||||||
|
"integrity": "sha512-iGtg8kus4GrsGLRDLRBRHY9dNVA78ZaS7xr01cWnS7PEMQyFtTqBiyCrfpTYTZXRWM94akzckYjh8oADfFNTzw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"chokidar": "^4.0.0",
|
||||||
|
"immutable": "^5.0.2",
|
||||||
|
"source-map-js": ">=0.6.2 <2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"sass": "sass.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@parcel/watcher": "^2.4.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/source-map-js": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/to-regex-range": {
|
||||||
|
"version": "5.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
|
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"dependencies": {
|
||||||
|
"is-number": "^7.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/uview-ui": {
|
||||||
|
"version": "2.0.38",
|
||||||
|
"resolved": "https://registry.npmjs.org/uview-ui/-/uview-ui-2.0.38.tgz",
|
||||||
|
"integrity": "sha512-6egHDf9lXHKpG3hEjRE0vMx4+VWwKk/ReTf5x18KrIKqdvdPRqO3+B8Unh7vYYwrIxzAWIlmhZ9RJpKI/4UqPQ==",
|
||||||
|
"engines": {
|
||||||
|
"HBuilderX": "^3.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
202
node_modules/@dcloudio/uni-ui/LICENSE
generated
vendored
Normal file
202
node_modules/@dcloudio/uni-ui/LICENSE
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
245
node_modules/@dcloudio/uni-ui/README.md
generated
vendored
Normal file
245
node_modules/@dcloudio/uni-ui/README.md
generated
vendored
Normal file
@ -0,0 +1,245 @@
|
|||||||
|
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-transition)
|
||||||
|
#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
|
||||||
|
|
||||||
|
## uni-ui产品特点
|
||||||
|
|
||||||
|
### 1. 高性能
|
||||||
|
|
||||||
|
目前为止,在小程序和混合app领域,暂时还没有比 `uni-ui` 更高性能的框架。
|
||||||
|
- 自动差量更新数据
|
||||||
|
|
||||||
|
虽然uni-app支持小程序自定义组件,所有小程序的ui库都可以用。但小程序自定义组件的ui库都需要使用setData手动更新数据,在大数据量时、或高频更新数据时,很容易产生性能问题。
|
||||||
|
|
||||||
|
而 `uni-ui` 属于vue组件,uni-app引擎底层自动diff更新数据。当然其实插件市场里众多vue组件都具备这个特点。
|
||||||
|
- 优化逻辑层和视图层通讯折损
|
||||||
|
|
||||||
|
非H5,不管是小程序还是App,不管是app的webview渲染还是原生渲染,全都是逻辑层和视图层分离的。这里就有一个逻辑层和视图层通讯的折损问题。
|
||||||
|
比如在视图层拖动一个可跟手的组件,由于通讯的损耗,用js监听很难做到实时跟手。
|
||||||
|
|
||||||
|
这时就需要使用css动画以及平台底层提供的wxs、bindingx等技术。不过这些技术都比较复杂,所以 `uni-ui` 里做了封装,在需要跟手式操作的ui组件,比如swiperaction列表项左滑菜单,就在底层使用了这些技术,实现了高性能的交互体验
|
||||||
|
- 背景停止
|
||||||
|
|
||||||
|
很多ui组件是会一直动的,比如轮播图、跑马灯。即便这个窗体被新窗体挡住,它在背景层仍然在消耗着硬件资源。在Android的webview版本为chrome66以上,背景操作ui会引发很严重的性能问题,造成前台界面明显卡顿。
|
||||||
|
|
||||||
|
而 `uni-ui` 的组件,会自动判断自己的显示状态,在组件不再可见时,不会再消耗硬件资源。
|
||||||
|
|
||||||
|
### 2. 全端
|
||||||
|
|
||||||
|
`uni-ui` 的组件都是多端自适应的,底层会抹平很多小程序平台的差异或bug。
|
||||||
|
|
||||||
|
比如导航栏navbar组件,会自动处理不同端的状态栏。
|
||||||
|
比如swiperaction组件,在app和微信小程序上会使用交互体验更好的wxs技术,但在不支持wxs的其他小程序端会使用js模拟类似效果。
|
||||||
|
|
||||||
|
`uni-ui` 还支持nvue原生渲染,[详见](https://github.com/dcloudio/uni-ui/tree/nvue-uni-ui)
|
||||||
|
|
||||||
|
未来 `uni-ui` 还会支持pc等大屏设备。
|
||||||
|
|
||||||
|
### 3. 与uni统计自动集成实现免打点
|
||||||
|
|
||||||
|
uni统计是优秀的多端统计平台,见[tongji.dcloud.net.cn](https://tongji.dcloud.net.cn)。
|
||||||
|
|
||||||
|
除了一张报表看全端,它的另一个重要特点是免打点。
|
||||||
|
比如使用 `uni-ui` 的navbar标题栏、收藏、购物车等组件,均可实现自动打点,统计页面标题等各种行为数据。
|
||||||
|
当然你也可以关闭uni统计,这不是强制的。
|
||||||
|
|
||||||
|
### 4. 主题扩展
|
||||||
|
|
||||||
|
`uni-ui` 支持[uni.scss](https://uniapp.dcloud.io/collocation/uni-scss),可以方便的切换App的风格。
|
||||||
|
|
||||||
|
ui是一种需求非常发散的产品,DCloud官方也无意用 `uni-ui` 压制第三方ui插件的空间,但官方有义务在性能和多端方面提供一个开源的标杆给大家。
|
||||||
|
|
||||||
|
我们欢迎更多优秀的ui组件出现,也欢迎更多人贡献 `uni-ui` 的主题风格,满足更多用户的需求。
|
||||||
|
|
||||||
|
|
||||||
|
# 快速开始
|
||||||
|
|
||||||
|
## 方式一:使用 uni_modules 安装(推荐)
|
||||||
|
|
||||||
|
使用 `uni_modules` 方式安装组件库,可以直接通过插件市场导入,通过右键菜单快速更新组件,不需要引用、注册,直接在页面中使用 `uni-ui` 组件。[点击安装 uni-ui 组件库](https://ext.dcloud.net.cn/plugin?id=55)
|
||||||
|
|
||||||
|
**注意:下载最新的组件目前仅支持 uni_modules ,非 uni_modules 版本最高支持到组件的1.2.10版本**
|
||||||
|
|
||||||
|
如不能升级到 `uni_modules` 版本,可以使用 `uni_modules` 安装好对应组件,将组件拷贝到对应目录。
|
||||||
|
|
||||||
|
例如需更新 `uni-list`和`uni-badge` ,将 `uni_modules>uni-list>components`和`uni_modules>uni-badege>components`下所有目录拷贝到如下目录即可:
|
||||||
|
|
||||||
|
**目录示例**
|
||||||
|
```json {2,3,4,5,6,7}
|
||||||
|
┌─components 组件目录
|
||||||
|
│ ├─uni-list list 列表目录
|
||||||
|
│ │ └─uni-list.vue list 组件文件
|
||||||
|
│ ├─uni-list-item list-item 列表目录
|
||||||
|
│ │ └─uni-list-item.vue list 组件文件
|
||||||
|
│ ├─uni-badge badge 角标目录
|
||||||
|
│ │ └─uni-badge.vue badge 组件文件
|
||||||
|
│ └─ //.... 更多组件文件
|
||||||
|
├─pages 业务页面文件存放的目录
|
||||||
|
│ ├─index
|
||||||
|
│ │ └─index.vue index示例页面
|
||||||
|
├─main.js Vue初始化入口文件
|
||||||
|
├─App.vue 应用配置,用来配置App全局样式以及监听 应用生命周期
|
||||||
|
├─manifest.json 配置应用名称、appid、logo、版本等打包信息,详见
|
||||||
|
└─pages.json 配置页
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## 方式二:使用 npm 安装
|
||||||
|
|
||||||
|
在 `vue-cli` 项目中可以使用 `npm` 安装 `uni-ui` 库 ,或者直接在 `HBuilderX` 项目中使用 `npm` 。(不推荐后一种方式)
|
||||||
|
|
||||||
|
> **注意**
|
||||||
|
> cli 项目默认是不编译 `node_modules` 下的组件的,导致条件编译等功能失效 ,导致组件异常
|
||||||
|
> 需要在根目录创建 `vue.config.js` 文件 ,增加 `@dcloudio/uni-ui` 包的编译即可正常
|
||||||
|
> ```javascript
|
||||||
|
> // vue.config.js
|
||||||
|
> module.exports = {
|
||||||
|
> transpileDependencies:['@dcloudio/uni-ui']
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**准备 sass**
|
||||||
|
|
||||||
|
`vue-cli` 项目请先安装 sass 及 sass-loader,如在 HBuliderX 中使用,可跳过此步。
|
||||||
|
|
||||||
|
- 安装 sass
|
||||||
|
```
|
||||||
|
npm i sass -D 或 yarn add sass -D
|
||||||
|
```
|
||||||
|
|
||||||
|
- 安装 sass-loader
|
||||||
|
```
|
||||||
|
npm i sass-loader@10.1.1 -D 或 yarn add sass-loader@10.1.1 -D
|
||||||
|
```
|
||||||
|
|
||||||
|
> sass-loader 请使用低于 @11.0.0 的版本,[sass-loader@11.0.0 不支持 vue@2.6.12 ](https://stackoverflow.com/questions/66082397/typeerror-this-getoptions-is-not-a-function)
|
||||||
|
|
||||||
|
|
||||||
|
**安装 uni-ui**
|
||||||
|
|
||||||
|
```
|
||||||
|
npm i @dcloudio/uni-ui 或 yarn add @dcloudio/uni-ui
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
在 ``script`` 中引用组件:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {uniBadge} from '@dcloudio/uni-ui'
|
||||||
|
//import uniBadge from '@dcloudio/uni-ui/lib/uni-badge/uni-badge.vue' //也可使用此方式引入组件
|
||||||
|
export default {
|
||||||
|
components: {uniBadge}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
在 ``template`` 中使用组件:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<uni-badge text="1"></uni-badge>
|
||||||
|
<uni-badge text="2" type="success" @click="bindClick"></uni-badge>
|
||||||
|
<uni-badge text="3" type="primary" :inverted="true"></uni-badge>
|
||||||
|
```
|
||||||
|
> **注意**
|
||||||
|
> - `CLI` 引用方式, `H5` 端不支持在 `main.js` 中全局注册组件,如有需求请使用([easyCom](https://uniapp.dcloud.io/collocation/pages?id=easycom)) 的方式引用组件
|
||||||
|
> - 使用 npm 安装的组件,默认情况下 babel-loader 会忽略所有 node_modules 中的文件 ,导致条件编译失效,需要通过配置 `vue.config.js` 解决:
|
||||||
|
> ```javascript
|
||||||
|
> // 在根目录创建 vue.config.js 文件,并配置如下
|
||||||
|
> module.exports = {
|
||||||
|
> transpileDependencies: ['@dcloudio/uni-ui']
|
||||||
|
> }
|
||||||
|
> ```
|
||||||
|
|
||||||
|
|
||||||
|
## 使用 npm + easycom
|
||||||
|
|
||||||
|
使用 `npm` 安装好 `uni-ui` 之后,需要配置 `easycom` 规则,让 `npm` 安装的组件支持 `easycom`
|
||||||
|
|
||||||
|
打开项目根目录下的 `pages.json` 并添加 `easycom` 节点:
|
||||||
|
|
||||||
|
```javascript {8}
|
||||||
|
// pages.json
|
||||||
|
|
||||||
|
{
|
||||||
|
"easycom": {
|
||||||
|
"autoscan": true,
|
||||||
|
"custom": {
|
||||||
|
// uni-ui 规则如下配置
|
||||||
|
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 其他内容
|
||||||
|
pages:[
|
||||||
|
// ...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### uni-ui 已支持的组件列表
|
||||||
|
|组件名|组件说明|
|
||||||
|
|---|---|
|
||||||
|
|uni-badge|[数字角标](https://ext.dcloud.net.cn/plugin?name=uni-badge)|
|
||||||
|
|uni-breadcrumb|[面包屑](https://ext.dcloud.net.cn/plugin?name=uni-breadcrumb)|
|
||||||
|
|uni-calendar|[日历](https://ext.dcloud.net.cn/plugin?name=uni-calendar)|
|
||||||
|
|uni-card|[卡片](https://ext.dcloud.net.cn/plugin?name=uni-card)|
|
||||||
|
|uni-collapse|[折叠面板](https://ext.dcloud.net.cn/plugin?name=uni-collapse)|
|
||||||
|
|uni-combox|[组合框](https://ext.dcloud.net.cn/plugin?name=uni-combox)|
|
||||||
|
|uni-countdown|[倒计时](https://ext.dcloud.net.cn/plugin?name=uni-countdown)|
|
||||||
|
|uni-data-checkbox|[数据选择器](https://ext.dcloud.net.cn/plugin?name=uni-data-checkbox)|
|
||||||
|
|uni-data-picker|[数据驱动的picker选择器](https://ext.dcloud.net.cn/plugin?name=uni-data-picker)|
|
||||||
|
|uni-data-select|[下拉框选择器](https://ext.dcloud.net.cn/plugin?name=uni-data-select)|
|
||||||
|
|uni-dateformat|[日期格式化](https://ext.dcloud.net.cn/plugin?name=uni-dateformat)|
|
||||||
|
|uni-datetime-picker|[日期选择器](https://ext.dcloud.net.cn/plugin?name=uni-datetime-picker)|
|
||||||
|
|uni-drawer|[抽屉](https://ext.dcloud.net.cn/plugin?name=uni-drawer)|
|
||||||
|
|uni-easyinput|[增强输入框](https://ext.dcloud.net.cn/plugin?name=uni-easyinput)|
|
||||||
|
|uni-fab|[悬浮按钮](https://ext.dcloud.net.cn/plugin?name=uni-fab)|
|
||||||
|
|uni-fav|[收藏按钮](https://ext.dcloud.net.cn/plugin?name=uni-fav)|
|
||||||
|
|uni-file-picker|[文件选择上传](https://ext.dcloud.net.cn/plugin?name=uni-file-picker)|
|
||||||
|
|uni-forms|[表单](https://ext.dcloud.net.cn/plugin?name=uni-forms)|
|
||||||
|
|uni-goods-nav|[商品导航](https://ext.dcloud.net.cn/plugin?name=uni-goods-nav)|
|
||||||
|
|uni-grid|[宫格](https://ext.dcloud.net.cn/plugin?name=uni-grid)|
|
||||||
|
|uni-group|[分组](https://ext.dcloud.net.cn/plugin?name=uni-group)|
|
||||||
|
|uni-icons|[图标](https://ext.dcloud.net.cn/plugin?name=uni-icons)|
|
||||||
|
|uni-indexed-list|[索引列表](https://ext.dcloud.net.cn/plugin?name=uni-indexed-list)|
|
||||||
|
|uni-link|[超链接](https://ext.dcloud.net.cn/plugin?name=uni-link)|
|
||||||
|
|uni-list|[列表](https://ext.dcloud.net.cn/plugin?name=uni-list)|
|
||||||
|
|uni-load-more|[加载更多](https://ext.dcloud.net.cn/plugin?name=uni-load-more)|
|
||||||
|
|uni-nav-bar|[自定义导航栏](https://ext.dcloud.net.cn/plugin?name=uni-nav-bar)|
|
||||||
|
|uni-notice-bar|[通告栏](https://ext.dcloud.net.cn/plugin?name=uni-notice-bar)|
|
||||||
|
|uni-number-box|[数字输入框](https://ext.dcloud.net.cn/plugin?name=uni-number-box)|
|
||||||
|
|uni-pagination|[分页器](https://ext.dcloud.net.cn/plugin?name=uni-pagination)|
|
||||||
|
|uni-popup|[弹出层](https://ext.dcloud.net.cn/plugin?name=uni-popup)|
|
||||||
|
|uni-rate|[评分](https://ext.dcloud.net.cn/plugin?name=uni-rate)|
|
||||||
|
|uni-row|[布局-行](https://ext.dcloud.net.cn/plugin?name=uni-row)|
|
||||||
|
|uni-scss|[辅助样式](https://ext.dcloud.net.cn/plugin?name=uni-scss)|
|
||||||
|
|uni-search-bar|[搜索栏](https://ext.dcloud.net.cn/plugin?name=uni-search-bar)|
|
||||||
|
|uni-section|[标题栏](https://ext.dcloud.net.cn/plugin?name=uni-section)|
|
||||||
|
|uni-segmented-control|[分段器](https://ext.dcloud.net.cn/plugin?name=uni-segmented-control)|
|
||||||
|
|uni-steps|[步骤条](https://ext.dcloud.net.cn/plugin?name=uni-steps)|
|
||||||
|
|uni-swipe-action|[滑动操作](https://ext.dcloud.net.cn/plugin?name=uni-swipe-action)|
|
||||||
|
|uni-swiper-dot|[轮播图指示点](https://ext.dcloud.net.cn/plugin?name=uni-swiper-dot)|
|
||||||
|
|uni-table|[表格](https://ext.dcloud.net.cn/plugin?name=uni-table)|
|
||||||
|
|uni-tag|[标签](https://ext.dcloud.net.cn/plugin?name=uni-tag)|
|
||||||
|
|uni-title|[章节标题](https://ext.dcloud.net.cn/plugin?name=uni-title)|
|
||||||
|
|uni-tooltip|[提示文字](https://ext.dcloud.net.cn/plugin?name=uni-tooltip)|
|
||||||
|
|uni-transition|[过渡动画](https://ext.dcloud.net.cn/plugin?name=uni-transition)|
|
||||||
|
|
||||||
|
|
||||||
|
### 其他
|
||||||
|
|
||||||
|
- uni-ui 是全端兼容的基于flex布局的、无dom的ui库
|
||||||
|
- uni-ui 是uni-app内置组件的扩展。注意与web开发不同,uni-ui不包括基础组件,它是基础组件的补充。web开发中有的开发者习惯用一个ui库完成所有开发,但在uni-app体系中,推荐开发者首先使用性能更高的基础组件,然后按需引入必要的扩展组件。
|
||||||
|
|
||||||
|
|
||||||
|
> **注意**
|
||||||
|
> - `uni-ui` 不支持使用 `Vue.use()` 的方式安装
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 贡献代码
|
||||||
|
在使用 `uni-ui` 中,如遇到无法解决的问题,请提 [Issues](https://github.com/dcloudio/uni-ui/issues) 给我们,假如您有更好的点子或更好的实现方式,也欢迎给我们提交 [PR](https://github.com/dcloudio/uni-ui/pulls)
|
||||||
268
node_modules/@dcloudio/uni-ui/lib/uni-badge/uni-badge.vue
generated
vendored
Normal file
268
node_modules/@dcloudio/uni-ui/lib/uni-badge/uni-badge.vue
generated
vendored
Normal file
@ -0,0 +1,268 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-badge--x">
|
||||||
|
<slot />
|
||||||
|
<text v-if="text" :class="classNames" :style="[positionStyle, customStyle, dotStyle]"
|
||||||
|
class="uni-badge" @click="onClick()">{{displayValue}}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Badge 数字角标
|
||||||
|
* @description 数字角标一般和其它控件(列表、9宫格等)配合使用,用于进行数量提示,默认为实心灰色背景
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=21
|
||||||
|
* @property {String} text 角标内容
|
||||||
|
* @property {String} size = [normal|small] 角标内容
|
||||||
|
* @property {String} type = [info|primary|success|warning|error] 颜色类型
|
||||||
|
* @value info 灰色
|
||||||
|
* @value primary 蓝色
|
||||||
|
* @value success 绿色
|
||||||
|
* @value warning 黄色
|
||||||
|
* @value error 红色
|
||||||
|
* @property {String} inverted = [true|false] 是否无需背景颜色
|
||||||
|
* @property {Number} maxNum 展示封顶的数字值,超过 99 显示 99+
|
||||||
|
* @property {String} absolute = [rightTop|rightBottom|leftBottom|leftTop] 开启绝对定位, 角标将定位到其包裹的标签的四角上
|
||||||
|
* @value rightTop 右上
|
||||||
|
* @value rightBottom 右下
|
||||||
|
* @value leftTop 左上
|
||||||
|
* @value leftBottom 左下
|
||||||
|
* @property {Array[number]} offset 距定位角中心点的偏移量,只有存在 absolute 属性时有效,例如:[-10, -10] 表示向外偏移 10px,[10, 10] 表示向 absolute 指定的内偏移 10px
|
||||||
|
* @property {String} isDot = [true|false] 是否显示为一个小点
|
||||||
|
* @event {Function} click 点击 Badge 触发事件
|
||||||
|
* @example <uni-badge text="1"></uni-badge>
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'UniBadge',
|
||||||
|
emits: ['click'],
|
||||||
|
props: {
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'error'
|
||||||
|
},
|
||||||
|
inverted: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
isDot: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
maxNum: {
|
||||||
|
type: Number,
|
||||||
|
default: 99
|
||||||
|
},
|
||||||
|
absolute: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
offset: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return [0, 0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: String,
|
||||||
|
default: 'small'
|
||||||
|
},
|
||||||
|
customStyle: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
width() {
|
||||||
|
return String(this.text).length * 8 + 12
|
||||||
|
},
|
||||||
|
classNames() {
|
||||||
|
const {
|
||||||
|
inverted,
|
||||||
|
type,
|
||||||
|
size,
|
||||||
|
absolute
|
||||||
|
} = this
|
||||||
|
return [
|
||||||
|
inverted ? 'uni-badge--' + type + '-inverted' : '',
|
||||||
|
'uni-badge--' + type,
|
||||||
|
'uni-badge--' + size,
|
||||||
|
absolute ? 'uni-badge--absolute' : ''
|
||||||
|
].join(' ')
|
||||||
|
},
|
||||||
|
positionStyle() {
|
||||||
|
if (!this.absolute) return {}
|
||||||
|
let w = this.width / 2,
|
||||||
|
h = 10
|
||||||
|
if (this.isDot) {
|
||||||
|
w = 5
|
||||||
|
h = 5
|
||||||
|
}
|
||||||
|
const x = `${- w + this.offset[0]}px`
|
||||||
|
const y = `${- h + this.offset[1]}px`
|
||||||
|
|
||||||
|
const whiteList = {
|
||||||
|
rightTop: {
|
||||||
|
right: x,
|
||||||
|
top: y
|
||||||
|
},
|
||||||
|
rightBottom: {
|
||||||
|
right: x,
|
||||||
|
bottom: y
|
||||||
|
},
|
||||||
|
leftBottom: {
|
||||||
|
left: x,
|
||||||
|
bottom: y
|
||||||
|
},
|
||||||
|
leftTop: {
|
||||||
|
left: x,
|
||||||
|
top: y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const match = whiteList[this.absolute]
|
||||||
|
return match ? match : whiteList['rightTop']
|
||||||
|
},
|
||||||
|
dotStyle() {
|
||||||
|
if (!this.isDot) return {}
|
||||||
|
return {
|
||||||
|
width: '10px',
|
||||||
|
minWidth: '0',
|
||||||
|
height: '10px',
|
||||||
|
padding: '0',
|
||||||
|
borderRadius: '10px'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
displayValue() {
|
||||||
|
const {
|
||||||
|
isDot,
|
||||||
|
text,
|
||||||
|
maxNum
|
||||||
|
} = this
|
||||||
|
return isDot ? '' : (Number(text) > maxNum ? `${maxNum}+` : text)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick() {
|
||||||
|
this.$emit('click');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" >
|
||||||
|
$uni-primary: #2979ff !default;
|
||||||
|
$uni-success: #4cd964 !default;
|
||||||
|
$uni-warning: #f0ad4e !default;
|
||||||
|
$uni-error: #dd524d !default;
|
||||||
|
$uni-info: #909399 !default;
|
||||||
|
|
||||||
|
|
||||||
|
$bage-size: 12px;
|
||||||
|
$bage-small: scale(0.8);
|
||||||
|
|
||||||
|
.uni-badge--x {
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
// align-self: flex-start;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: inline-block;
|
||||||
|
/* #endif */
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-badge--absolute {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-badge--small {
|
||||||
|
transform: $bage-small;
|
||||||
|
transform-origin: center center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-badge {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
overflow: hidden;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-feature-settings: "tnum";
|
||||||
|
min-width: 20px;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: row;
|
||||||
|
height: 20px;
|
||||||
|
padding: 0 4px;
|
||||||
|
line-height: 18px;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 100px;
|
||||||
|
background-color: $uni-info;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 1px solid #fff;
|
||||||
|
text-align: center;
|
||||||
|
font-family: 'Helvetica Neue', Helvetica, sans-serif;
|
||||||
|
font-size: $bage-size;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
z-index: 999;
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
&--info {
|
||||||
|
color: #fff;
|
||||||
|
background-color: $uni-info;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--primary {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--success {
|
||||||
|
background-color: $uni-success;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--warning {
|
||||||
|
background-color: $uni-warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--error {
|
||||||
|
background-color: $uni-error;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--inverted {
|
||||||
|
padding: 0 5px 0 0;
|
||||||
|
color: $uni-info;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--info-inverted {
|
||||||
|
color: $uni-info;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--primary-inverted {
|
||||||
|
color: $uni-primary;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--success-inverted {
|
||||||
|
color: $uni-success;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--warning-inverted {
|
||||||
|
color: $uni-warning;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--error-inverted {
|
||||||
|
color: $uni-error;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
126
node_modules/@dcloudio/uni-ui/lib/uni-breadcrumb-item/uni-breadcrumb-item.vue
generated
vendored
Normal file
126
node_modules/@dcloudio/uni-ui/lib/uni-breadcrumb-item/uni-breadcrumb-item.vue
generated
vendored
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-breadcrumb-item">
|
||||||
|
<view :class="{
|
||||||
|
'uni-breadcrumb-item--slot': true,
|
||||||
|
'uni-breadcrumb-item--slot-link': to && currentPage !== to
|
||||||
|
}" @click="navTo">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
<i v-if="separatorClass" class="uni-breadcrumb-item--separator" :class="separatorClass" />
|
||||||
|
<text v-else class="uni-breadcrumb-item--separator">{{ separator }}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* BreadcrumbItem 面包屑导航子组件
|
||||||
|
* @property {String/Object} to 路由跳转页面路径/对象
|
||||||
|
* @property {Boolean} replace 在使用 to 进行路由跳转时,启用 replace 将不会向 history 添加新记录(仅 h5 支持)
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
currentPage: ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
to: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
replace:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
inject: {
|
||||||
|
uniBreadcrumb: {
|
||||||
|
from: "uniBreadcrumb",
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created(){
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
const page = pages[pages.length-1]
|
||||||
|
|
||||||
|
if(page){
|
||||||
|
this.currentPage = `/${page.route}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
separator() {
|
||||||
|
return this.uniBreadcrumb.separator
|
||||||
|
},
|
||||||
|
separatorClass() {
|
||||||
|
return this.uniBreadcrumb.separatorClass
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
navTo() {
|
||||||
|
const { to } = this
|
||||||
|
|
||||||
|
if (!to || this.currentPage === to){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.replace){
|
||||||
|
uni.redirectTo({
|
||||||
|
url:to
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
uni.navigateTo({
|
||||||
|
url:to
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-primary: #2979ff !default;
|
||||||
|
$uni-base-color: #6a6a6a !default;
|
||||||
|
$uni-main-color: #3a3a3a !default;
|
||||||
|
.uni-breadcrumb-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 14px;
|
||||||
|
|
||||||
|
&--slot {
|
||||||
|
color: $uni-base-color;
|
||||||
|
padding: 0 10px;
|
||||||
|
|
||||||
|
&-link {
|
||||||
|
color: $uni-main-color;
|
||||||
|
font-weight: bold;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--separator {
|
||||||
|
font-size: 12px;
|
||||||
|
color: $uni-base-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:first-child &--slot {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:last-child &--separator {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
46
node_modules/@dcloudio/uni-ui/lib/uni-breadcrumb/uni-breadcrumb.vue
generated
vendored
Normal file
46
node_modules/@dcloudio/uni-ui/lib/uni-breadcrumb/uni-breadcrumb.vue
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-breadcrumb">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Breadcrumb 面包屑导航父组件
|
||||||
|
* @description 显示当前页面的路径,快速返回之前的任意页面
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=xxx
|
||||||
|
* @property {String} separator 分隔符,默认为斜杠'/'
|
||||||
|
* @property {String} separatorClass 图标分隔符 class
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
separator: {
|
||||||
|
type: String,
|
||||||
|
default: '/'
|
||||||
|
},
|
||||||
|
separatorClass: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
uniBreadcrumb: this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-breadcrumb {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
544
node_modules/@dcloudio/uni-ui/lib/uni-calendar/calendar.js
generated
vendored
Normal file
544
node_modules/@dcloudio/uni-ui/lib/uni-calendar/calendar.js
generated
vendored
Normal file
@ -0,0 +1,544 @@
|
|||||||
|
/**
|
||||||
|
* @1900-2100区间内的公历、农历互转
|
||||||
|
* @charset UTF-8
|
||||||
|
* @github https://github.com/jjonline/calendar.js
|
||||||
|
* @Author Jea杨(JJonline@JJonline.Cn)
|
||||||
|
* @Time 2014-7-21
|
||||||
|
* @Time 2016-8-13 Fixed 2033hex、Attribution Annals
|
||||||
|
* @Time 2016-9-25 Fixed lunar LeapMonth Param Bug
|
||||||
|
* @Time 2017-7-24 Fixed use getTerm Func Param Error.use solar year,NOT lunar year
|
||||||
|
* @Version 1.0.3
|
||||||
|
* @公历转农历:calendar.solar2lunar(1987,11,01); //[you can ignore params of prefix 0]
|
||||||
|
* @农历转公历:calendar.lunar2solar(1987,09,10); //[you can ignore params of prefix 0]
|
||||||
|
*/
|
||||||
|
/* eslint-disable */
|
||||||
|
var calendar = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 农历1900-2100的润大小信息表
|
||||||
|
* @Array Of Property
|
||||||
|
* @return Hex
|
||||||
|
*/
|
||||||
|
lunarInfo: [0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, // 1900-1909
|
||||||
|
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, // 1910-1919
|
||||||
|
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, // 1920-1929
|
||||||
|
0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, // 1930-1939
|
||||||
|
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, // 1940-1949
|
||||||
|
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, // 1950-1959
|
||||||
|
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, // 1960-1969
|
||||||
|
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, // 1970-1979
|
||||||
|
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, // 1980-1989
|
||||||
|
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, // 1990-1999
|
||||||
|
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, // 2000-2009
|
||||||
|
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, // 2010-2019
|
||||||
|
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, // 2020-2029
|
||||||
|
0x05aa0, 0x076a3, 0x096d0, 0x04afb, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, // 2030-2039
|
||||||
|
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, // 2040-2049
|
||||||
|
/** Add By JJonline@JJonline.Cn**/
|
||||||
|
0x14b63, 0x09370, 0x049f8, 0x04970, 0x064b0, 0x168a6, 0x0ea50, 0x06b20, 0x1a6c4, 0x0aae0, // 2050-2059
|
||||||
|
0x0a2e0, 0x0d2e3, 0x0c960, 0x0d557, 0x0d4a0, 0x0da50, 0x05d55, 0x056a0, 0x0a6d0, 0x055d4, // 2060-2069
|
||||||
|
0x052d0, 0x0a9b8, 0x0a950, 0x0b4a0, 0x0b6a6, 0x0ad50, 0x055a0, 0x0aba4, 0x0a5b0, 0x052b0, // 2070-2079
|
||||||
|
0x0b273, 0x06930, 0x07337, 0x06aa0, 0x0ad50, 0x14b55, 0x04b60, 0x0a570, 0x054e4, 0x0d160, // 2080-2089
|
||||||
|
0x0e968, 0x0d520, 0x0daa0, 0x16aa6, 0x056d0, 0x04ae0, 0x0a9d4, 0x0a2d0, 0x0d150, 0x0f252, // 2090-2099
|
||||||
|
0x0d520], // 2100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公历每个月份的天数普通表
|
||||||
|
* @Array Of Property
|
||||||
|
* @return Number
|
||||||
|
*/
|
||||||
|
solarMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天干地支之天干速查表
|
||||||
|
* @Array Of Property trans["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"]
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
Gan: ['\u7532', '\u4e59', '\u4e19', '\u4e01', '\u620a', '\u5df1', '\u5e9a', '\u8f9b', '\u58ec', '\u7678'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天干地支之地支速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"]
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
Zhi: ['\u5b50', '\u4e11', '\u5bc5', '\u536f', '\u8fb0', '\u5df3', '\u5348', '\u672a', '\u7533', '\u9149', '\u620c', '\u4ea5'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天干地支之地支速查表<=>生肖
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
Animals: ['\u9f20', '\u725b', '\u864e', '\u5154', '\u9f99', '\u86c7', '\u9a6c', '\u7f8a', '\u7334', '\u9e21', '\u72d7', '\u732a'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 24节气速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"]
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
solarTerm: ['\u5c0f\u5bd2', '\u5927\u5bd2', '\u7acb\u6625', '\u96e8\u6c34', '\u60ca\u86f0', '\u6625\u5206', '\u6e05\u660e', '\u8c37\u96e8', '\u7acb\u590f', '\u5c0f\u6ee1', '\u8292\u79cd', '\u590f\u81f3', '\u5c0f\u6691', '\u5927\u6691', '\u7acb\u79cb', '\u5904\u6691', '\u767d\u9732', '\u79cb\u5206', '\u5bd2\u9732', '\u971c\u964d', '\u7acb\u51ac', '\u5c0f\u96ea', '\u5927\u96ea', '\u51ac\u81f3'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1900-2100各年的24节气日期速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @return 0x string For splice
|
||||||
|
*/
|
||||||
|
sTermInfo: ['9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf97c3598082c95f8c965cc920f',
|
||||||
|
'97bd0b06bdb0722c965ce1cfcc920f', 'b027097bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||||
|
'97bcf97c359801ec95f8c965cc920f', '97bd0b06bdb0722c965ce1cfcc920f', 'b027097bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f', '97bd0b06bdb0722c965ce1cfcc920f',
|
||||||
|
'b027097bd097c36b0b6fc9274c91aa', '9778397bd19801ec9210c965cc920e', '97b6b97bd19801ec95f8c965cc920f',
|
||||||
|
'97bd09801d98082c95f8e1cfcc920f', '97bd097bd097c36b0b6fc9210c8dc2', '9778397bd197c36c9210c9274c91aa',
|
||||||
|
'97b6b97bd19801ec95f8c965cc920e', '97bd09801d98082c95f8e1cfcc920f', '97bd097bd097c36b0b6fc9210c8dc2',
|
||||||
|
'9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec95f8c965cc920e', '97bcf97c3598082c95f8e1cfcc920f',
|
||||||
|
'97bd097bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||||
|
'97bcf97c3598082c95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b97bd19801ec9210c965cc920e', '97bcf97c3598082c95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f',
|
||||||
|
'97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||||
|
'97bcf97c359801ec95f8c965cc920f', '97bd097bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b97bd19801ec9210c965cc920e', '97bcf97c359801ec95f8c965cc920f', '97bd097bd07f595b0b6fc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9210c8dc2', '9778397bd19801ec9210c9274c920e', '97b6b97bd19801ec95f8c965cc920f',
|
||||||
|
'97bd07f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c920e',
|
||||||
|
'97b6b97bd19801ec95f8c965cc920f', '97bd07f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2',
|
||||||
|
'9778397bd097c36c9210c9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bd07f1487f595b0b0bc920fb0722',
|
||||||
|
'7f0e397bd097c36b0b6fc9210c8dc2', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||||
|
'97bcf7f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b97bd19801ec9210c965cc920e', '97bcf7f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e', '97bcf7f1487f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b97bd19801ec9210c965cc920e',
|
||||||
|
'97bcf7f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b97bd19801ec9210c9274c920e', '97bcf7f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9210c91aa', '97b6b97bd197c36c9210c9274c920e', '97bcf7f0e47f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9210c8dc2', '9778397bd097c36c9210c9274c920e',
|
||||||
|
'97b6b7f0e47f531b0723b0b6fb0722', '7f0e37f5307f595b0b0bc920fb0722', '7f0e397bd097c36b0b6fc9210c8dc2',
|
||||||
|
'9778397bd097c36b0b70c9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721', '7f0e37f1487f595b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd097c35b0b6fc9210c8dc2', '9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e27f1487f595b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd097c35b0b6fc920fb0722', '9778397bd097c36b0b6fc9274c91aa', '97b6b7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9274c91aa',
|
||||||
|
'97b6b7f0e47f531b0723b0787b0721', '7f0e27f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||||
|
'9778397bd097c36b0b6fc9210c91aa', '97b6b7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||||
|
'7f0e397bd07f595b0b0bc920fb0722', '9778397bd097c36b0b6fc9210c8dc2', '977837f0e37f149b0723b0787b0721',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f5307f595b0b0bc920fb0722', '7f0e397bd097c35b0b6fc9210c8dc2',
|
||||||
|
'977837f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e37f1487f595b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd097c35b0b6fc9210c8dc2', '977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722', '977837f0e37f14998082b0787b06bd',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd097c35b0b6fc920fb0722',
|
||||||
|
'977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14998082b0787b06bd',
|
||||||
|
'7f07e7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0b0bb0b6fb0722', '7f0e397bd07f595b0b0bc920fb0722',
|
||||||
|
'977837f0e37f14998082b0723b06bd', '7f07e7f0e37f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||||
|
'7f0e397bd07f595b0b0bc920fb0722', '977837f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b0721',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f1487f595b0b0bb0b6fb0722', '7f0e37f0e37f14898082b0723b02d5',
|
||||||
|
'7ec967f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0722', '7f0e37f1487f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e37f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e37f1487f531b0b0bb0b6fb0722', '7f0e37f0e37f14898082b072297c35', '7ec967f0e37f14998082b0787b06bd',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722', '7f0e37f0e37f14898082b072297c35',
|
||||||
|
'7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722',
|
||||||
|
'7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f149b0723b0787b0721',
|
||||||
|
'7f0e27f1487f531b0b0bb0b6fb0722', '7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14998082b0723b06bd',
|
||||||
|
'7f07e7f0e47f149b0723b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722', '7f0e37f0e366aa89801eb072297c35',
|
||||||
|
'7ec967f0e37f14998082b0723b06bd', '7f07e7f0e37f14998083b0787b0721', '7f0e27f0e47f531b0723b0b6fb0722',
|
||||||
|
'7f0e37f0e366aa89801eb072297c35', '7ec967f0e37f14898082b0723b02d5', '7f07e7f0e37f14998082b0787b0721',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0722', '7f0e36665b66aa89801e9808297c35', '665f67f0e37f14898082b0723b02d5',
|
||||||
|
'7ec967f0e37f14998082b0787b0721', '7f07e7f0e47f531b0723b0b6fb0722', '7f0e36665b66a449801e9808297c35',
|
||||||
|
'665f67f0e37f14898082b0723b02d5', '7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721',
|
||||||
|
'7f0e36665b66a449801e9808297c35', '665f67f0e37f14898082b072297c35', '7ec967f0e37f14998082b0787b06bd',
|
||||||
|
'7f07e7f0e47f531b0723b0b6fb0721', '7f0e26665b66a449801e9808297c35', '665f67f0e37f1489801eb072297c35',
|
||||||
|
'7ec967f0e37f14998082b0787b06bd', '7f07e7f0e47f531b0723b0b6fb0721', '7f0e27f1487f531b0b0bb0b6fb0722'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数字转中文速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans ['日','一','二','三','四','五','六','七','八','九','十']
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
nStr1: ['\u65e5', '\u4e00', '\u4e8c', '\u4e09', '\u56db', '\u4e94', '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期转农历称呼速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans ['初','十','廿','卅']
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
nStr2: ['\u521d', '\u5341', '\u5eff', '\u5345'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 月份转农历称呼速查表
|
||||||
|
* @Array Of Property
|
||||||
|
* @trans ['正','一','二','三','四','五','六','七','八','九','十','冬','腊']
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
nStr3: ['\u6b63', '\u4e8c', '\u4e09', '\u56db', '\u4e94', '\u516d', '\u4e03', '\u516b', '\u4e5d', '\u5341', '\u51ac', '\u814a'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回农历y年一整年的总天数
|
||||||
|
* @param lunar Year
|
||||||
|
* @return Number
|
||||||
|
* @eg:var count = calendar.lYearDays(1987) ;//count=387
|
||||||
|
*/
|
||||||
|
lYearDays: function (y) {
|
||||||
|
var i; var sum = 348
|
||||||
|
for (i = 0x8000; i > 0x8; i >>= 1) { sum += (this.lunarInfo[y - 1900] & i) ? 1 : 0 }
|
||||||
|
return (sum + this.leapDays(y))
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回农历y年闰月是哪个月;若y年没有闰月 则返回0
|
||||||
|
* @param lunar Year
|
||||||
|
* @return Number (0-12)
|
||||||
|
* @eg:var leapMonth = calendar.leapMonth(1987) ;//leapMonth=6
|
||||||
|
*/
|
||||||
|
leapMonth: function (y) { // 闰字编码 \u95f0
|
||||||
|
return (this.lunarInfo[y - 1900] & 0xf)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回农历y年闰月的天数 若该年没有闰月则返回0
|
||||||
|
* @param lunar Year
|
||||||
|
* @return Number (0、29、30)
|
||||||
|
* @eg:var leapMonthDay = calendar.leapDays(1987) ;//leapMonthDay=29
|
||||||
|
*/
|
||||||
|
leapDays: function (y) {
|
||||||
|
if (this.leapMonth(y)) {
|
||||||
|
return ((this.lunarInfo[y - 1900] & 0x10000) ? 30 : 29)
|
||||||
|
}
|
||||||
|
return (0)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回农历y年m月(非闰月)的总天数,计算m为闰月时的天数请使用leapDays方法
|
||||||
|
* @param lunar Year
|
||||||
|
* @return Number (-1、29、30)
|
||||||
|
* @eg:var MonthDay = calendar.monthDays(1987,9) ;//MonthDay=29
|
||||||
|
*/
|
||||||
|
monthDays: function (y, m) {
|
||||||
|
if (m > 12 || m < 1) { return -1 }// 月份参数从1至12,参数错误返回-1
|
||||||
|
return ((this.lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回公历(!)y年m月的天数
|
||||||
|
* @param solar Year
|
||||||
|
* @return Number (-1、28、29、30、31)
|
||||||
|
* @eg:var solarMonthDay = calendar.leapDays(1987) ;//solarMonthDay=30
|
||||||
|
*/
|
||||||
|
solarDays: function (y, m) {
|
||||||
|
if (m > 12 || m < 1) { return -1 } // 若参数错误 返回-1
|
||||||
|
var ms = m - 1
|
||||||
|
if (ms == 1) { // 2月份的闰平规律测算后确认返回28或29
|
||||||
|
return (((y % 4 == 0) && (y % 100 != 0) || (y % 400 == 0)) ? 29 : 28)
|
||||||
|
} else {
|
||||||
|
return (this.solarMonth[ms])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 农历年份转换为干支纪年
|
||||||
|
* @param lYear 农历年的年份数
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
toGanZhiYear: function (lYear) {
|
||||||
|
var ganKey = (lYear - 3) % 10
|
||||||
|
var zhiKey = (lYear - 3) % 12
|
||||||
|
if (ganKey == 0) ganKey = 10// 如果余数为0则为最后一个天干
|
||||||
|
if (zhiKey == 0) zhiKey = 12// 如果余数为0则为最后一个地支
|
||||||
|
return this.Gan[ganKey - 1] + this.Zhi[zhiKey - 1]
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公历月、日判断所属星座
|
||||||
|
* @param cMonth [description]
|
||||||
|
* @param cDay [description]
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
toAstro: function (cMonth, cDay) {
|
||||||
|
var s = '\u9b54\u7faf\u6c34\u74f6\u53cc\u9c7c\u767d\u7f8a\u91d1\u725b\u53cc\u5b50\u5de8\u87f9\u72ee\u5b50\u5904\u5973\u5929\u79e4\u5929\u874e\u5c04\u624b\u9b54\u7faf'
|
||||||
|
var arr = [20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]
|
||||||
|
return s.substr(cMonth * 2 - (cDay < arr[cMonth - 1] ? 2 : 0), 2) + '\u5ea7'// 座
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入offset偏移量返回干支
|
||||||
|
* @param offset 相对甲子的偏移量
|
||||||
|
* @return Cn string
|
||||||
|
*/
|
||||||
|
toGanZhi: function (offset) {
|
||||||
|
return this.Gan[offset % 10] + this.Zhi[offset % 12]
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入公历(!)y年获得该年第n个节气的公历日期
|
||||||
|
* @param y公历年(1900-2100);n二十四节气中的第几个节气(1~24);从n=1(小寒)算起
|
||||||
|
* @return day Number
|
||||||
|
* @eg:var _24 = calendar.getTerm(1987,3) ;//_24=4;意即1987年2月4日立春
|
||||||
|
*/
|
||||||
|
getTerm: function (y, n) {
|
||||||
|
if (y < 1900 || y > 2100) { return -1 }
|
||||||
|
if (n < 1 || n > 24) { return -1 }
|
||||||
|
var _table = this.sTermInfo[y - 1900]
|
||||||
|
var _info = [
|
||||||
|
parseInt('0x' + _table.substr(0, 5)).toString(),
|
||||||
|
parseInt('0x' + _table.substr(5, 5)).toString(),
|
||||||
|
parseInt('0x' + _table.substr(10, 5)).toString(),
|
||||||
|
parseInt('0x' + _table.substr(15, 5)).toString(),
|
||||||
|
parseInt('0x' + _table.substr(20, 5)).toString(),
|
||||||
|
parseInt('0x' + _table.substr(25, 5)).toString()
|
||||||
|
]
|
||||||
|
var _calday = [
|
||||||
|
_info[0].substr(0, 1),
|
||||||
|
_info[0].substr(1, 2),
|
||||||
|
_info[0].substr(3, 1),
|
||||||
|
_info[0].substr(4, 2),
|
||||||
|
|
||||||
|
_info[1].substr(0, 1),
|
||||||
|
_info[1].substr(1, 2),
|
||||||
|
_info[1].substr(3, 1),
|
||||||
|
_info[1].substr(4, 2),
|
||||||
|
|
||||||
|
_info[2].substr(0, 1),
|
||||||
|
_info[2].substr(1, 2),
|
||||||
|
_info[2].substr(3, 1),
|
||||||
|
_info[2].substr(4, 2),
|
||||||
|
|
||||||
|
_info[3].substr(0, 1),
|
||||||
|
_info[3].substr(1, 2),
|
||||||
|
_info[3].substr(3, 1),
|
||||||
|
_info[3].substr(4, 2),
|
||||||
|
|
||||||
|
_info[4].substr(0, 1),
|
||||||
|
_info[4].substr(1, 2),
|
||||||
|
_info[4].substr(3, 1),
|
||||||
|
_info[4].substr(4, 2),
|
||||||
|
|
||||||
|
_info[5].substr(0, 1),
|
||||||
|
_info[5].substr(1, 2),
|
||||||
|
_info[5].substr(3, 1),
|
||||||
|
_info[5].substr(4, 2)
|
||||||
|
]
|
||||||
|
return parseInt(_calday[n - 1])
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入农历数字月份返回汉语通俗表示法
|
||||||
|
* @param lunar month
|
||||||
|
* @return Cn string
|
||||||
|
* @eg:var cnMonth = calendar.toChinaMonth(12) ;//cnMonth='腊月'
|
||||||
|
*/
|
||||||
|
toChinaMonth: function (m) { // 月 => \u6708
|
||||||
|
if (m > 12 || m < 1) { return -1 } // 若参数错误 返回-1
|
||||||
|
var s = this.nStr3[m - 1]
|
||||||
|
s += '\u6708'// 加上月字
|
||||||
|
return s
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入农历日期数字返回汉字表示法
|
||||||
|
* @param lunar day
|
||||||
|
* @return Cn string
|
||||||
|
* @eg:var cnDay = calendar.toChinaDay(21) ;//cnMonth='廿一'
|
||||||
|
*/
|
||||||
|
toChinaDay: function (d) { // 日 => \u65e5
|
||||||
|
var s
|
||||||
|
switch (d) {
|
||||||
|
case 10:
|
||||||
|
s = '\u521d\u5341'; break
|
||||||
|
case 20:
|
||||||
|
s = '\u4e8c\u5341'; break
|
||||||
|
case 30:
|
||||||
|
s = '\u4e09\u5341'; break
|
||||||
|
default :
|
||||||
|
s = this.nStr2[Math.floor(d / 10)]
|
||||||
|
s += this.nStr1[d % 10]
|
||||||
|
}
|
||||||
|
return (s)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 年份转生肖[!仅能大致转换] => 精确划分生肖分界线是“立春”
|
||||||
|
* @param y year
|
||||||
|
* @return Cn string
|
||||||
|
* @eg:var animal = calendar.getAnimal(1987) ;//animal='兔'
|
||||||
|
*/
|
||||||
|
getAnimal: function (y) {
|
||||||
|
return this.Animals[(y - 4) % 12]
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入阳历年月日获得详细的公历、农历object信息 <=>JSON
|
||||||
|
* @param y solar year
|
||||||
|
* @param m solar month
|
||||||
|
* @param d solar day
|
||||||
|
* @return JSON object
|
||||||
|
* @eg:console.log(calendar.solar2lunar(1987,11,01));
|
||||||
|
*/
|
||||||
|
solar2lunar: function (y, m, d) { // 参数区间1900.1.31~2100.12.31
|
||||||
|
// 年份限定、上限
|
||||||
|
if (y < 1900 || y > 2100) {
|
||||||
|
return -1// undefined转换为数字变为NaN
|
||||||
|
}
|
||||||
|
// 公历传参最下限
|
||||||
|
if (y == 1900 && m == 1 && d < 31) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
// 未传参 获得当天
|
||||||
|
if (!y) {
|
||||||
|
var objDate = new Date()
|
||||||
|
} else {
|
||||||
|
var objDate = new Date(y, parseInt(m) - 1, d)
|
||||||
|
}
|
||||||
|
var i; var leap = 0; var temp = 0
|
||||||
|
// 修正ymd参数
|
||||||
|
var y = objDate.getFullYear()
|
||||||
|
var m = objDate.getMonth() + 1
|
||||||
|
var d = objDate.getDate()
|
||||||
|
var offset = (Date.UTC(objDate.getFullYear(), objDate.getMonth(), objDate.getDate()) - Date.UTC(1900, 0, 31)) / 86400000
|
||||||
|
for (i = 1900; i < 2101 && offset > 0; i++) {
|
||||||
|
temp = this.lYearDays(i)
|
||||||
|
offset -= temp
|
||||||
|
}
|
||||||
|
if (offset < 0) {
|
||||||
|
offset += temp; i--
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否今天
|
||||||
|
var isTodayObj = new Date()
|
||||||
|
var isToday = false
|
||||||
|
if (isTodayObj.getFullYear() == y && isTodayObj.getMonth() + 1 == m && isTodayObj.getDate() == d) {
|
||||||
|
isToday = true
|
||||||
|
}
|
||||||
|
// 星期几
|
||||||
|
var nWeek = objDate.getDay()
|
||||||
|
var cWeek = this.nStr1[nWeek]
|
||||||
|
// 数字表示周几顺应天朝周一开始的惯例
|
||||||
|
if (nWeek == 0) {
|
||||||
|
nWeek = 7
|
||||||
|
}
|
||||||
|
// 农历年
|
||||||
|
var year = i
|
||||||
|
var leap = this.leapMonth(i) // 闰哪个月
|
||||||
|
var isLeap = false
|
||||||
|
|
||||||
|
// 效验闰月
|
||||||
|
for (i = 1; i < 13 && offset > 0; i++) {
|
||||||
|
// 闰月
|
||||||
|
if (leap > 0 && i == (leap + 1) && isLeap == false) {
|
||||||
|
--i
|
||||||
|
isLeap = true; temp = this.leapDays(year) // 计算农历闰月天数
|
||||||
|
} else {
|
||||||
|
temp = this.monthDays(year, i)// 计算农历普通月天数
|
||||||
|
}
|
||||||
|
// 解除闰月
|
||||||
|
if (isLeap == true && i == (leap + 1)) { isLeap = false }
|
||||||
|
offset -= temp
|
||||||
|
}
|
||||||
|
// 闰月导致数组下标重叠取反
|
||||||
|
if (offset == 0 && leap > 0 && i == leap + 1) {
|
||||||
|
if (isLeap) {
|
||||||
|
isLeap = false
|
||||||
|
} else {
|
||||||
|
isLeap = true; --i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (offset < 0) {
|
||||||
|
offset += temp; --i
|
||||||
|
}
|
||||||
|
// 农历月
|
||||||
|
var month = i
|
||||||
|
// 农历日
|
||||||
|
var day = offset + 1
|
||||||
|
// 天干地支处理
|
||||||
|
var sm = m - 1
|
||||||
|
var gzY = this.toGanZhiYear(year)
|
||||||
|
|
||||||
|
// 当月的两个节气
|
||||||
|
// bugfix-2017-7-24 11:03:38 use lunar Year Param `y` Not `year`
|
||||||
|
var firstNode = this.getTerm(y, (m * 2 - 1))// 返回当月「节」为几日开始
|
||||||
|
var secondNode = this.getTerm(y, (m * 2))// 返回当月「节」为几日开始
|
||||||
|
|
||||||
|
// 依据12节气修正干支月
|
||||||
|
var gzM = this.toGanZhi((y - 1900) * 12 + m + 11)
|
||||||
|
if (d >= firstNode) {
|
||||||
|
gzM = this.toGanZhi((y - 1900) * 12 + m + 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 传入的日期的节气与否
|
||||||
|
var isTerm = false
|
||||||
|
var Term = null
|
||||||
|
if (firstNode == d) {
|
||||||
|
isTerm = true
|
||||||
|
Term = this.solarTerm[m * 2 - 2]
|
||||||
|
}
|
||||||
|
if (secondNode == d) {
|
||||||
|
isTerm = true
|
||||||
|
Term = this.solarTerm[m * 2 - 1]
|
||||||
|
}
|
||||||
|
// 日柱 当月一日与 1900/1/1 相差天数
|
||||||
|
var dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10
|
||||||
|
var gzD = this.toGanZhi(dayCyclical + d - 1)
|
||||||
|
// 该日期所属的星座
|
||||||
|
var astro = this.toAstro(m, d)
|
||||||
|
|
||||||
|
return { 'lYear': year, 'lMonth': month, 'lDay': day, 'Animal': this.getAnimal(year), 'IMonthCn': (isLeap ? '\u95f0' : '') + this.toChinaMonth(month), 'IDayCn': this.toChinaDay(day), 'cYear': y, 'cMonth': m, 'cDay': d, 'gzYear': gzY, 'gzMonth': gzM, 'gzDay': gzD, 'isToday': isToday, 'isLeap': isLeap, 'nWeek': nWeek, 'ncWeek': '\u661f\u671f' + cWeek, 'isTerm': isTerm, 'Term': Term, 'astro': astro }
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入农历年月日以及传入的月份是否闰月获得详细的公历、农历object信息 <=>JSON
|
||||||
|
* @param y lunar year
|
||||||
|
* @param m lunar month
|
||||||
|
* @param d lunar day
|
||||||
|
* @param isLeapMonth lunar month is leap or not.[如果是农历闰月第四个参数赋值true即可]
|
||||||
|
* @return JSON object
|
||||||
|
* @eg:console.log(calendar.lunar2solar(1987,9,10));
|
||||||
|
*/
|
||||||
|
lunar2solar: function (y, m, d, isLeapMonth) { // 参数区间1900.1.31~2100.12.1
|
||||||
|
var isLeapMonth = !!isLeapMonth
|
||||||
|
var leapOffset = 0
|
||||||
|
var leapMonth = this.leapMonth(y)
|
||||||
|
var leapDay = this.leapDays(y)
|
||||||
|
if (isLeapMonth && (leapMonth != m)) { return -1 }// 传参要求计算该闰月公历 但该年得出的闰月与传参的月份并不同
|
||||||
|
if (y == 2100 && m == 12 && d > 1 || y == 1900 && m == 1 && d < 31) { return -1 }// 超出了最大极限值
|
||||||
|
var day = this.monthDays(y, m)
|
||||||
|
var _day = day
|
||||||
|
// bugFix 2016-9-25
|
||||||
|
// if month is leap, _day use leapDays method
|
||||||
|
if (isLeapMonth) {
|
||||||
|
_day = this.leapDays(y, m)
|
||||||
|
}
|
||||||
|
if (y < 1900 || y > 2100 || d > _day) { return -1 }// 参数合法性效验
|
||||||
|
|
||||||
|
// 计算农历的时间差
|
||||||
|
var offset = 0
|
||||||
|
for (var i = 1900; i < y; i++) {
|
||||||
|
offset += this.lYearDays(i)
|
||||||
|
}
|
||||||
|
var leap = 0; var isAdd = false
|
||||||
|
for (var i = 1; i < m; i++) {
|
||||||
|
leap = this.leapMonth(y)
|
||||||
|
if (!isAdd) { // 处理闰月
|
||||||
|
if (leap <= i && leap > 0) {
|
||||||
|
offset += this.leapDays(y); isAdd = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
offset += this.monthDays(y, i)
|
||||||
|
}
|
||||||
|
// 转换闰月农历 需补充该年闰月的前一个月的时差
|
||||||
|
if (isLeapMonth) { offset += day }
|
||||||
|
// 1900年农历正月一日的公历时间为1900年1月30日0时0分0秒(该时间也是本农历的最开始起始点)
|
||||||
|
var stmap = Date.UTC(1900, 1, 30, 0, 0, 0)
|
||||||
|
var calObj = new Date((offset + d - 31) * 86400000 + stmap)
|
||||||
|
var cY = calObj.getUTCFullYear()
|
||||||
|
var cM = calObj.getUTCMonth() + 1
|
||||||
|
var cD = calObj.getUTCDate()
|
||||||
|
|
||||||
|
return this.solar2lunar(cY, cM, cD)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default calendar
|
||||||
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/en.json
generated
vendored
Normal file
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/en.json
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"uni-calender.ok": "ok",
|
||||||
|
"uni-calender.cancel": "cancel",
|
||||||
|
"uni-calender.today": "today",
|
||||||
|
"uni-calender.MON": "MON",
|
||||||
|
"uni-calender.TUE": "TUE",
|
||||||
|
"uni-calender.WED": "WED",
|
||||||
|
"uni-calender.THU": "THU",
|
||||||
|
"uni-calender.FRI": "FRI",
|
||||||
|
"uni-calender.SAT": "SAT",
|
||||||
|
"uni-calender.SUN": "SUN"
|
||||||
|
}
|
||||||
8
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/index.js
generated
vendored
Normal file
8
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import en from './en.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
||||||
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/zh-Hans.json
generated
vendored
Normal file
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/zh-Hans.json
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"uni-calender.ok": "确定",
|
||||||
|
"uni-calender.cancel": "取消",
|
||||||
|
"uni-calender.today": "今日",
|
||||||
|
"uni-calender.SUN": "日",
|
||||||
|
"uni-calender.MON": "一",
|
||||||
|
"uni-calender.TUE": "二",
|
||||||
|
"uni-calender.WED": "三",
|
||||||
|
"uni-calender.THU": "四",
|
||||||
|
"uni-calender.FRI": "五",
|
||||||
|
"uni-calender.SAT": "六"
|
||||||
|
}
|
||||||
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/zh-Hant.json
generated
vendored
Normal file
12
node_modules/@dcloudio/uni-ui/lib/uni-calendar/i18n/zh-Hant.json
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"uni-calender.ok": "確定",
|
||||||
|
"uni-calender.cancel": "取消",
|
||||||
|
"uni-calender.today": "今日",
|
||||||
|
"uni-calender.SUN": "日",
|
||||||
|
"uni-calender.MON": "一",
|
||||||
|
"uni-calender.TUE": "二",
|
||||||
|
"uni-calender.WED": "三",
|
||||||
|
"uni-calender.THU": "四",
|
||||||
|
"uni-calender.FRI": "五",
|
||||||
|
"uni-calender.SAT": "六"
|
||||||
|
}
|
||||||
187
node_modules/@dcloudio/uni-ui/lib/uni-calendar/uni-calendar-item.vue
generated
vendored
Normal file
187
node_modules/@dcloudio/uni-ui/lib/uni-calendar/uni-calendar-item.vue
generated
vendored
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-calendar-item__weeks-box" :class="{
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
|
||||||
|
'uni-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) ,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
}"
|
||||||
|
@click="choiceDate(weeks)">
|
||||||
|
<view class="uni-calendar-item__weeks-box-item">
|
||||||
|
<text v-if="selected&&weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
|
||||||
|
<text class="uni-calendar-item__weeks-box-text" :class="{
|
||||||
|
'uni-calendar-item--isDay-text': weeks.isDay,
|
||||||
|
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
|
||||||
|
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
}">{{weeks.date}}</text>
|
||||||
|
<text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uni-calendar-item__weeks-lunar-text" :class="{
|
||||||
|
'uni-calendar-item--isDay-text':weeks.isDay,
|
||||||
|
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
|
||||||
|
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
}">{{todayText}}</text>
|
||||||
|
<text v-if="lunar&&!weeks.extraInfo" class="uni-calendar-item__weeks-lunar-text" :class="{
|
||||||
|
'uni-calendar-item--isDay-text':weeks.isDay,
|
||||||
|
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
|
||||||
|
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
}">{{weeks.isDay ? todayText : (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text>
|
||||||
|
<text v-if="weeks.extraInfo&&weeks.extraInfo.info" class="uni-calendar-item__weeks-lunar-text" :class="{
|
||||||
|
'uni-calendar-item--extra':weeks.extraInfo.info,
|
||||||
|
'uni-calendar-item--isDay-text':weeks.isDay,
|
||||||
|
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
|
||||||
|
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
}">{{weeks.extraInfo.info}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { initVueI18n } from '@dcloudio/uni-i18n'
|
||||||
|
import i18nMessages from './i18n/index.js'
|
||||||
|
const { t } = initVueI18n(i18nMessages)
|
||||||
|
|
||||||
|
export default {
|
||||||
|
emits:['change'],
|
||||||
|
props: {
|
||||||
|
weeks: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
calendar: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selected: {
|
||||||
|
type: Array,
|
||||||
|
default: () => {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lunar: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
todayText() {
|
||||||
|
return t("uni-calender.today")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
choiceDate(weeks) {
|
||||||
|
this.$emit('change', weeks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$uni-font-size-base:14px;
|
||||||
|
$uni-text-color:#333;
|
||||||
|
$uni-font-size-sm:12px;
|
||||||
|
$uni-color-error: #e43d33;
|
||||||
|
$uni-opacity-disabled: 0.3;
|
||||||
|
$uni-text-color-disable:#c0c0c0;
|
||||||
|
$uni-primary: #2979ff !default;
|
||||||
|
.uni-calendar-item__weeks-box {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-text {
|
||||||
|
font-size: $uni-font-size-base;
|
||||||
|
color: $uni-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-lunar-text {
|
||||||
|
font-size: $uni-font-size-sm;
|
||||||
|
color: $uni-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-item {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100rpx;
|
||||||
|
height: 100rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-circle {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
right: 5px;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background-color: $uni-color-error;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--disable {
|
||||||
|
background-color: rgba(249, 249, 249, $uni-opacity-disabled);
|
||||||
|
color: $uni-text-color-disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--isDay-text {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--isDay {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
opacity: 0.8;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--extra {
|
||||||
|
color: $uni-color-error;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--checked {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
color: #fff;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--multiple {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
color: #fff;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
.uni-calendar-item--before-checked {
|
||||||
|
background-color: #ff5a5f;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.uni-calendar-item--after-checked {
|
||||||
|
background-color: #ff5a5f;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
567
node_modules/@dcloudio/uni-ui/lib/uni-calendar/uni-calendar.vue
generated
vendored
Normal file
567
node_modules/@dcloudio/uni-ui/lib/uni-calendar/uni-calendar.vue
generated
vendored
Normal file
@ -0,0 +1,567 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-calendar">
|
||||||
|
<view v-if="!insert&&show" class="uni-calendar__mask" :class="{'uni-calendar--mask-show':aniMaskShow}" @click="clean"></view>
|
||||||
|
<view v-if="insert || show" class="uni-calendar__content" :class="{'uni-calendar--fixed':!insert,'uni-calendar--ani-show':aniMaskShow}">
|
||||||
|
<view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top">
|
||||||
|
<view class="uni-calendar__header-btn-box" @click="close">
|
||||||
|
<text class="uni-calendar__header-text uni-calendar--fixed-width">{{cancelText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__header-btn-box" @click="confirm">
|
||||||
|
<text class="uni-calendar__header-text uni-calendar--fixed-width">{{okText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__header">
|
||||||
|
<view class="uni-calendar__header-btn-box" @click.stop="pre">
|
||||||
|
<view class="uni-calendar__header-btn uni-calendar--left"></view>
|
||||||
|
</view>
|
||||||
|
<picker mode="date" :value="date" fields="month" @change="bindDateChange">
|
||||||
|
<text class="uni-calendar__header-text">{{ (nowDate.year||'') +' / '+( nowDate.month||'')}}</text>
|
||||||
|
</picker>
|
||||||
|
<view class="uni-calendar__header-btn-box" @click.stop="next">
|
||||||
|
<view class="uni-calendar__header-btn uni-calendar--right"></view>
|
||||||
|
</view>
|
||||||
|
<text class="uni-calendar__backtoday" @click="backToday">{{todayText}}</text>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__box">
|
||||||
|
<view v-if="showMonth" class="uni-calendar__box-bg">
|
||||||
|
<text class="uni-calendar__box-bg-text">{{nowDate.month}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks">
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{SUNText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{monText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{TUEText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{WEDText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{THUText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{FRIText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{SATText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
|
||||||
|
<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
|
||||||
|
<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></calendar-item>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Calendar from './util.js';
|
||||||
|
import CalendarItem from './uni-calendar-item.vue'
|
||||||
|
|
||||||
|
import { initVueI18n } from '@dcloudio/uni-i18n'
|
||||||
|
import i18nMessages from './i18n/index.js'
|
||||||
|
const { t } = initVueI18n(i18nMessages)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar 日历
|
||||||
|
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
|
||||||
|
* @property {String} date 自定义当前时间,默认为今天
|
||||||
|
* @property {Boolean} lunar 显示农历
|
||||||
|
* @property {String} startDate 日期选择范围-开始日期
|
||||||
|
* @property {String} endDate 日期选择范围-结束日期
|
||||||
|
* @property {Boolean} range 范围选择
|
||||||
|
* @property {Boolean} insert = [true|false] 插入模式,默认为false
|
||||||
|
* @value true 弹窗模式
|
||||||
|
* @value false 插入模式
|
||||||
|
* @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
|
||||||
|
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
|
||||||
|
* @property {Boolean} showMonth 是否选择月份为背景
|
||||||
|
* @event {Function} change 日期改变,`insert :ture` 时生效
|
||||||
|
* @event {Function} confirm 确认选择`insert :false` 时生效
|
||||||
|
* @event {Function} monthSwitch 切换月份时触发
|
||||||
|
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
CalendarItem
|
||||||
|
},
|
||||||
|
emits:['close','confirm','change','monthSwitch'],
|
||||||
|
props: {
|
||||||
|
date: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
selected: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lunar: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
range: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
insert: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showMonth: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
clearDate: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
show: false,
|
||||||
|
weeks: [],
|
||||||
|
calendar: {},
|
||||||
|
nowDate: '',
|
||||||
|
aniMaskShow: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed:{
|
||||||
|
/**
|
||||||
|
* for i18n
|
||||||
|
*/
|
||||||
|
|
||||||
|
okText() {
|
||||||
|
return t("uni-calender.ok")
|
||||||
|
},
|
||||||
|
cancelText() {
|
||||||
|
return t("uni-calender.cancel")
|
||||||
|
},
|
||||||
|
todayText() {
|
||||||
|
return t("uni-calender.today")
|
||||||
|
},
|
||||||
|
monText() {
|
||||||
|
return t("uni-calender.MON")
|
||||||
|
},
|
||||||
|
TUEText() {
|
||||||
|
return t("uni-calender.TUE")
|
||||||
|
},
|
||||||
|
WEDText() {
|
||||||
|
return t("uni-calender.WED")
|
||||||
|
},
|
||||||
|
THUText() {
|
||||||
|
return t("uni-calender.THU")
|
||||||
|
},
|
||||||
|
FRIText() {
|
||||||
|
return t("uni-calender.FRI")
|
||||||
|
},
|
||||||
|
SATText() {
|
||||||
|
return t("uni-calender.SAT")
|
||||||
|
},
|
||||||
|
SUNText() {
|
||||||
|
return t("uni-calender.SUN")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
date(newVal) {
|
||||||
|
// this.cale.setDate(newVal)
|
||||||
|
this.init(newVal)
|
||||||
|
},
|
||||||
|
startDate(val){
|
||||||
|
this.cale.resetSatrtDate(val)
|
||||||
|
this.cale.setDate(this.nowDate.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
},
|
||||||
|
endDate(val){
|
||||||
|
this.cale.resetEndDate(val)
|
||||||
|
this.cale.setDate(this.nowDate.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
},
|
||||||
|
selected(newVal) {
|
||||||
|
this.cale.setSelectInfo(this.nowDate.fullDate, newVal)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.cale = new Calendar({
|
||||||
|
selected: this.selected,
|
||||||
|
startDate: this.startDate,
|
||||||
|
endDate: this.endDate,
|
||||||
|
range: this.range,
|
||||||
|
})
|
||||||
|
this.init(this.date)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 取消穿透
|
||||||
|
clean() {},
|
||||||
|
bindDateChange(e) {
|
||||||
|
const value = e.detail.value + '-1'
|
||||||
|
this.setDate(value)
|
||||||
|
|
||||||
|
const { year,month } = this.cale.getDate(value)
|
||||||
|
this.$emit('monthSwitch', {
|
||||||
|
year,
|
||||||
|
month
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 初始化日期显示
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
init(date) {
|
||||||
|
this.cale.setDate(date)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.nowDate = this.calendar = this.cale.getInfo(date)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 打开日历弹窗
|
||||||
|
*/
|
||||||
|
open() {
|
||||||
|
// 弹窗模式并且清理数据
|
||||||
|
if (this.clearDate && !this.insert) {
|
||||||
|
this.cale.cleanMultipleStatus()
|
||||||
|
// this.cale.setDate(this.date)
|
||||||
|
this.init(this.date)
|
||||||
|
}
|
||||||
|
this.show = true
|
||||||
|
this.$nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.aniMaskShow = true
|
||||||
|
}, 50)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 关闭日历弹窗
|
||||||
|
*/
|
||||||
|
close() {
|
||||||
|
this.aniMaskShow = false
|
||||||
|
this.$nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.show = false
|
||||||
|
this.$emit('close')
|
||||||
|
}, 300)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 确认按钮
|
||||||
|
*/
|
||||||
|
confirm() {
|
||||||
|
this.setEmit('confirm')
|
||||||
|
this.close()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 变化触发
|
||||||
|
*/
|
||||||
|
change() {
|
||||||
|
if (!this.insert) return
|
||||||
|
this.setEmit('change')
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 选择月份触发
|
||||||
|
*/
|
||||||
|
monthSwitch() {
|
||||||
|
let {
|
||||||
|
year,
|
||||||
|
month
|
||||||
|
} = this.nowDate
|
||||||
|
this.$emit('monthSwitch', {
|
||||||
|
year,
|
||||||
|
month: Number(month)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 派发事件
|
||||||
|
* @param {Object} name
|
||||||
|
*/
|
||||||
|
setEmit(name) {
|
||||||
|
let {
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
date,
|
||||||
|
fullDate,
|
||||||
|
lunar,
|
||||||
|
extraInfo
|
||||||
|
} = this.calendar
|
||||||
|
this.$emit(name, {
|
||||||
|
range: this.cale.multipleStatus,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
date,
|
||||||
|
fulldate: fullDate,
|
||||||
|
lunar,
|
||||||
|
extraInfo: extraInfo || {}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 选择天触发
|
||||||
|
* @param {Object} weeks
|
||||||
|
*/
|
||||||
|
choiceDate(weeks) {
|
||||||
|
if (weeks.disable) return
|
||||||
|
this.calendar = weeks
|
||||||
|
// 设置多选
|
||||||
|
this.cale.setMultiple(this.calendar.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.change()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 回到今天
|
||||||
|
*/
|
||||||
|
backToday() {
|
||||||
|
const nowYearMonth = `${this.nowDate.year}-${this.nowDate.month}`
|
||||||
|
const date = this.cale.getDate(new Date())
|
||||||
|
const todayYearMonth = `${date.year}-${date.month}`
|
||||||
|
|
||||||
|
this.init(date.fullDate)
|
||||||
|
|
||||||
|
if(nowYearMonth !== todayYearMonth) {
|
||||||
|
this.monthSwitch()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.change()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 上个月
|
||||||
|
*/
|
||||||
|
pre() {
|
||||||
|
const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
|
||||||
|
this.setDate(preDate)
|
||||||
|
this.monthSwitch()
|
||||||
|
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 下个月
|
||||||
|
*/
|
||||||
|
next() {
|
||||||
|
const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate
|
||||||
|
this.setDate(nextDate)
|
||||||
|
this.monthSwitch()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 设置日期
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
setDate(date) {
|
||||||
|
this.cale.setDate(date)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.nowDate = this.cale.getInfo(date)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$uni-bg-color-mask: rgba($color: #000000, $alpha: 0.4);
|
||||||
|
$uni-border-color: #EDEDED;
|
||||||
|
$uni-text-color: #333;
|
||||||
|
$uni-bg-color-hover:#f1f1f1;
|
||||||
|
$uni-font-size-base:14px;
|
||||||
|
$uni-text-color-placeholder: #808080;
|
||||||
|
$uni-color-subtitle: #555555;
|
||||||
|
$uni-text-color-grey:#999;
|
||||||
|
.uni-calendar {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__mask {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background-color: $uni-bg-color-mask;
|
||||||
|
transition-property: opacity;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
opacity: 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
z-index: 99;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--mask-show {
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed {
|
||||||
|
position: fixed;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
bottom: 0;
|
||||||
|
/* #endif */
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
transition-property: transform;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
transform: translateY(460px);
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
bottom: calc(var(--window-bottom));
|
||||||
|
z-index: 99;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--ani-show {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__content {
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 50px;
|
||||||
|
border-bottom-color: $uni-border-color;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed-top {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-top-color: $uni-border-color;
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed-width {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__backtoday {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 25rpx;
|
||||||
|
padding: 0 5px;
|
||||||
|
padding-left: 10px;
|
||||||
|
height: 25px;
|
||||||
|
line-height: 25px;
|
||||||
|
font-size: 12px;
|
||||||
|
border-top-left-radius: 25px;
|
||||||
|
border-bottom-left-radius: 25px;
|
||||||
|
color: $uni-text-color;
|
||||||
|
background-color: $uni-bg-color-hover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-text {
|
||||||
|
text-align: center;
|
||||||
|
width: 100px;
|
||||||
|
font-size: $uni-font-size-base;
|
||||||
|
color: $uni-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-btn-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-btn {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-left-color: $uni-text-color-placeholder;
|
||||||
|
border-left-style: solid;
|
||||||
|
border-left-width: 2px;
|
||||||
|
border-top-color: $uni-color-subtitle;
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--left {
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--right {
|
||||||
|
transform: rotate(135deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-calendar__weeks {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-item {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-day {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 45px;
|
||||||
|
border-bottom-color: #F5F5F5;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-day-text {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box-bg {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box-bg-text {
|
||||||
|
font-size: 200px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: $uni-text-color-grey;
|
||||||
|
opacity: 0.1;
|
||||||
|
text-align: center;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
line-height: 1;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
360
node_modules/@dcloudio/uni-ui/lib/uni-calendar/util.js
generated
vendored
Normal file
360
node_modules/@dcloudio/uni-ui/lib/uni-calendar/util.js
generated
vendored
Normal file
@ -0,0 +1,360 @@
|
|||||||
|
import CALENDAR from './calendar.js'
|
||||||
|
|
||||||
|
class Calendar {
|
||||||
|
constructor({
|
||||||
|
date,
|
||||||
|
selected,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
range
|
||||||
|
} = {}) {
|
||||||
|
// 当前日期
|
||||||
|
this.date = this.getDate(new Date()) // 当前初入日期
|
||||||
|
// 打点信息
|
||||||
|
this.selected = selected || [];
|
||||||
|
// 范围开始
|
||||||
|
this.startDate = startDate
|
||||||
|
// 范围结束
|
||||||
|
this.endDate = endDate
|
||||||
|
this.range = range
|
||||||
|
// 多选状态
|
||||||
|
this.cleanMultipleStatus()
|
||||||
|
// 每周日期
|
||||||
|
this.weeks = {}
|
||||||
|
// this._getWeek(this.date.fullDate)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置日期
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
setDate(date) {
|
||||||
|
this.selectDate = this.getDate(date)
|
||||||
|
this._getWeek(this.selectDate.fullDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理多选状态
|
||||||
|
*/
|
||||||
|
cleanMultipleStatus() {
|
||||||
|
this.multipleStatus = {
|
||||||
|
before: '',
|
||||||
|
after: '',
|
||||||
|
data: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置开始日期
|
||||||
|
*/
|
||||||
|
resetSatrtDate(startDate) {
|
||||||
|
// 范围开始
|
||||||
|
this.startDate = startDate
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置结束日期
|
||||||
|
*/
|
||||||
|
resetEndDate(endDate) {
|
||||||
|
// 范围结束
|
||||||
|
this.endDate = endDate
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取任意时间
|
||||||
|
*/
|
||||||
|
getDate(date, AddDayCount = 0, str = 'day') {
|
||||||
|
if (!date) {
|
||||||
|
date = new Date()
|
||||||
|
}
|
||||||
|
if (typeof date !== 'object') {
|
||||||
|
date = date.replace(/-/g, '/')
|
||||||
|
}
|
||||||
|
const dd = new Date(date)
|
||||||
|
switch (str) {
|
||||||
|
case 'day':
|
||||||
|
dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
|
||||||
|
break
|
||||||
|
case 'month':
|
||||||
|
if (dd.getDate() === 31 && AddDayCount>0) {
|
||||||
|
dd.setDate(dd.getDate() + AddDayCount)
|
||||||
|
} else {
|
||||||
|
const preMonth = dd.getMonth()
|
||||||
|
dd.setMonth(preMonth + AddDayCount) // 获取AddDayCount天后的日期
|
||||||
|
const nextMonth = dd.getMonth()
|
||||||
|
// 处理 pre 切换月份目标月份为2月没有当前日(30 31) 切换错误问题
|
||||||
|
if(AddDayCount<0 && preMonth!==0 && nextMonth-preMonth>AddDayCount){
|
||||||
|
dd.setMonth(nextMonth+(nextMonth-preMonth+AddDayCount))
|
||||||
|
}
|
||||||
|
// 处理 next 切换月份目标月份为2月没有当前日(30 31) 切换错误问题
|
||||||
|
if(AddDayCount>0 && nextMonth-preMonth>AddDayCount){
|
||||||
|
dd.setMonth(nextMonth-(nextMonth-preMonth-AddDayCount))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'year':
|
||||||
|
dd.setFullYear(dd.getFullYear() + AddDayCount) // 获取AddDayCount天后的日期
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const y = dd.getFullYear()
|
||||||
|
const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
|
||||||
|
const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
|
||||||
|
return {
|
||||||
|
fullDate: y + '-' + m + '-' + d,
|
||||||
|
year: y,
|
||||||
|
month: m,
|
||||||
|
date: d,
|
||||||
|
day: dd.getDay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上月剩余天数
|
||||||
|
*/
|
||||||
|
_getLastMonthDays(firstDay, full) {
|
||||||
|
let dateArr = []
|
||||||
|
for (let i = firstDay; i > 0; i--) {
|
||||||
|
const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate()
|
||||||
|
dateArr.push({
|
||||||
|
date: beforeDate,
|
||||||
|
month: full.month - 1,
|
||||||
|
lunar: this.getlunar(full.year, full.month - 1, beforeDate),
|
||||||
|
disable: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return dateArr
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取本月天数
|
||||||
|
*/
|
||||||
|
_currentMonthDys(dateData, full) {
|
||||||
|
let dateArr = []
|
||||||
|
let fullDate = this.date.fullDate
|
||||||
|
for (let i = 1; i <= dateData; i++) {
|
||||||
|
let nowDate = full.year + '-' + (full.month < 10 ?
|
||||||
|
full.month : full.month) + '-' + (i < 10 ?
|
||||||
|
'0' + i : i)
|
||||||
|
// 是否今天
|
||||||
|
let isDay = fullDate === nowDate
|
||||||
|
// 获取打点信息
|
||||||
|
let info = this.selected && this.selected.find((item) => {
|
||||||
|
if (this.dateEqual(nowDate, item.date)) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 日期禁用
|
||||||
|
let disableBefore = true
|
||||||
|
let disableAfter = true
|
||||||
|
if (this.startDate) {
|
||||||
|
// let dateCompBefore = this.dateCompare(this.startDate, fullDate)
|
||||||
|
// disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate)
|
||||||
|
disableBefore = this.dateCompare(this.startDate, nowDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.endDate) {
|
||||||
|
// let dateCompAfter = this.dateCompare(fullDate, this.endDate)
|
||||||
|
// disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate)
|
||||||
|
disableAfter = this.dateCompare(nowDate, this.endDate)
|
||||||
|
}
|
||||||
|
let multiples = this.multipleStatus.data
|
||||||
|
let checked = false
|
||||||
|
let multiplesStatus = -1
|
||||||
|
if (this.range) {
|
||||||
|
if (multiples) {
|
||||||
|
multiplesStatus = multiples.findIndex((item) => {
|
||||||
|
return this.dateEqual(item, nowDate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (multiplesStatus !== -1) {
|
||||||
|
checked = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let data = {
|
||||||
|
fullDate: nowDate,
|
||||||
|
year: full.year,
|
||||||
|
date: i,
|
||||||
|
multiple: this.range ? checked : false,
|
||||||
|
beforeMultiple: this.dateEqual(this.multipleStatus.before, nowDate),
|
||||||
|
afterMultiple: this.dateEqual(this.multipleStatus.after, nowDate),
|
||||||
|
month: full.month,
|
||||||
|
lunar: this.getlunar(full.year, full.month, i),
|
||||||
|
disable: !(disableBefore && disableAfter),
|
||||||
|
isDay
|
||||||
|
}
|
||||||
|
if (info) {
|
||||||
|
data.extraInfo = info
|
||||||
|
}
|
||||||
|
|
||||||
|
dateArr.push(data)
|
||||||
|
}
|
||||||
|
return dateArr
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取下月天数
|
||||||
|
*/
|
||||||
|
_getNextMonthDays(surplus, full) {
|
||||||
|
let dateArr = []
|
||||||
|
for (let i = 1; i < surplus + 1; i++) {
|
||||||
|
dateArr.push({
|
||||||
|
date: i,
|
||||||
|
month: Number(full.month) + 1,
|
||||||
|
lunar: this.getlunar(full.year, Number(full.month) + 1, i),
|
||||||
|
disable: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return dateArr
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期详情
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
getInfo(date) {
|
||||||
|
if (!date) {
|
||||||
|
date = new Date()
|
||||||
|
}
|
||||||
|
const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate)
|
||||||
|
return dateInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较时间大小
|
||||||
|
*/
|
||||||
|
dateCompare(startDate, endDate) {
|
||||||
|
// 计算截止时间
|
||||||
|
startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
|
||||||
|
// 计算详细项的截止时间
|
||||||
|
endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
|
||||||
|
if (startDate <= endDate) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较时间是否相等
|
||||||
|
*/
|
||||||
|
dateEqual(before, after) {
|
||||||
|
// 计算截止时间
|
||||||
|
before = new Date(before.replace('-', '/').replace('-', '/'))
|
||||||
|
// 计算详细项的截止时间
|
||||||
|
after = new Date(after.replace('-', '/').replace('-', '/'))
|
||||||
|
if (before.getTime() - after.getTime() === 0) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日期范围内所有日期
|
||||||
|
* @param {Object} begin
|
||||||
|
* @param {Object} end
|
||||||
|
*/
|
||||||
|
geDateAll(begin, end) {
|
||||||
|
var arr = []
|
||||||
|
var ab = begin.split('-')
|
||||||
|
var ae = end.split('-')
|
||||||
|
var db = new Date()
|
||||||
|
db.setFullYear(ab[0], ab[1] - 1, ab[2])
|
||||||
|
var de = new Date()
|
||||||
|
de.setFullYear(ae[0], ae[1] - 1, ae[2])
|
||||||
|
var unixDb = db.getTime() - 24 * 60 * 60 * 1000
|
||||||
|
var unixDe = de.getTime() - 24 * 60 * 60 * 1000
|
||||||
|
for (var k = unixDb; k <= unixDe;) {
|
||||||
|
k = k + 24 * 60 * 60 * 1000
|
||||||
|
arr.push(this.getDate(new Date(parseInt(k))).fullDate)
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 计算阴历日期显示
|
||||||
|
*/
|
||||||
|
getlunar(year, month, date) {
|
||||||
|
return CALENDAR.solar2lunar(year, month, date)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置打点
|
||||||
|
*/
|
||||||
|
setSelectInfo(data, value) {
|
||||||
|
this.selected = value
|
||||||
|
this._getWeek(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取多选状态
|
||||||
|
*/
|
||||||
|
setMultiple(fullDate) {
|
||||||
|
let {
|
||||||
|
before,
|
||||||
|
after
|
||||||
|
} = this.multipleStatus
|
||||||
|
|
||||||
|
if (!this.range) return
|
||||||
|
if (before && after) {
|
||||||
|
this.multipleStatus.before = fullDate
|
||||||
|
this.multipleStatus.after = ''
|
||||||
|
this.multipleStatus.data = []
|
||||||
|
} else {
|
||||||
|
if (!before) {
|
||||||
|
this.multipleStatus.before = fullDate
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.after = fullDate
|
||||||
|
if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._getWeek(fullDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取每周数据
|
||||||
|
* @param {Object} dateData
|
||||||
|
*/
|
||||||
|
_getWeek(dateData) {
|
||||||
|
const {
|
||||||
|
year,
|
||||||
|
month
|
||||||
|
} = this.getDate(dateData)
|
||||||
|
let firstDay = new Date(year, month - 1, 1).getDay()
|
||||||
|
let currentDay = new Date(year, month, 0).getDate()
|
||||||
|
let dates = {
|
||||||
|
lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 上个月末尾几天
|
||||||
|
currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 本月天数
|
||||||
|
nextMonthDays: [], // 下个月开始几天
|
||||||
|
weeks: []
|
||||||
|
}
|
||||||
|
let canlender = []
|
||||||
|
const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
|
||||||
|
dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
|
||||||
|
canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
|
||||||
|
let weeks = {}
|
||||||
|
// 拼接数组 上个月开始几天 + 本月天数+ 下个月开始几天
|
||||||
|
for (let i = 0; i < canlender.length; i++) {
|
||||||
|
if (i % 7 === 0) {
|
||||||
|
weeks[parseInt(i / 7)] = new Array(7)
|
||||||
|
}
|
||||||
|
weeks[parseInt(i / 7)][i % 7] = canlender[i]
|
||||||
|
}
|
||||||
|
this.canlender = canlender
|
||||||
|
this.weeks = weeks
|
||||||
|
}
|
||||||
|
|
||||||
|
//静态方法
|
||||||
|
// static init(date) {
|
||||||
|
// if (!this.instance) {
|
||||||
|
// this.instance = new Calendar(date);
|
||||||
|
// }
|
||||||
|
// return this.instance;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default Calendar
|
||||||
270
node_modules/@dcloudio/uni-ui/lib/uni-card/uni-card.vue
generated
vendored
Normal file
270
node_modules/@dcloudio/uni-ui/lib/uni-card/uni-card.vue
generated
vendored
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-card" :class="{ 'uni-card--full': isFull, 'uni-card--shadow': isShadow,'uni-card--border':border}"
|
||||||
|
:style="{'margin':isFull?0:margin,'padding':spacing,'box-shadow':isShadow?shadow:''}">
|
||||||
|
<!-- 封面 -->
|
||||||
|
<slot name="cover">
|
||||||
|
<view v-if="cover" class="uni-card__cover">
|
||||||
|
<image class="uni-card__cover-image" mode="widthFix" @click="onClick('cover')" :src="cover"></image>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
<slot name="title">
|
||||||
|
<view v-if="title || extra" class="uni-card__header">
|
||||||
|
<!-- 卡片标题 -->
|
||||||
|
<view class="uni-card__header-box" @click="onClick('title')">
|
||||||
|
<view v-if="thumbnail" class="uni-card__header-avatar">
|
||||||
|
<image class="uni-card__header-avatar-image" :src="thumbnail" mode="aspectFit" />
|
||||||
|
</view>
|
||||||
|
<view class="uni-card__header-content">
|
||||||
|
<text class="uni-card__header-content-title uni-ellipsis">{{ title }}</text>
|
||||||
|
<text v-if="title&&subTitle"
|
||||||
|
class="uni-card__header-content-subtitle uni-ellipsis">{{ subTitle }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-card__header-extra" @click="onClick('extra')">
|
||||||
|
<text class="uni-card__header-extra-text">{{ extra }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
<!-- 卡片内容 -->
|
||||||
|
<view class="uni-card__content" :style="{padding:padding}" @click="onClick('content')">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
<view class="uni-card__actions" @click="onClick('actions')">
|
||||||
|
<slot name="actions"></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Card 卡片
|
||||||
|
* @description 卡片视图组件
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=22
|
||||||
|
* @property {String} title 标题文字
|
||||||
|
* @property {String} subTitle 副标题
|
||||||
|
* @property {Number} padding 内容内边距
|
||||||
|
* @property {Number} margin 卡片外边距
|
||||||
|
* @property {Number} spacing 卡片内边距
|
||||||
|
* @property {String} extra 标题额外信息
|
||||||
|
* @property {String} cover 封面图(本地路径需要引入)
|
||||||
|
* @property {String} thumbnail 标题左侧缩略图
|
||||||
|
* @property {Boolean} is-full = [true | false] 卡片内容是否通栏,为 true 时将去除padding值
|
||||||
|
* @property {Boolean} is-shadow = [true | false] 卡片内容是否开启阴影
|
||||||
|
* @property {String} shadow 卡片阴影
|
||||||
|
* @property {Boolean} border 卡片边框
|
||||||
|
* @event {Function} click 点击 Card 触发事件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniCard',
|
||||||
|
emits: ['click'],
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
subTitle: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
type: String,
|
||||||
|
default: '10px'
|
||||||
|
},
|
||||||
|
margin: {
|
||||||
|
type: String,
|
||||||
|
default: '15px'
|
||||||
|
},
|
||||||
|
spacing: {
|
||||||
|
type: String,
|
||||||
|
default: '0 10px'
|
||||||
|
},
|
||||||
|
extra: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
cover: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
thumbnail: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
isFull: {
|
||||||
|
// 内容区域是否通栏
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
isShadow: {
|
||||||
|
// 是否开启阴影
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
shadow: {
|
||||||
|
type: String,
|
||||||
|
default: '0px 0px 3px 1px rgba(0, 0, 0, 0.08)'
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick(type) {
|
||||||
|
this.$emit('click', type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-border-3: #EBEEF5 !default;
|
||||||
|
$uni-shadow-base:0 0px 6px 1px rgba($color: #a5a5a5, $alpha: 0.2) !default;
|
||||||
|
$uni-main-color: #3a3a3a !default;
|
||||||
|
$uni-base-color: #6a6a6a !default;
|
||||||
|
$uni-secondary-color: #909399 !default;
|
||||||
|
$uni-spacing-sm: 8px !default;
|
||||||
|
$uni-border-color:$uni-border-3;
|
||||||
|
$uni-shadow: $uni-shadow-base;
|
||||||
|
$uni-card-title: 15px;
|
||||||
|
$uni-cart-title-color:$uni-main-color;
|
||||||
|
$uni-card-subtitle: 12px;
|
||||||
|
$uni-cart-subtitle-color:$uni-secondary-color;
|
||||||
|
$uni-card-spacing: 10px;
|
||||||
|
$uni-card-content-color: $uni-base-color;
|
||||||
|
|
||||||
|
.uni-card {
|
||||||
|
margin: $uni-card-spacing;
|
||||||
|
padding: 0 $uni-spacing-sm;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: hidden;
|
||||||
|
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;
|
||||||
|
background-color: #fff;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
.uni-card__cover {
|
||||||
|
position: relative;
|
||||||
|
margin-top: $uni-card-spacing;
|
||||||
|
flex-direction: row;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 4px;
|
||||||
|
.uni-card__cover-image {
|
||||||
|
flex: 1;
|
||||||
|
// width: 100%;
|
||||||
|
/* #ifndef APP-PLUS */
|
||||||
|
vertical-align: middle;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__header {
|
||||||
|
display: flex;
|
||||||
|
border-bottom: 1px $uni-border-color solid;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding: $uni-card-spacing;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.uni-card__header-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__header-avatar {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-right: $uni-card-spacing;
|
||||||
|
.uni-card__header-avatar-image {
|
||||||
|
flex: 1;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__header-content {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
flex: 1;
|
||||||
|
// height: 40px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.uni-card__header-content-title {
|
||||||
|
font-size: $uni-card-title;
|
||||||
|
color: $uni-cart-title-color;
|
||||||
|
// line-height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__header-content-subtitle {
|
||||||
|
font-size: $uni-card-subtitle;
|
||||||
|
margin-top: 5px;
|
||||||
|
color: $uni-cart-subtitle-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__header-extra {
|
||||||
|
line-height: 12px;
|
||||||
|
|
||||||
|
.uni-card__header-extra-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: $uni-cart-subtitle-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__content {
|
||||||
|
padding: $uni-card-spacing;
|
||||||
|
font-size: 14px;
|
||||||
|
color: $uni-card-content-color;
|
||||||
|
line-height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card__actions {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card--border {
|
||||||
|
border: 1px solid $uni-border-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card--shadow {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-shadow: $uni-shadow;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-card--full {
|
||||||
|
margin: 0;
|
||||||
|
border-left-width: 0;
|
||||||
|
border-left-width: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
.uni-card--full:after {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
.uni-ellipsis {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
lines: 1;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
317
node_modules/@dcloudio/uni-ui/lib/uni-col/uni-col.vue
generated
vendored
Normal file
317
node_modules/@dcloudio/uni-ui/lib/uni-col/uni-col.vue
generated
vendored
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
<template>
|
||||||
|
<!-- #ifndef APP-NVUE -->
|
||||||
|
<view :class="['uni-col', sizeClass, pointClassList]" :style="{
|
||||||
|
paddingLeft:`${Number(gutter)}rpx`,
|
||||||
|
paddingRight:`${Number(gutter)}rpx`,
|
||||||
|
}">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifdef APP-NVUE -->
|
||||||
|
<!-- 在nvue上,类名样式不生效,换为style -->
|
||||||
|
<!-- 设置right正值失效,设置 left 负值 -->
|
||||||
|
<view :class="['uni-col']" :style="{
|
||||||
|
paddingLeft:`${Number(gutter)}rpx`,
|
||||||
|
paddingRight:`${Number(gutter)}rpx`,
|
||||||
|
width:`${nvueWidth}rpx`,
|
||||||
|
position:'relative',
|
||||||
|
marginLeft:`${marginLeft}rpx`,
|
||||||
|
left:`${right === 0 ? left : -right}rpx`
|
||||||
|
}">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Col 布局-列
|
||||||
|
* @description 搭配uni-row使用,构建布局。
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3958
|
||||||
|
*
|
||||||
|
* @property {span} type = Number 栅格占据的列数
|
||||||
|
* 默认 24
|
||||||
|
* @property {offset} type = Number 栅格左侧的间隔格数
|
||||||
|
* @property {push} type = Number 栅格向右移动格数
|
||||||
|
* @property {pull} type = Number 栅格向左移动格数
|
||||||
|
* @property {xs} type = [Number, Object] <768px 响应式栅格数或者栅格属性对象
|
||||||
|
* @description Number时表示在此屏幕宽度下,栅格占据的列数。Object时可配置多个描述{span: 4, offset: 4}
|
||||||
|
* @property {sm} type = [Number, Object] ≥768px 响应式栅格数或者栅格属性对象
|
||||||
|
* @description Number时表示在此屏幕宽度下,栅格占据的列数。Object时可配置多个描述{span: 4, offset: 4}
|
||||||
|
* @property {md} type = [Number, Object] ≥992px 响应式栅格数或者栅格属性对象
|
||||||
|
* @description Number时表示在此屏幕宽度下,栅格占据的列数。Object时可配置多个描述{span: 4, offset: 4}
|
||||||
|
* @property {lg} type = [Number, Object] ≥1200px 响应式栅格数或者栅格属性对象
|
||||||
|
* @description Number时表示在此屏幕宽度下,栅格占据的列数。Object时可配置多个描述{span: 4, offset: 4}
|
||||||
|
* @property {xl} type = [Number, Object] ≥1920px 响应式栅格数或者栅格属性对象
|
||||||
|
* @description Number时表示在此屏幕宽度下,栅格占据的列数。Object时可配置多个描述{span: 4, offset: 4}
|
||||||
|
*/
|
||||||
|
const ComponentClass = 'uni-col';
|
||||||
|
|
||||||
|
// -1 默认值,因为在微信小程序端只给Number会有默认值0
|
||||||
|
export default {
|
||||||
|
name: 'uniCol',
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
options: {
|
||||||
|
virtualHost: true // 在微信小程序中将组件节点渲染为虚拟节点,更加接近Vue组件的表现
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
props: {
|
||||||
|
span: {
|
||||||
|
type: Number,
|
||||||
|
default: 24
|
||||||
|
},
|
||||||
|
offset: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
|
},
|
||||||
|
pull: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
|
},
|
||||||
|
push: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
|
},
|
||||||
|
xs: [Number, Object],
|
||||||
|
sm: [Number, Object],
|
||||||
|
md: [Number, Object],
|
||||||
|
lg: [Number, Object],
|
||||||
|
xl: [Number, Object]
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
gutter: 0,
|
||||||
|
sizeClass: '',
|
||||||
|
parentWidth: 0,
|
||||||
|
nvueWidth: 0,
|
||||||
|
marginLeft: 0,
|
||||||
|
right: 0,
|
||||||
|
left: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// 字节小程序中,在computed中读取$parent为undefined
|
||||||
|
let parent = this.$parent;
|
||||||
|
|
||||||
|
while (parent && parent.$options.componentName !== 'uniRow') {
|
||||||
|
parent = parent.$parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateGutter(parent.gutter)
|
||||||
|
parent.$watch('gutter', (gutter) => {
|
||||||
|
this.updateGutter(gutter)
|
||||||
|
})
|
||||||
|
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
this.updateNvueWidth(parent.width)
|
||||||
|
parent.$watch('width', (width) => {
|
||||||
|
this.updateNvueWidth(width)
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
sizeList() {
|
||||||
|
let {
|
||||||
|
span,
|
||||||
|
offset,
|
||||||
|
pull,
|
||||||
|
push
|
||||||
|
} = this;
|
||||||
|
|
||||||
|
return {
|
||||||
|
span,
|
||||||
|
offset,
|
||||||
|
pull,
|
||||||
|
push
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
pointClassList() {
|
||||||
|
let classList = [];
|
||||||
|
|
||||||
|
['xs', 'sm', 'md', 'lg', 'xl'].forEach(point => {
|
||||||
|
const props = this[point];
|
||||||
|
if (typeof props === 'number') {
|
||||||
|
classList.push(`${ComponentClass}-${point}-${props}`)
|
||||||
|
} else if (typeof props === 'object' && props) {
|
||||||
|
Object.keys(props).forEach(pointProp => {
|
||||||
|
classList.push(
|
||||||
|
pointProp === 'span' ?
|
||||||
|
`${ComponentClass}-${point}-${props[pointProp]}` :
|
||||||
|
`${ComponentClass}-${point}-${pointProp}-${props[pointProp]}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 支付宝小程序使用 :class=[ ['a','b'] ],渲染错误
|
||||||
|
return classList.join(' ');
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
updateGutter(parentGutter) {
|
||||||
|
parentGutter = Number(parentGutter);
|
||||||
|
if (!isNaN(parentGutter)) {
|
||||||
|
this.gutter = parentGutter / 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
updateNvueWidth(width) {
|
||||||
|
// 用于在nvue端,span,offset,pull,push的计算
|
||||||
|
this.parentWidth = width;
|
||||||
|
['span', 'offset', 'pull', 'push'].forEach(size => {
|
||||||
|
const curSize = this[size];
|
||||||
|
if ((curSize || curSize === 0) && curSize !== -1) {
|
||||||
|
let RPX = 1 / 24 * curSize * width
|
||||||
|
RPX = Number(RPX);
|
||||||
|
switch (size) {
|
||||||
|
case 'span':
|
||||||
|
this.nvueWidth = RPX
|
||||||
|
break;
|
||||||
|
case 'offset':
|
||||||
|
this.marginLeft = RPX
|
||||||
|
break;
|
||||||
|
case 'pull':
|
||||||
|
this.right = RPX
|
||||||
|
break;
|
||||||
|
case 'push':
|
||||||
|
this.left = RPX
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
sizeList: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal) {
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
let classList = [];
|
||||||
|
for (let size in newVal) {
|
||||||
|
const curSize = newVal[size];
|
||||||
|
if ((curSize || curSize === 0) && curSize !== -1) {
|
||||||
|
classList.push(
|
||||||
|
size === 'span' ?
|
||||||
|
`${ComponentClass}-${curSize}` :
|
||||||
|
`${ComponentClass}-${size}-${curSize}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 支付宝小程序使用 :class=[ ['a','b'] ],渲染错误
|
||||||
|
this.sizeClass = classList.join(' ');
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
this.updateNvueWidth(this.parentWidth);
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang='scss' scoped>
|
||||||
|
/* breakpoints */
|
||||||
|
$--sm: 768px !default;
|
||||||
|
$--md: 992px !default;
|
||||||
|
$--lg: 1200px !default;
|
||||||
|
$--xl: 1920px !default;
|
||||||
|
|
||||||
|
$breakpoints: ('xs' : (max-width: $--sm - 1),
|
||||||
|
'sm' : (min-width: $--sm),
|
||||||
|
'md' : (min-width: $--md),
|
||||||
|
'lg' : (min-width: $--lg),
|
||||||
|
'xl' : (min-width: $--xl));
|
||||||
|
|
||||||
|
$layout-namespace: ".uni-";
|
||||||
|
$col: $layout-namespace+"col";
|
||||||
|
|
||||||
|
@function getSize($size) {
|
||||||
|
/* TODO 1/24 * $size * 100 * 1%; 使用计算后的值,为了解决 vue3 控制台报错 */
|
||||||
|
@return 0.04166666666 * $size * 100 * 1%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin res($key, $map:$breakpoints) {
|
||||||
|
@if map-has-key($map, $key) {
|
||||||
|
@media screen and #{inspect(map-get($map,$key))} {
|
||||||
|
@content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@else {
|
||||||
|
@warn "Undeinfed point: `#{$key}`";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
#{$col} {
|
||||||
|
float: left;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-0 {
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
margin-left: 0;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: none;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
@for $i from 0 through 24 {
|
||||||
|
#{$col}-#{$i} {
|
||||||
|
width: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-offset-#{$i} {
|
||||||
|
margin-left: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-pull-#{$i} {
|
||||||
|
position: relative;
|
||||||
|
right: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-push-#{$i} {
|
||||||
|
position: relative;
|
||||||
|
left: getSize($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@each $point in map-keys($breakpoints) {
|
||||||
|
@include res($point) {
|
||||||
|
#{$col}-#{$point}-0 {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@for $i from 0 through 24 {
|
||||||
|
#{$col}-#{$point}-#{$i} {
|
||||||
|
width: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-#{$point}-offset-#{$i} {
|
||||||
|
margin-left: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-#{$point}-pull-#{$i} {
|
||||||
|
position: relative;
|
||||||
|
right: getSize($i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#{$col}-#{$point}-push-#{$i} {
|
||||||
|
position: relative;
|
||||||
|
left: getSize($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
</style>
|
||||||
402
node_modules/@dcloudio/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue
generated
vendored
Normal file
402
node_modules/@dcloudio/uni-ui/lib/uni-collapse-item/uni-collapse-item.vue
generated
vendored
Normal file
@ -0,0 +1,402 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-collapse-item">
|
||||||
|
<!-- onClick(!isOpen) -->
|
||||||
|
<view @click="onClick(!isOpen)" class="uni-collapse-item__title"
|
||||||
|
:class="{'is-open':isOpen &&titleBorder === 'auto' ,'uni-collapse-item-border':titleBorder !== 'none'}">
|
||||||
|
<view class="uni-collapse-item__title-wrap">
|
||||||
|
<slot name="title">
|
||||||
|
<view class="uni-collapse-item__title-box" :class="{'is-disabled':disabled}">
|
||||||
|
<image v-if="thumb" :src="thumb" class="uni-collapse-item__title-img" />
|
||||||
|
<text class="uni-collapse-item__title-text">{{ title }}</text>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
</view>
|
||||||
|
<view v-if="showArrow"
|
||||||
|
:class="{ 'uni-collapse-item__title-arrow-active': isOpen, 'uni-collapse-item--animation': showAnimation === true }"
|
||||||
|
class="uni-collapse-item__title-arrow">
|
||||||
|
<uni-icons :color="disabled?'#ddd':'#bbb'" size="14" type="bottom" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-collapse-item__wrap" :class="{'is--transition':showAnimation}"
|
||||||
|
:style="{height: (isOpen?height:0) +'px'}">
|
||||||
|
<view :id="elId" ref="collapse--hook" class="uni-collapse-item__wrap-content"
|
||||||
|
:class="{open:isheight,'uni-collapse-item--border':border&&isOpen}">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
const dom = weex.requireModule('dom')
|
||||||
|
// #endif
|
||||||
|
/**
|
||||||
|
* CollapseItem 折叠面板子组件
|
||||||
|
* @description 折叠面板子组件
|
||||||
|
* @property {String} title 标题文字
|
||||||
|
* @property {String} thumb 标题左侧缩略图
|
||||||
|
* @property {String} name 唯一标志符
|
||||||
|
* @property {Boolean} open = [true|false] 是否展开组件
|
||||||
|
* @property {Boolean} titleBorder = [true|false] 是否显示标题分隔线
|
||||||
|
* @property {String} border = ['auto'|'show'|'none'] 是否显示分隔线
|
||||||
|
* @property {Boolean} disabled = [true|false] 是否展开面板
|
||||||
|
* @property {Boolean} showAnimation = [true|false] 开启动画
|
||||||
|
* @property {Boolean} showArrow = [true|false] 是否显示右侧箭头
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniCollapseItem',
|
||||||
|
props: {
|
||||||
|
// 列表标题
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 是否禁用
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
// 是否显示动画,app 端默认不开启动画,卡顿严重
|
||||||
|
showAnimation: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-PLUS
|
||||||
|
// 是否显示动画
|
||||||
|
showAnimation: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// 是否展开
|
||||||
|
open: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
// 缩略图
|
||||||
|
thumb: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 标题分隔线显示类型
|
||||||
|
titleBorder: {
|
||||||
|
type: String,
|
||||||
|
default: 'auto'
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showArrow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
// TODO 随机生生元素ID,解决百度小程序获取同一个元素位置信息的bug
|
||||||
|
const elId = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
|
||||||
|
return {
|
||||||
|
isOpen: false,
|
||||||
|
isheight: null,
|
||||||
|
height: 0,
|
||||||
|
elId,
|
||||||
|
nameSync: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
open(val) {
|
||||||
|
this.isOpen = val
|
||||||
|
this.onClick(val, 'init')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updated(e) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.init(true)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.collapse = this.getCollapse()
|
||||||
|
this.oldHeight = 0
|
||||||
|
this.onClick(this.open, 'init')
|
||||||
|
},
|
||||||
|
// #ifndef VUE3
|
||||||
|
// TODO vue2
|
||||||
|
destroyed() {
|
||||||
|
if (this.__isUnmounted) return
|
||||||
|
this.uninstall()
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
// TODO vue3
|
||||||
|
unmounted() {
|
||||||
|
this.__isUnmounted = true
|
||||||
|
this.uninstall()
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
mounted() {
|
||||||
|
if (!this.collapse) return
|
||||||
|
if (this.name !== '') {
|
||||||
|
this.nameSync = this.name
|
||||||
|
} else {
|
||||||
|
this.nameSync = this.collapse.childrens.length + ''
|
||||||
|
}
|
||||||
|
if (this.collapse.names.indexOf(this.nameSync) === -1) {
|
||||||
|
this.collapse.names.push(this.nameSync)
|
||||||
|
} else {
|
||||||
|
console.warn(`name 值 ${this.nameSync} 重复`);
|
||||||
|
}
|
||||||
|
if (this.collapse.childrens.indexOf(this) === -1) {
|
||||||
|
this.collapse.childrens.push(this)
|
||||||
|
}
|
||||||
|
this.init()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
init(type) {
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
this.getCollapseHeight(type)
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
this.getNvueHwight(type)
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
uninstall() {
|
||||||
|
if (this.collapse) {
|
||||||
|
this.collapse.childrens.forEach((item, index) => {
|
||||||
|
if (item === this) {
|
||||||
|
this.collapse.childrens.splice(index, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.collapse.names.forEach((item, index) => {
|
||||||
|
if (item === this.nameSync) {
|
||||||
|
this.collapse.names.splice(index, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onClick(isOpen, type) {
|
||||||
|
if (this.disabled) return
|
||||||
|
this.isOpen = isOpen
|
||||||
|
if (this.isOpen && this.collapse) {
|
||||||
|
this.collapse.setAccordion(this)
|
||||||
|
}
|
||||||
|
if (type !== 'init') {
|
||||||
|
this.collapse.onChange(isOpen, this)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getCollapseHeight(type, index = 0) {
|
||||||
|
const views = uni.createSelectorQuery().in(this)
|
||||||
|
views
|
||||||
|
.select(`#${this.elId}`)
|
||||||
|
.fields({
|
||||||
|
size: true
|
||||||
|
}, data => {
|
||||||
|
// TODO 百度中可能获取不到节点信息 ,需要循环获取
|
||||||
|
if (index >= 10) return
|
||||||
|
if (!data) {
|
||||||
|
index++
|
||||||
|
this.getCollapseHeight(false, index)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
this.height = data.height + 1
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
this.height = data.height
|
||||||
|
// #endif
|
||||||
|
this.isheight = true
|
||||||
|
if (type) return
|
||||||
|
this.onClick(this.isOpen, 'init')
|
||||||
|
})
|
||||||
|
.exec()
|
||||||
|
},
|
||||||
|
getNvueHwight(type) {
|
||||||
|
const result = dom.getComponentRect(this.$refs['collapse--hook'], option => {
|
||||||
|
if (option && option.result && option.size) {
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
this.height = option.size.height + 1
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
this.height = option.size.height
|
||||||
|
// #endif
|
||||||
|
this.isheight = true
|
||||||
|
if (type) return
|
||||||
|
this.onClick(this.open, 'init')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取父元素实例
|
||||||
|
*/
|
||||||
|
getCollapse(name = 'uniCollapse') {
|
||||||
|
let parent = this.$parent;
|
||||||
|
let parentName = parent.$options.name;
|
||||||
|
while (parentName !== name) {
|
||||||
|
parent = parent.$parent;
|
||||||
|
if (!parent) return false;
|
||||||
|
parentName = parent.$options.name;
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-collapse-item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
&__title {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
transition: border-bottom-color .3s;
|
||||||
|
|
||||||
|
// transition-property: border-bottom-color;
|
||||||
|
// transition-duration: 5s;
|
||||||
|
&-wrap {
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
&-box {
|
||||||
|
padding: 0 15px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
height: 48px;
|
||||||
|
line-height: 48px;
|
||||||
|
background-color: #fff;
|
||||||
|
color: #303133;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
outline: none;
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
&.is-disabled {
|
||||||
|
.uni-collapse-item__title-text {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
&.uni-collapse-item-border {
|
||||||
|
border-bottom: 1px solid #ebeef5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-open {
|
||||||
|
border-bottom-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
height: 22px;
|
||||||
|
width: 22px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-text {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 14px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
white-space: nowrap;
|
||||||
|
color: inherit;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
lines: 1;
|
||||||
|
/* #endif */
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-arrow {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-right: 10px;
|
||||||
|
transform: rotate(0deg);
|
||||||
|
|
||||||
|
&-active {
|
||||||
|
transform: rotate(-180deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
&__wrap {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
will-change: height;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
background-color: #fff;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
height: 0;
|
||||||
|
|
||||||
|
&.is--transition {
|
||||||
|
// transition: all 0.3s;
|
||||||
|
transition-property: height, border-bottom-width;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
will-change: height;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
&-content {
|
||||||
|
position: absolute;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #303133;
|
||||||
|
// transition: height 0.3s;
|
||||||
|
border-bottom-color: transparent;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-bottom-width: 0;
|
||||||
|
|
||||||
|
&.uni-collapse-item--border {
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-bottom-color: red;
|
||||||
|
border-bottom-color: #ebeef5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.open {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--animation {
|
||||||
|
transition-property: transform;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
transition-timing-function: ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
147
node_modules/@dcloudio/uni-ui/lib/uni-collapse/uni-collapse.vue
generated
vendored
Normal file
147
node_modules/@dcloudio/uni-ui/lib/uni-collapse/uni-collapse.vue
generated
vendored
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-collapse">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Collapse 折叠面板
|
||||||
|
* @description 展示可以折叠 / 展开的内容区域
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=23
|
||||||
|
* @property {String|Array} value 当前激活面板改变时触发(如果是手风琴模式,参数类型为string,否则为array)
|
||||||
|
* @property {Boolean} accordion = [true|false] 是否开启手风琴效果是否开启手风琴效果
|
||||||
|
* @event {Function} change 切换面板时触发,如果是手风琴模式,返回类型为string,否则为array
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniCollapse',
|
||||||
|
emits:['change','activeItem','input','update:modelValue'],
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: [String, Array],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Array],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
accordion: {
|
||||||
|
// 是否开启手风琴效果
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// TODO 兼容 vue2 和 vue3
|
||||||
|
dataValue() {
|
||||||
|
let value = (typeof this.value === 'string' && this.value === '') ||
|
||||||
|
(Array.isArray(this.value) && this.value.length === 0)
|
||||||
|
let modelValue = (typeof this.modelValue === 'string' && this.modelValue === '') ||
|
||||||
|
(Array.isArray(this.modelValue) && this.modelValue.length === 0)
|
||||||
|
if (value) {
|
||||||
|
return this.modelValue
|
||||||
|
}
|
||||||
|
if (modelValue) {
|
||||||
|
return this.value
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
dataValue(val) {
|
||||||
|
this.setOpen(val)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.childrens = []
|
||||||
|
this.names = []
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$nextTick(()=>{
|
||||||
|
this.setOpen(this.dataValue)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
setOpen(val) {
|
||||||
|
let str = typeof val === 'string'
|
||||||
|
let arr = Array.isArray(val)
|
||||||
|
this.childrens.forEach((vm, index) => {
|
||||||
|
if (str) {
|
||||||
|
if (val === vm.nameSync) {
|
||||||
|
if (!this.accordion) {
|
||||||
|
console.warn('accordion 属性为 false ,v-model 类型应该为 array')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vm.isOpen = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arr) {
|
||||||
|
val.forEach(v => {
|
||||||
|
if (v === vm.nameSync) {
|
||||||
|
if (this.accordion) {
|
||||||
|
console.warn('accordion 属性为 true ,v-model 类型应该为 string')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
vm.isOpen = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.emit(val)
|
||||||
|
},
|
||||||
|
setAccordion(self) {
|
||||||
|
if (!this.accordion) return
|
||||||
|
this.childrens.forEach((vm, index) => {
|
||||||
|
if (self !== vm) {
|
||||||
|
vm.isOpen = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
resize() {
|
||||||
|
this.childrens.forEach((vm, index) => {
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
vm.getCollapseHeight()
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
vm.getNvueHwight()
|
||||||
|
// #endif
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onChange(isOpen, self) {
|
||||||
|
let activeItem = []
|
||||||
|
|
||||||
|
if (this.accordion) {
|
||||||
|
activeItem = isOpen ? self.nameSync : ''
|
||||||
|
} else {
|
||||||
|
this.childrens.forEach((vm, index) => {
|
||||||
|
if (vm.isOpen) {
|
||||||
|
activeItem.push(vm.nameSync)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.$emit('change', activeItem)
|
||||||
|
this.emit(activeItem)
|
||||||
|
},
|
||||||
|
emit(val){
|
||||||
|
this.$emit('input', val)
|
||||||
|
this.$emit('update:modelValue', val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss" >
|
||||||
|
.uni-collapse {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
flex: 1;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
284
node_modules/@dcloudio/uni-ui/lib/uni-combox/uni-combox.vue
generated
vendored
Normal file
284
node_modules/@dcloudio/uni-ui/lib/uni-combox/uni-combox.vue
generated
vendored
Normal file
@ -0,0 +1,284 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-combox" :class="border ? '' : 'uni-combox__no-border'">
|
||||||
|
<view v-if="label" class="uni-combox__label" :style="labelStyle">
|
||||||
|
<text>{{label}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-combox__input-box">
|
||||||
|
<input class="uni-combox__input" type="text" :placeholder="placeholder" placeholder-class="uni-combox__input-plac"
|
||||||
|
v-model="inputVal" @input="onInput" @focus="onFocus" @blur="onBlur" />
|
||||||
|
<uni-icons v-if="!inputVal || !clearAble" :type="showSelector? 'top' : 'bottom'" size="14" color="#999" @click="toggleSelector">
|
||||||
|
</uni-icons>
|
||||||
|
<uni-icons v-if="inputVal && clearAble" type="clear" size="24" color="#999" @click="clean">
|
||||||
|
</uni-icons>
|
||||||
|
</view>
|
||||||
|
<view class="uni-combox__selector" v-if="showSelector">
|
||||||
|
<view class="uni-popper__arrow"></view>
|
||||||
|
<scroll-view scroll-y="true" class="uni-combox__selector-scroll">
|
||||||
|
<view class="uni-combox__selector-empty" v-if="filterCandidatesLength === 0">
|
||||||
|
<text>{{emptyTips}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-combox__selector-item" v-for="(item,index) in filterCandidates" :key="index"
|
||||||
|
@click="onSelectorClick(index)">
|
||||||
|
<text>{{item}}</text>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Combox 组合输入框
|
||||||
|
* @description 组合输入框一般用于既可以输入也可以选择的场景
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=1261
|
||||||
|
* @property {String} label 左侧文字
|
||||||
|
* @property {String} labelWidth 左侧内容宽度
|
||||||
|
* @property {String} placeholder 输入框占位符
|
||||||
|
* @property {Array} candidates 候选项列表
|
||||||
|
* @property {String} emptyTips 筛选结果为空时显示的文字
|
||||||
|
* @property {String} value 组合框的值
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniCombox',
|
||||||
|
emits: ['input', 'update:modelValue'],
|
||||||
|
props: {
|
||||||
|
clearAble: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
labelWidth: {
|
||||||
|
type: String,
|
||||||
|
default: 'auto'
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
candidates: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emptyTips: {
|
||||||
|
type: String,
|
||||||
|
default: '无匹配项'
|
||||||
|
},
|
||||||
|
// #ifndef VUE3
|
||||||
|
value: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showSelector: false,
|
||||||
|
inputVal: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
labelStyle() {
|
||||||
|
if (this.labelWidth === 'auto') {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return `width: ${this.labelWidth}`
|
||||||
|
},
|
||||||
|
filterCandidates() {
|
||||||
|
return this.candidates.filter((item) => {
|
||||||
|
return item.toString().indexOf(this.inputVal) > -1
|
||||||
|
})
|
||||||
|
},
|
||||||
|
filterCandidatesLength() {
|
||||||
|
return this.filterCandidates.length
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// #ifndef VUE3
|
||||||
|
value: {
|
||||||
|
handler(newVal) {
|
||||||
|
this.inputVal = newVal
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
modelValue: {
|
||||||
|
handler(newVal) {
|
||||||
|
this.inputVal = newVal
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleSelector() {
|
||||||
|
this.showSelector = !this.showSelector
|
||||||
|
},
|
||||||
|
onFocus() {
|
||||||
|
this.showSelector = true
|
||||||
|
},
|
||||||
|
onBlur() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.showSelector = false
|
||||||
|
}, 153)
|
||||||
|
},
|
||||||
|
onSelectorClick(index) {
|
||||||
|
this.inputVal = this.filterCandidates[index]
|
||||||
|
this.showSelector = false
|
||||||
|
this.$emit('input', this.inputVal)
|
||||||
|
this.$emit('update:modelValue', this.inputVal)
|
||||||
|
},
|
||||||
|
onInput() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$emit('input', this.inputVal)
|
||||||
|
this.$emit('update:modelValue', this.inputVal)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
clean() {
|
||||||
|
this.inputVal = ''
|
||||||
|
this.onInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.uni-combox {
|
||||||
|
font-size: 14px;
|
||||||
|
border: 1px solid #DCDFE6;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
// height: 40px;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
// border-bottom: solid 1px #DDDDDD;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__label {
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 22px;
|
||||||
|
padding-right: 10px;
|
||||||
|
color: #999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__input-box {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__input {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 14px;
|
||||||
|
height: 22px;
|
||||||
|
line-height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__input-plac {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__selector {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
position: absolute;
|
||||||
|
top: calc(100% + 12px);
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border: 1px solid #EBEEF5;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
z-index: 2;
|
||||||
|
padding: 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__selector-scroll {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
max-height: 200px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__selector-empty,
|
||||||
|
.uni-combox__selector-item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
line-height: 36px;
|
||||||
|
font-size: 14px;
|
||||||
|
text-align: center;
|
||||||
|
// border-bottom: solid 1px #DDDDDD;
|
||||||
|
padding: 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__selector-item:hover {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__selector-empty:last-child,
|
||||||
|
.uni-combox__selector-item:last-child {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
border-bottom: none;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
// picker 弹出层通用的指示小三角
|
||||||
|
.uni-popper__arrow,
|
||||||
|
.uni-popper__arrow::after {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-color: transparent;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow {
|
||||||
|
filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
|
||||||
|
top: -6px;
|
||||||
|
left: 10%;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #EBEEF5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow::after {
|
||||||
|
content: " ";
|
||||||
|
top: 1px;
|
||||||
|
margin-left: -6px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-combox__no-border {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/en.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/en.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-countdown.day": "day",
|
||||||
|
"uni-countdown.h": "h",
|
||||||
|
"uni-countdown.m": "m",
|
||||||
|
"uni-countdown.s": "s"
|
||||||
|
}
|
||||||
8
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/index.js
generated
vendored
Normal file
8
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import en from './en.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/zh-Hans.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/zh-Hans.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-countdown.day": "天",
|
||||||
|
"uni-countdown.h": "时",
|
||||||
|
"uni-countdown.m": "分",
|
||||||
|
"uni-countdown.s": "秒"
|
||||||
|
}
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/zh-Hant.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-countdown/i18n/zh-Hant.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-countdown.day": "天",
|
||||||
|
"uni-countdown.h": "時",
|
||||||
|
"uni-countdown.m": "分",
|
||||||
|
"uni-countdown.s": "秒"
|
||||||
|
}
|
||||||
276
node_modules/@dcloudio/uni-ui/lib/uni-countdown/uni-countdown.vue
generated
vendored
Normal file
276
node_modules/@dcloudio/uni-ui/lib/uni-countdown/uni-countdown.vue
generated
vendored
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-countdown">
|
||||||
|
<text v-if="showDay" :style="[timeStyle]" class="uni-countdown__number">{{ d }}</text>
|
||||||
|
<text v-if="showDay" :style="[splitorStyle]" class="uni-countdown__splitor">{{dayText}}</text>
|
||||||
|
<text v-if="showHour" :style="[timeStyle]" class="uni-countdown__number">{{ h }}</text>
|
||||||
|
<text v-if="showHour" :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : hourText }}</text>
|
||||||
|
<text v-if="showMinute" :style="[timeStyle]" class="uni-countdown__number">{{ i }}</text>
|
||||||
|
<text v-if="showMinute" :style="[splitorStyle]" class="uni-countdown__splitor">{{ showColon ? ':' : minuteText }}</text>
|
||||||
|
<text :style="[timeStyle]" class="uni-countdown__number">{{ s }}</text>
|
||||||
|
<text v-if="!showColon" :style="[splitorStyle]" class="uni-countdown__splitor">{{secondText}}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
initVueI18n
|
||||||
|
} from '@dcloudio/uni-i18n'
|
||||||
|
import messages from './i18n/index.js'
|
||||||
|
const {
|
||||||
|
t
|
||||||
|
} = initVueI18n(messages)
|
||||||
|
/**
|
||||||
|
* Countdown 倒计时
|
||||||
|
* @description 倒计时组件
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=25
|
||||||
|
* @property {String} backgroundColor 背景色
|
||||||
|
* @property {String} color 文字颜色
|
||||||
|
* @property {Number} day 天数
|
||||||
|
* @property {Number} hour 小时
|
||||||
|
* @property {Number} minute 分钟
|
||||||
|
* @property {Number} second 秒
|
||||||
|
* @property {Number} timestamp 时间戳
|
||||||
|
* @property {Boolean} showDay = [true|false] 是否显示天数
|
||||||
|
* @property {Boolean} showHour = [true|false] 是否显示小时
|
||||||
|
* @property {Boolean} showMinute = [true|false] 是否显示分钟
|
||||||
|
* @property {Boolean} show-colon = [true|false] 是否以冒号为分隔符
|
||||||
|
* @property {String} splitorColor 分割符号颜色
|
||||||
|
* @event {Function} timeup 倒计时时间到触发事件
|
||||||
|
* @example <uni-countdown :day="1" :hour="1" :minute="12" :second="40"></uni-countdown>
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniCountdown',
|
||||||
|
emits: ['timeup'],
|
||||||
|
props: {
|
||||||
|
showDay: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showHour: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showMinute: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showColon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
backgroundColor: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
type: String,
|
||||||
|
default: '#333'
|
||||||
|
},
|
||||||
|
fontSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 14
|
||||||
|
},
|
||||||
|
splitorColor: {
|
||||||
|
type: String,
|
||||||
|
default: '#333'
|
||||||
|
},
|
||||||
|
day: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
hour: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
minute: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
second: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
timestamp: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
filterShow : {
|
||||||
|
type:Object,
|
||||||
|
default:{}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
timer: null,
|
||||||
|
syncFlag: false,
|
||||||
|
d: '00',
|
||||||
|
h: '00',
|
||||||
|
i: '00',
|
||||||
|
s: '00',
|
||||||
|
leftTime: 0,
|
||||||
|
seconds: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
dayText() {
|
||||||
|
return t("uni-countdown.day")
|
||||||
|
},
|
||||||
|
hourText(val) {
|
||||||
|
return t("uni-countdown.h")
|
||||||
|
},
|
||||||
|
minuteText(val) {
|
||||||
|
return t("uni-countdown.m")
|
||||||
|
},
|
||||||
|
secondText(val) {
|
||||||
|
return t("uni-countdown.s")
|
||||||
|
},
|
||||||
|
timeStyle() {
|
||||||
|
const {
|
||||||
|
color,
|
||||||
|
backgroundColor,
|
||||||
|
fontSize
|
||||||
|
} = this
|
||||||
|
return {
|
||||||
|
color,
|
||||||
|
backgroundColor,
|
||||||
|
fontSize: `${fontSize}px`,
|
||||||
|
width: `${fontSize * 22 / 14}px`, // 按字体大小为 14px 时的比例缩放
|
||||||
|
lineHeight: `${fontSize * 20 / 14}px`,
|
||||||
|
borderRadius: `${fontSize * 3 / 14}px`,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
splitorStyle() {
|
||||||
|
const { splitorColor, fontSize, backgroundColor } = this
|
||||||
|
return {
|
||||||
|
color: splitorColor,
|
||||||
|
fontSize: `${fontSize * 12 / 14}px`,
|
||||||
|
margin: backgroundColor ? `${fontSize * 4 / 14}px` : ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
day(val) {
|
||||||
|
this.changeFlag()
|
||||||
|
},
|
||||||
|
hour(val) {
|
||||||
|
this.changeFlag()
|
||||||
|
},
|
||||||
|
minute(val) {
|
||||||
|
this.changeFlag()
|
||||||
|
},
|
||||||
|
second(val) {
|
||||||
|
this.changeFlag()
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal, oldVal) {
|
||||||
|
if (newVal) {
|
||||||
|
this.startData();
|
||||||
|
} else {
|
||||||
|
if (!oldVal) return
|
||||||
|
clearInterval(this.timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created: function(e) {
|
||||||
|
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
|
||||||
|
this.countDown()
|
||||||
|
},
|
||||||
|
// #ifndef VUE3
|
||||||
|
destroyed() {
|
||||||
|
clearInterval(this.timer)
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
unmounted() {
|
||||||
|
clearInterval(this.timer)
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
methods: {
|
||||||
|
toSeconds(timestamp, day, hours, minutes, seconds) {
|
||||||
|
if (timestamp) {
|
||||||
|
return timestamp - parseInt(new Date().getTime() / 1000, 10)
|
||||||
|
}
|
||||||
|
return day * 60 * 60 * 24 + hours * 60 * 60 + minutes * 60 + seconds
|
||||||
|
},
|
||||||
|
timeUp() {
|
||||||
|
clearInterval(this.timer)
|
||||||
|
this.$emit('timeup')
|
||||||
|
},
|
||||||
|
countDown() {
|
||||||
|
let seconds = this.seconds
|
||||||
|
let [day, hour, minute, second] = [0, 0, 0, 0]
|
||||||
|
if (seconds > 0) {
|
||||||
|
day = Math.floor(seconds / (60 * 60 * 24))
|
||||||
|
hour = Math.floor(seconds / (60 * 60)) - (day * 24)
|
||||||
|
minute = Math.floor(seconds / 60) - (day * 24 * 60) - (hour * 60)
|
||||||
|
second = Math.floor(seconds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60)
|
||||||
|
} else {
|
||||||
|
this.timeUp()
|
||||||
|
}
|
||||||
|
this.d = String(day).padStart(this.validFilterShow(this.filterShow.d), '0')
|
||||||
|
this.h = String(hour).padStart(this.validFilterShow(this.filterShow.h), '0')
|
||||||
|
this.i = String(minute).padStart(this.validFilterShow(this.filterShow.m), '0')
|
||||||
|
this.s = String(second).padStart(this.validFilterShow(this.filterShow.s), '0')
|
||||||
|
},
|
||||||
|
validFilterShow(filter){
|
||||||
|
return (filter && filter > 0) ? filter : 2;
|
||||||
|
},
|
||||||
|
startData() {
|
||||||
|
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
|
||||||
|
if (this.seconds <= 0) {
|
||||||
|
this.seconds = this.toSeconds(0, 0, 0, 0, 0)
|
||||||
|
this.countDown()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clearInterval(this.timer)
|
||||||
|
this.countDown()
|
||||||
|
this.timer = setInterval(() => {
|
||||||
|
this.seconds--
|
||||||
|
if (this.seconds < 0) {
|
||||||
|
this.timeUp()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.countDown()
|
||||||
|
}, 1000)
|
||||||
|
},
|
||||||
|
update(){
|
||||||
|
this.startData();
|
||||||
|
},
|
||||||
|
changeFlag() {
|
||||||
|
if (!this.syncFlag) {
|
||||||
|
this.seconds = this.toSeconds(this.timestamp, this.day, this.hour, this.minute, this.second)
|
||||||
|
this.startData();
|
||||||
|
this.syncFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$font-size: 14px;
|
||||||
|
|
||||||
|
.uni-countdown {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&__splitor {
|
||||||
|
margin: 0 2px;
|
||||||
|
font-size: $font-size;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__number {
|
||||||
|
border-radius: 3px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: $font-size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
849
node_modules/@dcloudio/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue
generated
vendored
Normal file
849
node_modules/@dcloudio/uni-ui/lib/uni-data-checkbox/uni-data-checkbox.vue
generated
vendored
Normal file
@ -0,0 +1,849 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-data-checklist" :style="{'margin-top':isTop+'px'}">
|
||||||
|
<template v-if="!isLocal">
|
||||||
|
<view class="uni-data-loading">
|
||||||
|
<uni-load-more v-if="!mixinDatacomErrorMessage" status="loading" iconType="snow" :iconSize="18"
|
||||||
|
:content-text="contentText"></uni-load-more>
|
||||||
|
<text v-else>{{mixinDatacomErrorMessage}}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<checkbox-group v-if="multiple" class="checklist-group" :class="{'is-list':mode==='list' || wrap}"
|
||||||
|
@change="change">
|
||||||
|
<label class="checklist-box"
|
||||||
|
:class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']"
|
||||||
|
:style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index">
|
||||||
|
<checkbox class="hidden" hidden :disabled="disabled || !!item.disabled" :value="item[map.value]+''"
|
||||||
|
:checked="item.selected" />
|
||||||
|
<view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')"
|
||||||
|
class="checkbox__inner" :style="item.styleIcon">
|
||||||
|
<view class="checkbox__inner-icon"></view>
|
||||||
|
</view>
|
||||||
|
<view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}">
|
||||||
|
<text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text>
|
||||||
|
<view v-if="mode === 'list' && icon === 'right'" class="checkobx__list" :style="item.styleBackgroud"></view>
|
||||||
|
</view>
|
||||||
|
</label>
|
||||||
|
</checkbox-group>
|
||||||
|
<radio-group v-else class="checklist-group" :class="{'is-list':mode==='list','is-wrap':wrap}" @change="change">
|
||||||
|
<label class="checklist-box"
|
||||||
|
:class="['is--'+mode,item.selected?'is-checked':'',(disabled || !!item.disabled)?'is-disable':'',index!==0&&mode==='list'?'is-list-border':'']"
|
||||||
|
:style="item.styleBackgroud" v-for="(item,index) in dataList" :key="index">
|
||||||
|
<radio class="hidden" hidden :disabled="disabled || item.disabled" :value="item[map.value]+''"
|
||||||
|
:checked="item.selected" />
|
||||||
|
<view v-if="(mode !=='tag' && mode !== 'list') || ( mode === 'list' && icon === 'left')" class="radio__inner"
|
||||||
|
:style="item.styleBackgroud">
|
||||||
|
<view class="radio__inner-icon" :style="item.styleIcon"></view>
|
||||||
|
</view>
|
||||||
|
<view class="checklist-content" :class="{'list-content':mode === 'list' && icon ==='left'}">
|
||||||
|
<text class="checklist-text" :style="item.styleIconText">{{item[map.text]}}</text>
|
||||||
|
<view v-if="mode === 'list' && icon === 'right'" :style="item.styleRightIcon" class="checkobx__list"></view>
|
||||||
|
</view>
|
||||||
|
</label>
|
||||||
|
</radio-group>
|
||||||
|
</template>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* DataChecklist 数据选择器
|
||||||
|
* @description 通过数据渲染 checkbox 和 radio
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=xxx
|
||||||
|
* @property {String} mode = [default| list | button | tag] 显示模式
|
||||||
|
* @value default 默认横排模式
|
||||||
|
* @value list 列表模式
|
||||||
|
* @value button 按钮模式
|
||||||
|
* @value tag 标签模式
|
||||||
|
* @property {Boolean} multiple = [true|false] 是否多选
|
||||||
|
* @property {Array|String|Number} value 默认值
|
||||||
|
* @property {Array} localdata 本地数据 ,格式 [{text:'',value:''}]
|
||||||
|
* @property {Number|String} min 最小选择个数 ,multiple为true时生效
|
||||||
|
* @property {Number|String} max 最大选择个数 ,multiple为true时生效
|
||||||
|
* @property {Boolean} wrap 是否换行显示
|
||||||
|
* @property {String} icon = [left|right] list 列表模式下icon显示位置
|
||||||
|
* @property {Boolean} selectedColor 选中颜色
|
||||||
|
* @property {Boolean} emptyText 没有数据时显示的文字 ,本地数据无效
|
||||||
|
* @property {Boolean} selectedTextColor 选中文本颜色,如不填写则自动显示
|
||||||
|
* @property {Object} map 字段映射, 默认 map={text:'text',value:'value'}
|
||||||
|
* @value left 左侧显示
|
||||||
|
* @value right 右侧显示
|
||||||
|
* @event {Function} change 选中发生变化触发
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'uniDataChecklist',
|
||||||
|
mixins: [uniCloud.mixinDatacom || {}],
|
||||||
|
emits: ['input', 'update:modelValue', 'change'],
|
||||||
|
props: {
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'default'
|
||||||
|
},
|
||||||
|
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [Array, String, Number],
|
||||||
|
default () {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// TODO vue3
|
||||||
|
modelValue: {
|
||||||
|
type: [Array, String, Number],
|
||||||
|
default () {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
localdata: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
min: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
max: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
wrap: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
default: 'left'
|
||||||
|
},
|
||||||
|
selectedColor: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
selectedTextColor: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
emptyText: {
|
||||||
|
type: String,
|
||||||
|
default: '暂无数据'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
map: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
text: 'text',
|
||||||
|
value: 'value'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
localdata: {
|
||||||
|
handler(newVal) {
|
||||||
|
this.range = newVal
|
||||||
|
this.dataList = this.getDataList(this.getSelectedValue(newVal))
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
},
|
||||||
|
mixinDatacomResData(newVal) {
|
||||||
|
this.range = newVal
|
||||||
|
this.dataList = this.getDataList(this.getSelectedValue(newVal))
|
||||||
|
},
|
||||||
|
value(newVal) {
|
||||||
|
this.dataList = this.getDataList(newVal)
|
||||||
|
// fix by mehaotian is_reset 在 uni-forms 中定义
|
||||||
|
// if(!this.is_reset){
|
||||||
|
// this.is_reset = false
|
||||||
|
// this.formItem && this.formItem.setValue(newVal)
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
modelValue(newVal) {
|
||||||
|
this.dataList = this.getDataList(newVal);
|
||||||
|
// if(!this.is_reset){
|
||||||
|
// this.is_reset = false
|
||||||
|
// this.formItem && this.formItem.setValue(newVal)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
dataList: [],
|
||||||
|
range: [],
|
||||||
|
contentText: {
|
||||||
|
contentdown: '查看更多',
|
||||||
|
contentrefresh: '加载中',
|
||||||
|
contentnomore: '没有更多'
|
||||||
|
},
|
||||||
|
isLocal: true,
|
||||||
|
styles: {
|
||||||
|
selectedColor: '#2979ff',
|
||||||
|
selectedTextColor: '#666',
|
||||||
|
},
|
||||||
|
isTop: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
dataValue() {
|
||||||
|
if (this.value === '') return this.modelValue
|
||||||
|
if (this.modelValue === '') return this.value
|
||||||
|
return this.value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// this.form = this.getForm('uniForms')
|
||||||
|
// this.formItem = this.getForm('uniFormsItem')
|
||||||
|
// this.formItem && this.formItem.setValue(this.value)
|
||||||
|
|
||||||
|
// if (this.formItem) {
|
||||||
|
// this.isTop = 6
|
||||||
|
// if (this.formItem.name) {
|
||||||
|
// // 如果存在name添加默认值,否则formData 中不存在这个字段不校验
|
||||||
|
// if(!this.is_reset){
|
||||||
|
// this.is_reset = false
|
||||||
|
// this.formItem.setValue(this.dataValue)
|
||||||
|
// }
|
||||||
|
// this.rename = this.formItem.name
|
||||||
|
// this.form.inputChildrens.push(this)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (this.localdata && this.localdata.length !== 0) {
|
||||||
|
this.isLocal = true
|
||||||
|
this.range = this.localdata
|
||||||
|
this.dataList = this.getDataList(this.getSelectedValue(this.range))
|
||||||
|
} else {
|
||||||
|
if (this.collection) {
|
||||||
|
this.isLocal = false
|
||||||
|
this.loadData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
loadData() {
|
||||||
|
this.mixinDatacomGet().then(res => {
|
||||||
|
this.mixinDatacomResData = res.result.data
|
||||||
|
if (this.mixinDatacomResData.length === 0) {
|
||||||
|
this.isLocal = false
|
||||||
|
this.mixinDatacomErrorMessage = this.emptyText
|
||||||
|
} else {
|
||||||
|
this.isLocal = true
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
this.mixinDatacomErrorMessage = err.message
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取父元素实例
|
||||||
|
*/
|
||||||
|
getForm(name = 'uniForms') {
|
||||||
|
let parent = this.$parent;
|
||||||
|
let parentName = parent.$options.name;
|
||||||
|
while (parentName !== name) {
|
||||||
|
parent = parent.$parent;
|
||||||
|
if (!parent) return false
|
||||||
|
parentName = parent.$options.name;
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
},
|
||||||
|
change(e) {
|
||||||
|
const values = e.detail.value
|
||||||
|
|
||||||
|
let detail = {
|
||||||
|
value: [],
|
||||||
|
data: []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.multiple) {
|
||||||
|
this.range.forEach(item => {
|
||||||
|
|
||||||
|
if (values.includes(item[this.map.value] + '')) {
|
||||||
|
detail.value.push(item[this.map.value])
|
||||||
|
detail.data.push(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const range = this.range.find(item => (item[this.map.value] + '') === values)
|
||||||
|
if (range) {
|
||||||
|
detail = {
|
||||||
|
value: range[this.map.value],
|
||||||
|
data: range
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this.formItem && this.formItem.setValue(detail.value)
|
||||||
|
// TODO 兼容 vue2
|
||||||
|
this.$emit('input', detail.value);
|
||||||
|
// // TOTO 兼容 vue3
|
||||||
|
this.$emit('update:modelValue', detail.value);
|
||||||
|
this.$emit('change', {
|
||||||
|
detail
|
||||||
|
})
|
||||||
|
if (this.multiple) {
|
||||||
|
// 如果 v-model 没有绑定 ,则走内部逻辑
|
||||||
|
// if (this.value.length === 0) {
|
||||||
|
this.dataList = this.getDataList(detail.value, true)
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
this.dataList = this.getDataList(detail.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取渲染的新数组
|
||||||
|
* @param {Object} value 选中内容
|
||||||
|
*/
|
||||||
|
getDataList(value) {
|
||||||
|
// 解除引用关系,破坏原引用关系,避免污染源数据
|
||||||
|
let dataList = JSON.parse(JSON.stringify(this.range))
|
||||||
|
let list = []
|
||||||
|
if (this.multiple) {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataList.forEach((item, index) => {
|
||||||
|
item.disabled = item.disable || item.disabled || false
|
||||||
|
if (this.multiple) {
|
||||||
|
if (value.length > 0) {
|
||||||
|
let have = value.find(val => val === item[this.map.value])
|
||||||
|
item.selected = have !== undefined
|
||||||
|
} else {
|
||||||
|
item.selected = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item.selected = value === item[this.map.value]
|
||||||
|
}
|
||||||
|
|
||||||
|
list.push(item)
|
||||||
|
})
|
||||||
|
return this.setRange(list)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 处理最大最小值
|
||||||
|
* @param {Object} list
|
||||||
|
*/
|
||||||
|
setRange(list) {
|
||||||
|
let selectList = list.filter(item => item.selected)
|
||||||
|
let min = Number(this.min) || 0
|
||||||
|
let max = Number(this.max) || ''
|
||||||
|
list.forEach((item, index) => {
|
||||||
|
if (this.multiple) {
|
||||||
|
if (selectList.length <= min) {
|
||||||
|
let have = selectList.find(val => val[this.map.value] === item[this.map.value])
|
||||||
|
if (have !== undefined) {
|
||||||
|
item.disabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectList.length >= max && max !== '') {
|
||||||
|
let have = selectList.find(val => val[this.map.value] === item[this.map.value])
|
||||||
|
if (have === undefined) {
|
||||||
|
item.disabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setStyles(item, index)
|
||||||
|
list[index] = item
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 设置 class
|
||||||
|
* @param {Object} item
|
||||||
|
* @param {Object} index
|
||||||
|
*/
|
||||||
|
setStyles(item, index) {
|
||||||
|
// 设置自定义样式
|
||||||
|
item.styleBackgroud = this.setStyleBackgroud(item)
|
||||||
|
item.styleIcon = this.setStyleIcon(item)
|
||||||
|
item.styleIconText = this.setStyleIconText(item)
|
||||||
|
item.styleRightIcon = this.setStyleRightIcon(item)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取选中值
|
||||||
|
* @param {Object} range
|
||||||
|
*/
|
||||||
|
getSelectedValue(range) {
|
||||||
|
if (!this.multiple) return this.dataValue
|
||||||
|
let selectedArr = []
|
||||||
|
range.forEach((item) => {
|
||||||
|
if (item.selected) {
|
||||||
|
selectedArr.push(item[this.map.value])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return this.dataValue.length > 0 ? this.dataValue : selectedArr
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置背景样式
|
||||||
|
*/
|
||||||
|
setStyleBackgroud(item) {
|
||||||
|
let styles = {}
|
||||||
|
let selectedColor = this.selectedColor ? this.selectedColor : '#2979ff'
|
||||||
|
if (this.selectedColor) {
|
||||||
|
if (this.mode !== 'list') {
|
||||||
|
styles['border-color'] = item.selected ? selectedColor : '#DCDFE6'
|
||||||
|
}
|
||||||
|
if (this.mode === 'tag') {
|
||||||
|
styles['background-color'] = item.selected ? selectedColor : '#f5f5f5'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let classles = ''
|
||||||
|
for (let i in styles) {
|
||||||
|
classles += `${i}:${styles[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
},
|
||||||
|
setStyleIcon(item) {
|
||||||
|
let styles = {}
|
||||||
|
let classles = ''
|
||||||
|
if (this.selectedColor) {
|
||||||
|
let selectedColor = this.selectedColor ? this.selectedColor : '#2979ff'
|
||||||
|
styles['background-color'] = item.selected ? selectedColor : '#fff'
|
||||||
|
styles['border-color'] = item.selected ? selectedColor : '#DCDFE6'
|
||||||
|
|
||||||
|
if (!item.selected && item.disabled) {
|
||||||
|
styles['background-color'] = '#F2F6FC'
|
||||||
|
styles['border-color'] = item.selected ? selectedColor : '#DCDFE6'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i in styles) {
|
||||||
|
classles += `${i}:${styles[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
},
|
||||||
|
setStyleIconText(item) {
|
||||||
|
let styles = {}
|
||||||
|
let classles = ''
|
||||||
|
if (this.selectedColor) {
|
||||||
|
let selectedColor = this.selectedColor ? this.selectedColor : '#2979ff'
|
||||||
|
if (this.mode === 'tag') {
|
||||||
|
styles.color = item.selected ? (this.selectedTextColor ? this.selectedTextColor : '#fff') : '#666'
|
||||||
|
} else {
|
||||||
|
styles.color = item.selected ? (this.selectedTextColor ? this.selectedTextColor : selectedColor) : '#666'
|
||||||
|
}
|
||||||
|
if (!item.selected && item.disabled) {
|
||||||
|
styles.color = '#999'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i in styles) {
|
||||||
|
classles += `${i}:${styles[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
},
|
||||||
|
setStyleRightIcon(item) {
|
||||||
|
let styles = {}
|
||||||
|
let classles = ''
|
||||||
|
if (this.mode === 'list') {
|
||||||
|
styles['border-color'] = item.selected ? this.styles.selectedColor : '#DCDFE6'
|
||||||
|
}
|
||||||
|
for (let i in styles) {
|
||||||
|
classles += `${i}:${styles[i]};`
|
||||||
|
}
|
||||||
|
|
||||||
|
return classles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-primary: #2979ff !default;
|
||||||
|
$border-color: #DCDFE6;
|
||||||
|
$disable: 0.4;
|
||||||
|
|
||||||
|
@mixin flex {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-loading {
|
||||||
|
@include flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 36px;
|
||||||
|
padding-left: 10px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-checklist {
|
||||||
|
position: relative;
|
||||||
|
z-index: 0;
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
// 多选样式
|
||||||
|
.checklist-group {
|
||||||
|
@include flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
&.is-list {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-box {
|
||||||
|
@include flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
margin: 5px 0;
|
||||||
|
margin-right: 25px;
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文字样式
|
||||||
|
.checklist-content {
|
||||||
|
@include flex;
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
margin-left: 5px;
|
||||||
|
line-height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkobx__list {
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-right-color: #007aff;
|
||||||
|
border-right-style: solid;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-bottom-color: #007aff;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
height: 12px;
|
||||||
|
width: 6px;
|
||||||
|
left: -5px;
|
||||||
|
transform-origin: center;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 多选样式
|
||||||
|
.checkbox__inner {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
position: relative;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 1px solid $border-color;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #fff;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
.checkbox__inner-icon {
|
||||||
|
position: absolute;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
top: 2px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
top: 1px;
|
||||||
|
/* #endif */
|
||||||
|
left: 5px;
|
||||||
|
height: 8px;
|
||||||
|
width: 4px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-right-color: #fff;
|
||||||
|
border-right-style: solid;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-bottom-color: #fff;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
opacity: 0;
|
||||||
|
transform-origin: center;
|
||||||
|
transform: rotate(40deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单选样式
|
||||||
|
.radio__inner {
|
||||||
|
@include flex;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: relative;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 1px solid $border-color;
|
||||||
|
border-radius: 16px;
|
||||||
|
background-color: #fff;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
.radio__inner-icon {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 10px;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认样式
|
||||||
|
&.is--default {
|
||||||
|
|
||||||
|
// 禁用
|
||||||
|
&.is-disable {
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
.checkbox__inner {
|
||||||
|
background-color: #F2F6FC;
|
||||||
|
border-color: $border-color;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
background-color: #F2F6FC;
|
||||||
|
border-color: $border-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中
|
||||||
|
&.is-checked {
|
||||||
|
.checkbox__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
|
||||||
|
.checkbox__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
|
||||||
|
.radio__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中禁用
|
||||||
|
&.is-disable {
|
||||||
|
.checkbox__inner {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按钮样式
|
||||||
|
&.is--button {
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border: 1px $border-color solid;
|
||||||
|
border-radius: 3px;
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
|
||||||
|
// 禁用
|
||||||
|
&.is-disable {
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
border: 1px #eee solid;
|
||||||
|
opacity: $disable;
|
||||||
|
|
||||||
|
.checkbox__inner {
|
||||||
|
background-color: #F2F6FC;
|
||||||
|
border-color: $border-color;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
background-color: #F2F6FC;
|
||||||
|
border-color: $border-color;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-checked {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
|
||||||
|
.checkbox__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
|
||||||
|
.checkbox__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
|
||||||
|
.radio__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中禁用
|
||||||
|
&.is-disable {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标签样式
|
||||||
|
&.is--tag {
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border: 1px $border-color solid;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
margin: 0;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 禁用
|
||||||
|
&.is-disable {
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-checked {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
border-color: $uni-primary;
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列表样式
|
||||||
|
&.is--list {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
padding: 10px 15px;
|
||||||
|
padding-left: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&.is-list-border {
|
||||||
|
border-top: 1px #eee solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 禁用
|
||||||
|
&.is-disable {
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
.checkbox__inner {
|
||||||
|
background-color: #F2F6FC;
|
||||||
|
border-color: $border-color;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-checked {
|
||||||
|
.checkbox__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
|
||||||
|
.checkbox__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio__inner {
|
||||||
|
border-color: $uni-primary;
|
||||||
|
.radio__inner-icon {
|
||||||
|
opacity: 1;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-content {
|
||||||
|
.checkobx__list {
|
||||||
|
opacity: 1;
|
||||||
|
border-color: $uni-primary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中禁用
|
||||||
|
&.is-disable {
|
||||||
|
.checkbox__inner {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checklist-text {
|
||||||
|
opacity: $disable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
45
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/keypress.js
generated
vendored
Normal file
45
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/keypress.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// #ifdef H5
|
||||||
|
export default {
|
||||||
|
name: 'Keypress',
|
||||||
|
props: {
|
||||||
|
disable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
const keyNames = {
|
||||||
|
esc: ['Esc', 'Escape'],
|
||||||
|
tab: 'Tab',
|
||||||
|
enter: 'Enter',
|
||||||
|
space: [' ', 'Spacebar'],
|
||||||
|
up: ['Up', 'ArrowUp'],
|
||||||
|
left: ['Left', 'ArrowLeft'],
|
||||||
|
right: ['Right', 'ArrowRight'],
|
||||||
|
down: ['Down', 'ArrowDown'],
|
||||||
|
delete: ['Backspace', 'Delete', 'Del']
|
||||||
|
}
|
||||||
|
const listener = ($event) => {
|
||||||
|
if (this.disable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const keyName = Object.keys(keyNames).find(key => {
|
||||||
|
const keyName = $event.key
|
||||||
|
const value = keyNames[key]
|
||||||
|
return value === keyName || (Array.isArray(value) && value.includes(keyName))
|
||||||
|
})
|
||||||
|
if (keyName) {
|
||||||
|
// 避免和其他按键事件冲突
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$emit(keyName, {})
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener('keyup', listener)
|
||||||
|
this.$once('hook:beforeDestroy', () => {
|
||||||
|
document.removeEventListener('keyup', listener)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
render: () => {}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
380
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/uni-data-picker.uvue
generated
vendored
Normal file
380
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/uni-data-picker.uvue
generated
vendored
Normal file
@ -0,0 +1,380 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-data-tree">
|
||||||
|
<view class="uni-data-tree-input" @click="handleInput">
|
||||||
|
<slot :data="selectedPaths" :error="error">
|
||||||
|
<view class="input-value" :class="{'input-value-border': border}">
|
||||||
|
<text v-if="error!=null" class="error-text">{{error!.errMsg}}</text>
|
||||||
|
<scroll-view v-if="selectedPaths.length" class="selected-path" scroll-x="true">
|
||||||
|
<view class="selected-list">
|
||||||
|
<template v-for="(item, index) in selectedPaths">
|
||||||
|
<text class="text-color">{{item[mappingTextName]}}</text>
|
||||||
|
<text v-if="index<selectedPaths.length-1" class="input-split-line">{{split}}</text>
|
||||||
|
</template>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<text v-else-if="error==null&&!loading" class="placeholder">{{placeholder}}</text>
|
||||||
|
<view v-if="!readonly" class="arrow-area">
|
||||||
|
<view class="input-arrow"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
<view v-if="loading && !isOpened" class="selected-loading">
|
||||||
|
<slot name="picker-loading" :loading="loading"></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-data-tree-cover" v-if="isOpened" @click="handleClose"></view>
|
||||||
|
<view class="uni-data-tree-dialog" v-if="isOpened">
|
||||||
|
<view class="uni-popper__arrow"></view>
|
||||||
|
<view class="dialog-caption">
|
||||||
|
<view class="dialog-title-view">
|
||||||
|
<text class="dialog-title">{{popupTitle}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="dialog-close" @click="handleClose">
|
||||||
|
<view class="dialog-close-plus" data-id="close"></view>
|
||||||
|
<view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view ref="pickerView" class="uni-data-pickerview">
|
||||||
|
<view v-if="error!=null" class="error">
|
||||||
|
<text class="error-text">{{error!.errMsg}}</text>
|
||||||
|
</view>
|
||||||
|
<scroll-view v-if="!isCloudDataList" :scroll-x="true">
|
||||||
|
<view class="selected-node-list">
|
||||||
|
<template v-for="(item, index) in selectedNodes">
|
||||||
|
<text class="selected-node-item" :class="{'selected-node-item-active':index==selectedIndex}"
|
||||||
|
@click="onTabSelect(index)">
|
||||||
|
{{item[mappingTextName]}}
|
||||||
|
</text>
|
||||||
|
</template>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<list-view class="list-view" :scroll-y="true">
|
||||||
|
<list-item class="list-item" v-for="(item, _) in currentDataList" @click="onNodeClick(item)">
|
||||||
|
<text class="item-text" :class="{'item-text-disabled': item['disable']}">{{item[mappingTextName]}}</text>
|
||||||
|
<text class="check" v-if="item[mappingValueName] == selectedNodes[selectedIndex][mappingValueName]"></text>
|
||||||
|
</list-item>
|
||||||
|
</list-view>
|
||||||
|
<view class="loading-cover" v-if="loading">
|
||||||
|
<slot name="pickerview-loading" :loading="loading"></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { dataPicker } from "../uni-data-pickerview/uni-data-picker.uts"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataPicker 级联选择
|
||||||
|
* @description 支持单列、和多列级联选择。列数没有限制,如果屏幕显示不全,顶部tab区域会左右滚动。
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3796
|
||||||
|
* @property {String} popup-title 弹出窗口标题
|
||||||
|
* @property {Array} localdata 本地数据,参考
|
||||||
|
* @property {Boolean} border = [true|false] 是否有边框
|
||||||
|
* @property {Boolean} readonly = [true|false] 是否仅读
|
||||||
|
* @property {Boolean} preload = [true|false] 是否预加载数据
|
||||||
|
* @value true 开启预加载数据,点击弹出窗口后显示已加载数据
|
||||||
|
* @value false 关闭预加载数据,点击弹出窗口后开始加载数据
|
||||||
|
* @property {Boolean} step-searh = [true|false] 是否分布查询
|
||||||
|
* @value true 启用分布查询,仅查询当前选中节点
|
||||||
|
* @value false 关闭分布查询,一次查询出所有数据
|
||||||
|
* @property {String|DBFieldString} self-field 分布查询当前字段名称
|
||||||
|
* @property {String|DBFieldString} parent-field 分布查询父字段名称
|
||||||
|
* @property {String|DBCollectionString} collection 表名
|
||||||
|
* @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
|
||||||
|
* @property {String} orderby 排序字段及正序倒叙设置
|
||||||
|
* @property {String|JQLString} where 查询条件
|
||||||
|
* @event {Function} popupshow 弹出的选择窗口打开时触发此事件
|
||||||
|
* @event {Function} popuphide 弹出的选择窗口关闭时触发此事件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniDataPicker',
|
||||||
|
emits: ['popupopened', 'popupclosed', 'nodeclick', 'change', 'input', 'update:modelValue', 'inputclick'],
|
||||||
|
mixins: [dataPicker],
|
||||||
|
props: {
|
||||||
|
popupTitle: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择'
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择'
|
||||||
|
},
|
||||||
|
heightMobile: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
readonly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
split: {
|
||||||
|
type: String,
|
||||||
|
default: '/'
|
||||||
|
},
|
||||||
|
ellipsis: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
isOpened: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isShowClearIcon() : boolean {
|
||||||
|
if (this.readonly) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.clearIcon && this.selectedPaths.length > 0) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.load()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
clear() {
|
||||||
|
},
|
||||||
|
load() {
|
||||||
|
if (this.isLocalData) {
|
||||||
|
this.loadLocalData()
|
||||||
|
} else if (this.isCloudDataList || this.isCloudDataTree) {
|
||||||
|
this.loadCloudDataPath()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
show() {
|
||||||
|
this.isOpened = true
|
||||||
|
this.$emit('popupopened')
|
||||||
|
if (!this.hasCloudTreeData) {
|
||||||
|
this.loadData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hide() {
|
||||||
|
this.isOpened = false
|
||||||
|
this.$emit('popupclosed')
|
||||||
|
},
|
||||||
|
handleInput() {
|
||||||
|
if (this.readonly) {
|
||||||
|
this.$emit('inputclick')
|
||||||
|
} else {
|
||||||
|
this.show()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleClose() {
|
||||||
|
this.hide()
|
||||||
|
},
|
||||||
|
onFinish() {
|
||||||
|
this.selectedPaths = this.getChangeNodes()
|
||||||
|
this.$emit('change', this.selectedPaths)
|
||||||
|
this.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import url("../uni-data-pickerview/uni-data-pickerview.css");
|
||||||
|
|
||||||
|
.uni-data-tree {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-input {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-loading {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #DD524D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-value {
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
padding: 5px 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
min-height: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-value-border {
|
||||||
|
border: 1px solid #e5e5e5;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-path {
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
width: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-list {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-color {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
color: grey;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-split-line {
|
||||||
|
opacity: .5;
|
||||||
|
margin-left: 1px;
|
||||||
|
margin-right: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-area {
|
||||||
|
position: relative;
|
||||||
|
padding: 0 12px;
|
||||||
|
margin-left: auto;
|
||||||
|
justify-content: center;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-arrow {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-left: 2px solid #999;
|
||||||
|
border-bottom: 2px solid #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-cover {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(0, 0, 0, .4);
|
||||||
|
flex-direction: column;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-dialog {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 20%;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
flex-direction: column;
|
||||||
|
z-index: 102;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-caption {
|
||||||
|
position: relative;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-title-view {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-title {
|
||||||
|
align-self: center;
|
||||||
|
padding: 0 10px;
|
||||||
|
line-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-plus {
|
||||||
|
width: 16px;
|
||||||
|
height: 2px;
|
||||||
|
background-color: #666;
|
||||||
|
border-radius: 2px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-pickerview {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-clear {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef H5 */
|
||||||
|
@media all and (min-width: 768px) {
|
||||||
|
.uni-data-tree-cover {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-dialog {
|
||||||
|
position: absolute;
|
||||||
|
top: 55px;
|
||||||
|
height: auto;
|
||||||
|
min-height: 400px;
|
||||||
|
max-height: 50vh;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #EBEEF5;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-caption {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* #endif */
|
||||||
|
</style>
|
||||||
551
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/uni-data-picker.vue
generated
vendored
Normal file
551
node_modules/@dcloudio/uni-ui/lib/uni-data-picker/uni-data-picker.vue
generated
vendored
Normal file
@ -0,0 +1,551 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-data-tree">
|
||||||
|
<view class="uni-data-tree-input" @click="handleInput">
|
||||||
|
<slot :options="options" :data="inputSelected" :error="errorMessage">
|
||||||
|
<view class="input-value" :class="{'input-value-border': border}">
|
||||||
|
<text v-if="errorMessage" class="selected-area error-text">{{errorMessage}}</text>
|
||||||
|
<view v-else-if="loading && !isOpened" class="selected-area">
|
||||||
|
<uni-load-more class="load-more" :contentText="loadMore" status="loading"></uni-load-more>
|
||||||
|
</view>
|
||||||
|
<scroll-view v-else-if="inputSelected.length" class="selected-area" scroll-x="true">
|
||||||
|
<view class="selected-list">
|
||||||
|
<view class="selected-item" v-for="(item,index) in inputSelected" :key="index">
|
||||||
|
<text class="text-color">{{item.text}}</text><text v-if="index<inputSelected.length-1"
|
||||||
|
class="input-split-line">{{split}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<text v-else class="selected-area placeholder">{{placeholder}}</text>
|
||||||
|
<view v-if="clearIcon && !readonly && inputSelected.length" class="icon-clear" @click.stop="clear">
|
||||||
|
<uni-icons type="clear" color="#c0c4cc" size="24"></uni-icons>
|
||||||
|
</view>
|
||||||
|
<view class="arrow-area" v-if="(!clearIcon || !inputSelected.length) && !readonly ">
|
||||||
|
<view class="input-arrow"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
</view>
|
||||||
|
<view class="uni-data-tree-cover" v-if="isOpened" @click="handleClose"></view>
|
||||||
|
<view class="uni-data-tree-dialog" v-if="isOpened">
|
||||||
|
<view class="uni-popper__arrow"></view>
|
||||||
|
<view class="dialog-caption">
|
||||||
|
<view class="title-area">
|
||||||
|
<text class="dialog-title">{{popupTitle}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="dialog-close" @click="handleClose">
|
||||||
|
<view class="dialog-close-plus" data-id="close"></view>
|
||||||
|
<view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<data-picker-view class="picker-view" ref="pickerView" v-model="dataValue" :localdata="localdata"
|
||||||
|
:preload="preload" :collection="collection" :field="field" :orderby="orderby" :where="where"
|
||||||
|
:step-searh="stepSearh" :self-field="selfField" :parent-field="parentField" :managed-mode="true" :map="map"
|
||||||
|
:ellipsis="ellipsis" @change="onchange" @datachange="ondatachange" @nodeclick="onnodeclick">
|
||||||
|
</data-picker-view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import dataPicker from "../uni-data-pickerview/uni-data-picker.js"
|
||||||
|
import DataPickerView from "../uni-data-pickerview/uni-data-pickerview.vue"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataPicker 级联选择
|
||||||
|
* @description 支持单列、和多列级联选择。列数没有限制,如果屏幕显示不全,顶部tab区域会左右滚动。
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3796
|
||||||
|
* @property {String} popup-title 弹出窗口标题
|
||||||
|
* @property {Array} localdata 本地数据,参考
|
||||||
|
* @property {Boolean} border = [true|false] 是否有边框
|
||||||
|
* @property {Boolean} readonly = [true|false] 是否仅读
|
||||||
|
* @property {Boolean} preload = [true|false] 是否预加载数据
|
||||||
|
* @value true 开启预加载数据,点击弹出窗口后显示已加载数据
|
||||||
|
* @value false 关闭预加载数据,点击弹出窗口后开始加载数据
|
||||||
|
* @property {Boolean} step-searh = [true|false] 是否分布查询
|
||||||
|
* @value true 启用分布查询,仅查询当前选中节点
|
||||||
|
* @value false 关闭分布查询,一次查询出所有数据
|
||||||
|
* @property {String|DBFieldString} self-field 分布查询当前字段名称
|
||||||
|
* @property {String|DBFieldString} parent-field 分布查询父字段名称
|
||||||
|
* @property {String|DBCollectionString} collection 表名
|
||||||
|
* @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
|
||||||
|
* @property {String} orderby 排序字段及正序倒叙设置
|
||||||
|
* @property {String|JQLString} where 查询条件
|
||||||
|
* @event {Function} popupshow 弹出的选择窗口打开时触发此事件
|
||||||
|
* @event {Function} popuphide 弹出的选择窗口关闭时触发此事件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniDataPicker',
|
||||||
|
emits: ['popupopened', 'popupclosed', 'nodeclick', 'input', 'change', 'update:modelValue','inputclick'],
|
||||||
|
mixins: [dataPicker],
|
||||||
|
components: {
|
||||||
|
DataPickerView
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
options: {
|
||||||
|
type: [Object, Array],
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
popupTitle: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择'
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择'
|
||||||
|
},
|
||||||
|
heightMobile: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
readonly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
clearIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
split: {
|
||||||
|
type: String,
|
||||||
|
default: '/'
|
||||||
|
},
|
||||||
|
ellipsis: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
isOpened: false,
|
||||||
|
inputSelected: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.load();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
localdata: {
|
||||||
|
handler() {
|
||||||
|
this.load()
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
clear() {
|
||||||
|
this._dispatchEvent([]);
|
||||||
|
},
|
||||||
|
onPropsChange() {
|
||||||
|
this._treeData = [];
|
||||||
|
this.selectedIndex = 0;
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
},
|
||||||
|
load() {
|
||||||
|
if (this.readonly) {
|
||||||
|
this._processReadonly(this.localdata, this.dataValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回显本地数据
|
||||||
|
if (this.isLocalData) {
|
||||||
|
this.loadData();
|
||||||
|
this.inputSelected = this.selected.slice(0);
|
||||||
|
} else if (this.isCloudDataList || this.isCloudDataTree) { // 回显 Cloud 数据
|
||||||
|
this.loading = true;
|
||||||
|
this.getCloudDataValue().then((res) => {
|
||||||
|
this.loading = false;
|
||||||
|
this.inputSelected = res;
|
||||||
|
}).catch((err) => {
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = err;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
show() {
|
||||||
|
this.isOpened = true
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$refs.pickerView.updateData({
|
||||||
|
treeData: this._treeData,
|
||||||
|
selected: this.selected,
|
||||||
|
selectedIndex: this.selectedIndex
|
||||||
|
})
|
||||||
|
}, 200)
|
||||||
|
this.$emit('popupopened')
|
||||||
|
},
|
||||||
|
hide() {
|
||||||
|
this.isOpened = false
|
||||||
|
this.$emit('popupclosed')
|
||||||
|
},
|
||||||
|
handleInput() {
|
||||||
|
if (this.readonly) {
|
||||||
|
this.$emit('inputclick')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.show()
|
||||||
|
},
|
||||||
|
handleClose(e) {
|
||||||
|
this.hide()
|
||||||
|
},
|
||||||
|
onnodeclick(e) {
|
||||||
|
this.$emit('nodeclick', e)
|
||||||
|
},
|
||||||
|
ondatachange(e) {
|
||||||
|
this._treeData = this.$refs.pickerView._treeData
|
||||||
|
},
|
||||||
|
onchange(e) {
|
||||||
|
this.hide()
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.inputSelected = e;
|
||||||
|
})
|
||||||
|
this._dispatchEvent(e)
|
||||||
|
},
|
||||||
|
_processReadonly(dataList, value) {
|
||||||
|
var isTree = dataList.findIndex((item) => {
|
||||||
|
return item.children
|
||||||
|
})
|
||||||
|
if (isTree > -1) {
|
||||||
|
let inputValue
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
inputValue = value[value.length - 1]
|
||||||
|
if (typeof inputValue === 'object' && inputValue.value) {
|
||||||
|
inputValue = inputValue.value
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputValue = value
|
||||||
|
}
|
||||||
|
this.inputSelected = this._findNodePath(inputValue, this.localdata)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.hasValue) {
|
||||||
|
this.inputSelected = []
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = []
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
var val = value[i]
|
||||||
|
var item = dataList.find((v) => {
|
||||||
|
return v.value == val
|
||||||
|
})
|
||||||
|
if (item) {
|
||||||
|
result.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result.length) {
|
||||||
|
this.inputSelected = result
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_filterForArray(data, valueArray) {
|
||||||
|
var result = []
|
||||||
|
for (let i = 0; i < valueArray.length; i++) {
|
||||||
|
var value = valueArray[i]
|
||||||
|
var found = data.find((item) => {
|
||||||
|
return item.value == value
|
||||||
|
})
|
||||||
|
if (found) {
|
||||||
|
result.push(found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
},
|
||||||
|
_dispatchEvent(selected) {
|
||||||
|
let item = {}
|
||||||
|
if (selected.length) {
|
||||||
|
var value = new Array(selected.length)
|
||||||
|
for (var i = 0; i < selected.length; i++) {
|
||||||
|
value[i] = selected[i].value
|
||||||
|
}
|
||||||
|
item = selected[selected.length - 1]
|
||||||
|
} else {
|
||||||
|
item.value = ''
|
||||||
|
}
|
||||||
|
if (this.formItem) {
|
||||||
|
this.formItem.setValue(item.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$emit('input', item.value)
|
||||||
|
this.$emit('update:modelValue', item.value)
|
||||||
|
this.$emit('change', {
|
||||||
|
detail: {
|
||||||
|
value: selected
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.uni-data-tree {
|
||||||
|
flex: 1;
|
||||||
|
position: relative;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
color: #DD524D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-value {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
font-size: 14px;
|
||||||
|
/* line-height: 35px; */
|
||||||
|
padding: 0 10px;
|
||||||
|
padding-right: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 35px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-value-border {
|
||||||
|
border: 1px solid #e5e5e5;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-area {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
margin-right: auto;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
width: 40px;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-list {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
/* padding: 0 5px; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item {
|
||||||
|
flex-direction: row;
|
||||||
|
/* padding: 0 1px; */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
white-space: nowrap;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-color {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
color: grey;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-split-line {
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-area {
|
||||||
|
position: relative;
|
||||||
|
width: 20px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
margin-bottom: 5px;
|
||||||
|
margin-left: auto;
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-arrow {
|
||||||
|
width: 7px;
|
||||||
|
height: 7px;
|
||||||
|
border-left: 1px solid #999;
|
||||||
|
border-bottom: 1px solid #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-cover {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(0, 0, 0, .4);
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-dialog {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
top: 20%;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
top: 200px;
|
||||||
|
/* #endif */
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
z-index: 102;
|
||||||
|
overflow: hidden;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
width: 750rpx;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-caption {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
/* border-bottom: 1px solid #f0f0f0; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.title-area {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
margin: auto;
|
||||||
|
/* #endif */
|
||||||
|
padding: 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-title {
|
||||||
|
/* font-weight: bold; */
|
||||||
|
line-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-plus {
|
||||||
|
width: 16px;
|
||||||
|
height: 2px;
|
||||||
|
background-color: #666;
|
||||||
|
border-radius: 2px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.picker-view {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-clear {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef H5 */
|
||||||
|
@media all and (min-width: 768px) {
|
||||||
|
.uni-data-tree-cover {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-data-tree-dialog {
|
||||||
|
position: absolute;
|
||||||
|
top: 55px;
|
||||||
|
height: auto;
|
||||||
|
min-height: 400px;
|
||||||
|
max-height: 50vh;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #EBEEF5;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-caption {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-clear {
|
||||||
|
/* margin-right: 5px; */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
/* picker 弹出层通用的指示小三角, todo:扩展至上下左右方向定位 */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
.uni-popper__arrow,
|
||||||
|
.uni-popper__arrow::after {
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-color: transparent;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow {
|
||||||
|
filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
|
||||||
|
top: -6px;
|
||||||
|
left: 10%;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #EBEEF5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow::after {
|
||||||
|
content: " ";
|
||||||
|
top: 1px;
|
||||||
|
margin-left: -6px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
</style>
|
||||||
1
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/loading.uts
generated
vendored
Normal file
1
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/loading.uts
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
622
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-picker.js
generated
vendored
Normal file
622
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-picker.js
generated
vendored
Normal file
@ -0,0 +1,622 @@
|
|||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
localdata: {
|
||||||
|
type: [Array, Object],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
spaceInfo: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
collection: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
field: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
orderby: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
type: [String, Object],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
pageData: {
|
||||||
|
type: String,
|
||||||
|
default: 'add'
|
||||||
|
},
|
||||||
|
pageCurrent: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
|
},
|
||||||
|
pageSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 500
|
||||||
|
},
|
||||||
|
getcount: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
getone: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
gettree: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
manual: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [Array, String, Number],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [Array, String, Number],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preload: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
stepSearh: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
selfField: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
parentField: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
map: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
text: "text",
|
||||||
|
value: "value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
errorMessage: '',
|
||||||
|
loadMore: {
|
||||||
|
contentdown: '',
|
||||||
|
contentrefresh: '',
|
||||||
|
contentnomore: ''
|
||||||
|
},
|
||||||
|
dataList: [],
|
||||||
|
selected: [],
|
||||||
|
selectedIndex: 0,
|
||||||
|
page: {
|
||||||
|
current: this.pageCurrent,
|
||||||
|
size: this.pageSize,
|
||||||
|
count: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isLocalData() {
|
||||||
|
return !this.collection.length;
|
||||||
|
},
|
||||||
|
isCloudData() {
|
||||||
|
return this.collection.length > 0;
|
||||||
|
},
|
||||||
|
isCloudDataList() {
|
||||||
|
return (this.isCloudData && (!this.parentField && !this.selfField));
|
||||||
|
},
|
||||||
|
isCloudDataTree() {
|
||||||
|
return (this.isCloudData && this.parentField && this.selfField);
|
||||||
|
},
|
||||||
|
dataValue() {
|
||||||
|
let isModelValue = Array.isArray(this.modelValue) ? (this.modelValue.length > 0) : (this.modelValue !== null ||
|
||||||
|
this.modelValue !== undefined);
|
||||||
|
return isModelValue ? this.modelValue : this.value;
|
||||||
|
},
|
||||||
|
hasValue() {
|
||||||
|
if (typeof this.dataValue === 'number') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return (this.dataValue != null) && (this.dataValue.length > 0)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.$watch(() => {
|
||||||
|
var al = [];
|
||||||
|
['pageCurrent',
|
||||||
|
'pageSize',
|
||||||
|
'spaceInfo',
|
||||||
|
'value',
|
||||||
|
'modelValue',
|
||||||
|
'localdata',
|
||||||
|
'collection',
|
||||||
|
'action',
|
||||||
|
'field',
|
||||||
|
'orderby',
|
||||||
|
'where',
|
||||||
|
'getont',
|
||||||
|
'getcount',
|
||||||
|
'gettree'
|
||||||
|
].forEach(key => {
|
||||||
|
al.push(this[key])
|
||||||
|
});
|
||||||
|
return al
|
||||||
|
}, (newValue, oldValue) => {
|
||||||
|
let needReset = false
|
||||||
|
for (let i = 2; i < newValue.length; i++) {
|
||||||
|
if (newValue[i] != oldValue[i]) {
|
||||||
|
needReset = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newValue[0] != oldValue[0]) {
|
||||||
|
this.page.current = this.pageCurrent
|
||||||
|
}
|
||||||
|
this.page.size = this.pageSize
|
||||||
|
|
||||||
|
this.onPropsChange()
|
||||||
|
})
|
||||||
|
this._treeData = []
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPropsChange() {
|
||||||
|
this._treeData = [];
|
||||||
|
},
|
||||||
|
|
||||||
|
// 填充 pickview 数据
|
||||||
|
async loadData() {
|
||||||
|
if (this.isLocalData) {
|
||||||
|
this.loadLocalData();
|
||||||
|
} else if (this.isCloudDataList) {
|
||||||
|
this.loadCloudDataList();
|
||||||
|
} else if (this.isCloudDataTree) {
|
||||||
|
this.loadCloudDataTree();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载本地数据
|
||||||
|
async loadLocalData() {
|
||||||
|
this._treeData = [];
|
||||||
|
this._extractTree(this.localdata, this._treeData);
|
||||||
|
|
||||||
|
let inputValue = this.dataValue;
|
||||||
|
if (inputValue === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(inputValue)) {
|
||||||
|
inputValue = inputValue[inputValue.length - 1];
|
||||||
|
if (typeof inputValue === 'object' && inputValue[this.map.value]) {
|
||||||
|
inputValue = inputValue[this.map.value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selected = this._findNodePath(inputValue, this.localdata);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (单列)
|
||||||
|
async loadCloudDataList() {
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let response = await this.getCommand();
|
||||||
|
let responseData = response.result.data;
|
||||||
|
|
||||||
|
this._treeData = responseData;
|
||||||
|
|
||||||
|
this._updateBindData();
|
||||||
|
this._updateSelected();
|
||||||
|
|
||||||
|
this.onDataChange();
|
||||||
|
} catch (e) {
|
||||||
|
this.errorMessage = e;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (树形)
|
||||||
|
async loadCloudDataTree() {
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let commandOptions = {
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
where: this._cloudDataTreeWhere()
|
||||||
|
};
|
||||||
|
if (this.gettree) {
|
||||||
|
commandOptions.startwith = `${this.selfField}=='${this.dataValue}'`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let response = await this.getCommand(commandOptions);
|
||||||
|
let responseData = response.result.data;
|
||||||
|
|
||||||
|
this._treeData = responseData;
|
||||||
|
this._updateBindData();
|
||||||
|
this._updateSelected();
|
||||||
|
|
||||||
|
this.onDataChange();
|
||||||
|
} catch (e) {
|
||||||
|
this.errorMessage = e;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (节点)
|
||||||
|
async loadCloudDataNode(callback) {
|
||||||
|
if (this.loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let commandOptions = {
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
where: this._cloudDataNodeWhere()
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = await this.getCommand(commandOptions);
|
||||||
|
let responseData = response.result.data;
|
||||||
|
|
||||||
|
callback(responseData);
|
||||||
|
} catch (e) {
|
||||||
|
this.errorMessage = e;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 回显 Cloud 数据
|
||||||
|
getCloudDataValue() {
|
||||||
|
if (this.isCloudDataList) {
|
||||||
|
return this.getCloudDataListValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isCloudDataTree) {
|
||||||
|
return this.getCloudDataTreeValue();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 回显 Cloud 数据 (单列)
|
||||||
|
getCloudDataListValue() {
|
||||||
|
// 根据 field's as value标识匹配 where 条件
|
||||||
|
let where = [];
|
||||||
|
let whereField = this._getForeignKeyByField();
|
||||||
|
if (whereField) {
|
||||||
|
where.push(`${whereField} == '${this.dataValue}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
where = where.join(' || ');
|
||||||
|
|
||||||
|
if (this.where) {
|
||||||
|
where = `(${this.where}) && (${where})`
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.getCommand({
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
where
|
||||||
|
}).then((res) => {
|
||||||
|
this.selected = res.result.data;
|
||||||
|
return res.result.data;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 回显 Cloud 数据 (树形)
|
||||||
|
getCloudDataTreeValue() {
|
||||||
|
return this.getCommand({
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
getTreePath: {
|
||||||
|
startWith: `${this.selfField}=='${this.dataValue}'`
|
||||||
|
}
|
||||||
|
}).then((res) => {
|
||||||
|
let treePath = [];
|
||||||
|
this._extractTreePath(res.result.data, treePath);
|
||||||
|
this.selected = treePath;
|
||||||
|
return treePath;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
getCommand(options = {}) {
|
||||||
|
/* eslint-disable no-undef */
|
||||||
|
let db = uniCloud.database(this.spaceInfo)
|
||||||
|
|
||||||
|
const action = options.action || this.action
|
||||||
|
if (action) {
|
||||||
|
db = db.action(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
const collection = options.collection || this.collection
|
||||||
|
db = db.collection(collection)
|
||||||
|
|
||||||
|
const where = options.where || this.where
|
||||||
|
if (!(!where || !Object.keys(where).length)) {
|
||||||
|
db = db.where(where)
|
||||||
|
}
|
||||||
|
|
||||||
|
const field = options.field || this.field
|
||||||
|
if (field) {
|
||||||
|
db = db.field(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderby = options.orderby || this.orderby
|
||||||
|
if (orderby) {
|
||||||
|
db = db.orderBy(orderby)
|
||||||
|
}
|
||||||
|
|
||||||
|
const current = options.pageCurrent !== undefined ? options.pageCurrent : this.page.current
|
||||||
|
const size = options.pageSize !== undefined ? options.pageSize : this.page.size
|
||||||
|
const getCount = options.getcount !== undefined ? options.getcount : this.getcount
|
||||||
|
const getTree = options.gettree !== undefined ? options.gettree : this.gettree
|
||||||
|
|
||||||
|
const getOptions = {
|
||||||
|
getCount,
|
||||||
|
getTree
|
||||||
|
}
|
||||||
|
if (options.getTreePath) {
|
||||||
|
getOptions.getTreePath = options.getTreePath
|
||||||
|
}
|
||||||
|
|
||||||
|
db = db.skip(size * (current - 1)).limit(size).get(getOptions)
|
||||||
|
|
||||||
|
return db
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataPostField() {
|
||||||
|
let fields = [this.field];
|
||||||
|
if (this.parentField) {
|
||||||
|
fields.push(`${this.parentField} as parent_value`);
|
||||||
|
}
|
||||||
|
return fields.join(',');
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataTreeWhere() {
|
||||||
|
let result = []
|
||||||
|
let selected = this.selected
|
||||||
|
let parentField = this.parentField
|
||||||
|
if (parentField) {
|
||||||
|
result.push(`${parentField} == null || ${parentField} == ""`)
|
||||||
|
}
|
||||||
|
if (selected.length) {
|
||||||
|
for (var i = 0; i < selected.length - 1; i++) {
|
||||||
|
result.push(`${parentField} == '${selected[i].value}'`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let where = []
|
||||||
|
if (this.where) {
|
||||||
|
where.push(`(${this.where})`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length) {
|
||||||
|
where.push(`(${result.join(' || ')})`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return where.join(' && ')
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataNodeWhere() {
|
||||||
|
let where = []
|
||||||
|
let selected = this.selected;
|
||||||
|
if (selected.length) {
|
||||||
|
where.push(`${this.parentField} == '${selected[selected.length - 1].value}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
where = where.join(' || ');
|
||||||
|
|
||||||
|
if (this.where) {
|
||||||
|
return `(${this.where}) && (${where})`
|
||||||
|
}
|
||||||
|
|
||||||
|
return where
|
||||||
|
},
|
||||||
|
|
||||||
|
_getWhereByForeignKey() {
|
||||||
|
let result = []
|
||||||
|
let whereField = this._getForeignKeyByField();
|
||||||
|
if (whereField) {
|
||||||
|
result.push(`${whereField} == '${this.dataValue}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.where) {
|
||||||
|
return `(${this.where}) && (${result.join(' || ')})`
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(' || ')
|
||||||
|
},
|
||||||
|
|
||||||
|
_getForeignKeyByField() {
|
||||||
|
let fields = this.field.split(',');
|
||||||
|
let whereField = null;
|
||||||
|
for (let i = 0; i < fields.length; i++) {
|
||||||
|
const items = fields[i].split('as');
|
||||||
|
if (items.length < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (items[1].trim() === 'value') {
|
||||||
|
whereField = items[0].trim();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return whereField;
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateBindData(node) {
|
||||||
|
const {
|
||||||
|
dataList,
|
||||||
|
hasNodes
|
||||||
|
} = this._filterData(this._treeData, this.selected)
|
||||||
|
|
||||||
|
let isleaf = this._stepSearh === false && !hasNodes
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
node.isleaf = isleaf
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dataList = dataList
|
||||||
|
this.selectedIndex = dataList.length - 1
|
||||||
|
|
||||||
|
if (!isleaf && this.selected.length < dataList.length) {
|
||||||
|
this.selected.push({
|
||||||
|
value: null,
|
||||||
|
text: "请选择"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isleaf,
|
||||||
|
hasNodes
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateSelected() {
|
||||||
|
let dl = this.dataList
|
||||||
|
let sl = this.selected
|
||||||
|
let textField = this.map.text
|
||||||
|
let valueField = this.map.value
|
||||||
|
for (let i = 0; i < sl.length; i++) {
|
||||||
|
let value = sl[i].value
|
||||||
|
let dl2 = dl[i]
|
||||||
|
for (let j = 0; j < dl2.length; j++) {
|
||||||
|
let item2 = dl2[j]
|
||||||
|
if (item2[valueField] === value) {
|
||||||
|
sl[i].text = item2[textField]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_filterData(data, paths) {
|
||||||
|
let dataList = []
|
||||||
|
let hasNodes = true
|
||||||
|
|
||||||
|
dataList.push(data.filter((item) => {
|
||||||
|
return (item.parent_value === null || item.parent_value === undefined || item.parent_value === '')
|
||||||
|
}))
|
||||||
|
for (let i = 0; i < paths.length; i++) {
|
||||||
|
let value = paths[i].value
|
||||||
|
let nodes = data.filter((item) => {
|
||||||
|
return item.parent_value === value
|
||||||
|
})
|
||||||
|
|
||||||
|
if (nodes.length) {
|
||||||
|
dataList.push(nodes)
|
||||||
|
} else {
|
||||||
|
hasNodes = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
dataList,
|
||||||
|
hasNodes
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_extractTree(nodes, result, parent_value) {
|
||||||
|
let list = result || []
|
||||||
|
let valueField = this.map.value
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
let node = nodes[i]
|
||||||
|
|
||||||
|
let child = {}
|
||||||
|
for (let key in node) {
|
||||||
|
if (key !== 'children') {
|
||||||
|
child[key] = node[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (parent_value !== null && parent_value !== undefined && parent_value !== '') {
|
||||||
|
child.parent_value = parent_value
|
||||||
|
}
|
||||||
|
result.push(child)
|
||||||
|
|
||||||
|
let children = node.children
|
||||||
|
if (children) {
|
||||||
|
this._extractTree(children, result, node[valueField])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_extractTreePath(nodes, result) {
|
||||||
|
let list = result || []
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
let node = nodes[i]
|
||||||
|
|
||||||
|
let child = {}
|
||||||
|
for (let key in node) {
|
||||||
|
if (key !== 'children') {
|
||||||
|
child[key] = node[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push(child)
|
||||||
|
|
||||||
|
let children = node.children
|
||||||
|
if (children) {
|
||||||
|
this._extractTreePath(children, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_findNodePath(key, nodes, path = []) {
|
||||||
|
let textField = this.map.text
|
||||||
|
let valueField = this.map.value
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
let node = nodes[i]
|
||||||
|
let children = node.children
|
||||||
|
let text = node[textField]
|
||||||
|
let value = node[valueField]
|
||||||
|
|
||||||
|
path.push({
|
||||||
|
value,
|
||||||
|
text
|
||||||
|
})
|
||||||
|
|
||||||
|
if (value === key) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
if (children) {
|
||||||
|
const p = this._findNodePath(key, children, path)
|
||||||
|
if (p.length) {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path.pop()
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
693
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-picker.uts
generated
vendored
Normal file
693
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-picker.uts
generated
vendored
Normal file
@ -0,0 +1,693 @@
|
|||||||
|
export type PaginationType = {
|
||||||
|
current : number,
|
||||||
|
size : number,
|
||||||
|
count : number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type LoadMoreType = {
|
||||||
|
contentdown : string,
|
||||||
|
contentrefresh : string,
|
||||||
|
contentnomore : string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SelectedItemType = {
|
||||||
|
name : string,
|
||||||
|
value : string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GetCommandOptions = {
|
||||||
|
collection ?: UTSJSONObject,
|
||||||
|
field ?: string,
|
||||||
|
orderby ?: string,
|
||||||
|
where ?: any,
|
||||||
|
pageData ?: string,
|
||||||
|
pageCurrent ?: number,
|
||||||
|
pageSize ?: number,
|
||||||
|
getCount ?: boolean,
|
||||||
|
getTree ?: any,
|
||||||
|
getTreePath ?: UTSJSONObject,
|
||||||
|
startwith ?: string,
|
||||||
|
limitlevel ?: number,
|
||||||
|
groupby ?: string,
|
||||||
|
groupField ?: string,
|
||||||
|
distinct ?: boolean,
|
||||||
|
pageIndistinct ?: boolean,
|
||||||
|
foreignKey ?: string,
|
||||||
|
loadtime ?: string,
|
||||||
|
manual ?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const DefaultSelectedNode = {
|
||||||
|
text: '请选择',
|
||||||
|
value: ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export const dataPicker = defineMixin({
|
||||||
|
props: {
|
||||||
|
localdata: {
|
||||||
|
type: Array as PropType<Array<UTSJSONObject>>,
|
||||||
|
default: [] as Array<UTSJSONObject>
|
||||||
|
},
|
||||||
|
collection: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
field: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
orderby: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
pageData: {
|
||||||
|
type: String,
|
||||||
|
default: 'add'
|
||||||
|
},
|
||||||
|
pageCurrent: {
|
||||||
|
type: Number,
|
||||||
|
default: 1
|
||||||
|
},
|
||||||
|
pageSize: {
|
||||||
|
type: Number,
|
||||||
|
default: 20
|
||||||
|
},
|
||||||
|
getcount: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
gettree: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
gettreepath: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
startwith: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
limitlevel: {
|
||||||
|
type: Number,
|
||||||
|
default: 10
|
||||||
|
},
|
||||||
|
groupby: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
groupField: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
distinct: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
pageIndistinct: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
foreignKey: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
loadtime: {
|
||||||
|
type: String,
|
||||||
|
default: 'auto'
|
||||||
|
},
|
||||||
|
manual: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
preload: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
stepSearh: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
selfField: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
parentField: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: Object,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
defaultProps: {
|
||||||
|
type: Object as PropType<UTSJSONObject>,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
error: null as UniCloudError | null,
|
||||||
|
treeData: [] as Array<UTSJSONObject>,
|
||||||
|
selectedIndex: 0,
|
||||||
|
selectedNodes: [] as Array<UTSJSONObject>,
|
||||||
|
selectedPages: [] as Array<UTSJSONObject>[],
|
||||||
|
selectedValue: '',
|
||||||
|
selectedPaths: [] as Array<UTSJSONObject>,
|
||||||
|
pagination: {
|
||||||
|
current: 1,
|
||||||
|
size: 20,
|
||||||
|
count: 0
|
||||||
|
} as PaginationType
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
mappingTextName() : string {
|
||||||
|
// TODO
|
||||||
|
return (this.defaultProps != null) ? this.defaultProps!.getString('text', 'text') : 'text'
|
||||||
|
},
|
||||||
|
mappingValueName() : string {
|
||||||
|
// TODO
|
||||||
|
return (this.defaultProps != null) ? this.defaultProps!.getString('value', 'value') : 'value'
|
||||||
|
},
|
||||||
|
currentDataList() : Array<UTSJSONObject> {
|
||||||
|
if (this.selectedIndex > this.selectedPages.length - 1) {
|
||||||
|
return [] as Array<UTSJSONObject>
|
||||||
|
}
|
||||||
|
return this.selectedPages[this.selectedIndex]
|
||||||
|
},
|
||||||
|
isLocalData() : boolean {
|
||||||
|
return this.localdata.length > 0
|
||||||
|
},
|
||||||
|
isCloudData() : boolean {
|
||||||
|
return this._checkIsNotNull(this.collection)
|
||||||
|
},
|
||||||
|
isCloudDataList() : boolean {
|
||||||
|
return (this.isCloudData && (this.parentField.length == 0 && this.selfField.length == 0))
|
||||||
|
},
|
||||||
|
isCloudDataTree() : boolean {
|
||||||
|
return (this.isCloudData && this.parentField.length > 0 && this.selfField.length > 0)
|
||||||
|
},
|
||||||
|
dataValue() : any {
|
||||||
|
return this.hasModelValue ? this.modelValue : this.value
|
||||||
|
},
|
||||||
|
hasCloudTreeData() : boolean {
|
||||||
|
return this.treeData.length > 0
|
||||||
|
},
|
||||||
|
hasModelValue() : boolean {
|
||||||
|
if (typeof this.modelValue == 'string') {
|
||||||
|
const valueString = this.modelValue as string
|
||||||
|
return (valueString.length > 0)
|
||||||
|
} else if (Array.isArray(this.modelValue)) {
|
||||||
|
const valueArray = this.modelValue as Array<string>
|
||||||
|
return (valueArray.length > 0)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
hasCloudDataValue() : boolean {
|
||||||
|
if (typeof this.dataValue == 'string') {
|
||||||
|
const valueString = this.dataValue as string
|
||||||
|
return (valueString.length > 0)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.pagination.current = this.pageCurrent
|
||||||
|
this.pagination.size = this.pageSize
|
||||||
|
|
||||||
|
this.$watch(
|
||||||
|
() : any => [
|
||||||
|
this.pageCurrent,
|
||||||
|
this.pageSize,
|
||||||
|
this.localdata,
|
||||||
|
this.value,
|
||||||
|
this.collection,
|
||||||
|
this.field,
|
||||||
|
this.getcount,
|
||||||
|
this.orderby,
|
||||||
|
this.where,
|
||||||
|
this.groupby,
|
||||||
|
this.groupField,
|
||||||
|
this.distinct
|
||||||
|
],
|
||||||
|
(newValue : Array<any>, oldValue : Array<any>) => {
|
||||||
|
this.pagination.size = this.pageSize
|
||||||
|
if (newValue[0] !== oldValue[0]) {
|
||||||
|
this.pagination.current = this.pageCurrent
|
||||||
|
}
|
||||||
|
|
||||||
|
this.onPropsChange()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPropsChange() {
|
||||||
|
this.selectedIndex = 0
|
||||||
|
this.treeData.length = 0
|
||||||
|
this.selectedNodes.length = 0
|
||||||
|
this.selectedPages.length = 0
|
||||||
|
this.selectedPaths.length = 0
|
||||||
|
|
||||||
|
// 加载数据
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.loadData()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
onTabSelect(index : number) {
|
||||||
|
this.selectedIndex = index
|
||||||
|
},
|
||||||
|
|
||||||
|
onNodeClick(nodeData : UTSJSONObject) {
|
||||||
|
if (nodeData.getBoolean('disable', false)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLeaf = this._checkIsLeafNode(nodeData)
|
||||||
|
|
||||||
|
this._trimSelectedNodes(nodeData)
|
||||||
|
|
||||||
|
this.$emit('nodeclick', nodeData)
|
||||||
|
|
||||||
|
if (this.isLocalData) {
|
||||||
|
if (isLeaf || !this._checkHasChildren(nodeData)) {
|
||||||
|
this.onFinish()
|
||||||
|
}
|
||||||
|
} else if (this.isCloudDataList) {
|
||||||
|
this.onFinish()
|
||||||
|
} else if (this.isCloudDataTree) {
|
||||||
|
if (isLeaf) {
|
||||||
|
this.onFinish()
|
||||||
|
} else if (!this._checkHasChildren(nodeData)) {
|
||||||
|
// 尝试请求一次,如果没有返回数据标记为叶子节点
|
||||||
|
this.loadCloudDataNode(nodeData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getChangeNodes(): Array<UTSJSONObject> {
|
||||||
|
const nodes: Array<UTSJSONObject> = []
|
||||||
|
this.selectedNodes.forEach((node : UTSJSONObject) => {
|
||||||
|
const newNode: UTSJSONObject = {}
|
||||||
|
newNode[this.mappingTextName] = node.getString(this.mappingTextName)
|
||||||
|
newNode[this.mappingValueName] = node.getString(this.mappingValueName)
|
||||||
|
nodes.push(newNode)
|
||||||
|
})
|
||||||
|
return nodes
|
||||||
|
},
|
||||||
|
|
||||||
|
onFinish() { },
|
||||||
|
|
||||||
|
// 加载数据(自动判定环境)
|
||||||
|
loadData() {
|
||||||
|
if (this.isLocalData) {
|
||||||
|
this.loadLocalData()
|
||||||
|
} else if (this.isCloudDataList) {
|
||||||
|
this.loadCloudDataList()
|
||||||
|
} else if (this.isCloudDataTree) {
|
||||||
|
this.loadCloudDataTree()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载本地数据
|
||||||
|
loadLocalData() {
|
||||||
|
this.treeData = this.localdata
|
||||||
|
if (Array.isArray(this.dataValue)) {
|
||||||
|
const value = this.dataValue as Array<UTSJSONObject>
|
||||||
|
this.selectedPaths = value.slice(0)
|
||||||
|
this._pushSelectedTreeNodes(value, this.localdata)
|
||||||
|
} else {
|
||||||
|
this._pushSelectedNodes(this.localdata)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (单列)
|
||||||
|
loadCloudDataList() {
|
||||||
|
this._loadCloudData(null, (data : Array<UTSJSONObject>) => {
|
||||||
|
this.treeData = data
|
||||||
|
this._pushSelectedNodes(data)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (树形)
|
||||||
|
loadCloudDataTree() {
|
||||||
|
let commandOptions = {
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
where: this._cloudDataTreeWhere(),
|
||||||
|
getTree: true
|
||||||
|
} as GetCommandOptions
|
||||||
|
if (this._checkIsNotNull(this.gettree)) {
|
||||||
|
commandOptions.startwith = `${this.selfField}=='${this.dataValue as string}'`
|
||||||
|
}
|
||||||
|
this._loadCloudData(commandOptions, (data : Array<UTSJSONObject>) => {
|
||||||
|
this.treeData = data
|
||||||
|
if (this.selectedPaths.length > 0) {
|
||||||
|
this._pushSelectedTreeNodes(this.selectedPaths, data)
|
||||||
|
} else {
|
||||||
|
this._pushSelectedNodes(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 加载 Cloud 数据 (节点)
|
||||||
|
loadCloudDataNode(nodeData : UTSJSONObject) {
|
||||||
|
const commandOptions = {
|
||||||
|
field: this._cloudDataPostField(),
|
||||||
|
where: this._cloudDataNodeWhere()
|
||||||
|
} as GetCommandOptions
|
||||||
|
this._loadCloudData(commandOptions, (data : Array<UTSJSONObject>) => {
|
||||||
|
nodeData['children'] = data
|
||||||
|
if (data.length == 0) {
|
||||||
|
nodeData['isleaf'] = true
|
||||||
|
this.onFinish()
|
||||||
|
} else {
|
||||||
|
this._pushSelectedNodes(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 回显 Cloud Tree Path
|
||||||
|
loadCloudDataPath() {
|
||||||
|
if (!this.hasCloudDataValue) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const command : GetCommandOptions = {}
|
||||||
|
|
||||||
|
// 单列
|
||||||
|
if (this.isCloudDataList) {
|
||||||
|
// 根据 field's as value标识匹配 where 条件
|
||||||
|
let where : Array<string> = [];
|
||||||
|
let whereField = this._getForeignKeyByField();
|
||||||
|
if (whereField.length > 0) {
|
||||||
|
where.push(`${whereField} == '${this.dataValue as string}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
let whereString = where.join(' || ')
|
||||||
|
if (this._checkIsNotNull(this.where)) {
|
||||||
|
whereString = `(${this.where}) && (${whereString})`
|
||||||
|
}
|
||||||
|
|
||||||
|
command.field = this._cloudDataPostField()
|
||||||
|
command.where = whereString
|
||||||
|
}
|
||||||
|
|
||||||
|
// 树形
|
||||||
|
if (this.isCloudDataTree) {
|
||||||
|
command.field = this._cloudDataPostField()
|
||||||
|
command.getTreePath = {
|
||||||
|
startWith: `${this.selfField}=='${this.dataValue as string}'`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this._loadCloudData(command, (data : Array<UTSJSONObject>) => {
|
||||||
|
this._extractTreePath(data, this.selectedPaths)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
_loadCloudData(options ?: GetCommandOptions, callback ?: ((data : Array<UTSJSONObject>) => void)) {
|
||||||
|
if (this.loading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loading = true
|
||||||
|
|
||||||
|
this.error = null
|
||||||
|
|
||||||
|
this._getCommand(options).then((response : UniCloudDBGetResult) => {
|
||||||
|
callback?.(response.data)
|
||||||
|
}).catch((err : any | null) => {
|
||||||
|
this.error = err as UniCloudError
|
||||||
|
}).finally(() => {
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataPostField() : string {
|
||||||
|
let fields = [this.field];
|
||||||
|
if (this.parentField.length > 0) {
|
||||||
|
fields.push(`${this.parentField} as parent_value`)
|
||||||
|
}
|
||||||
|
return fields.join(',')
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataTreeWhere() : string {
|
||||||
|
let result : Array<string> = []
|
||||||
|
let selectedNodes = this.selectedNodes.length > 0 ? this.selectedNodes : this.selectedPaths
|
||||||
|
let parentField = this.parentField
|
||||||
|
if (parentField.length > 0) {
|
||||||
|
result.push(`${parentField} == null || ${parentField} == ""`)
|
||||||
|
}
|
||||||
|
if (selectedNodes.length > 0) {
|
||||||
|
for (var i = 0; i < selectedNodes.length - 1; i++) {
|
||||||
|
const parentFieldValue = selectedNodes[i].getString('value', '')
|
||||||
|
result.push(`${parentField} == '${parentFieldValue}'`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let where : Array<string> = []
|
||||||
|
if (this._checkIsNotNull(this.where)) {
|
||||||
|
where.push(`(${this.where as string})`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length > 0) {
|
||||||
|
where.push(`(${result.join(' || ')})`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return where.join(' && ')
|
||||||
|
},
|
||||||
|
|
||||||
|
_cloudDataNodeWhere() : string {
|
||||||
|
const where : Array<string> = []
|
||||||
|
if (this.selectedNodes.length > 0) {
|
||||||
|
const value = this.selectedNodes[this.selectedNodes.length - 1].getString('value', '')
|
||||||
|
where.push(`${this.parentField} == '${value}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
let whereString = where.join(' || ')
|
||||||
|
if (this._checkIsNotNull(this.where)) {
|
||||||
|
return `(${this.where as string}) && (${whereString})`
|
||||||
|
}
|
||||||
|
|
||||||
|
return whereString
|
||||||
|
},
|
||||||
|
|
||||||
|
_getWhereByForeignKey() : string {
|
||||||
|
let result : Array<string> = []
|
||||||
|
let whereField = this._getForeignKeyByField();
|
||||||
|
if (whereField.length > 0) {
|
||||||
|
result.push(`${whereField} == '${this.dataValue as string}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._checkIsNotNull(this.where)) {
|
||||||
|
return `(${this.where}) && (${result.join(' || ')})`
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(' || ')
|
||||||
|
},
|
||||||
|
|
||||||
|
_getForeignKeyByField() : string {
|
||||||
|
const fields = this.field.split(',')
|
||||||
|
let whereField = ''
|
||||||
|
for (let i = 0; i < fields.length; i++) {
|
||||||
|
const items = fields[i].split('as')
|
||||||
|
if (items.length < 2) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (items[1].trim() === 'value') {
|
||||||
|
whereField = items[0].trim()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return whereField
|
||||||
|
},
|
||||||
|
|
||||||
|
_getCommand(options ?: GetCommandOptions) : Promise<UniCloudDBGetResult> {
|
||||||
|
let db = uniCloud.databaseForJQL()
|
||||||
|
|
||||||
|
let collection = Array.isArray(this.collection) ? db.collection(...(this.collection as Array<any>)) : db.collection(this.collection)
|
||||||
|
|
||||||
|
let filter : UniCloudDBFilter | null = null
|
||||||
|
if (this.foreignKey.length > 0) {
|
||||||
|
filter = collection.foreignKey(this.foreignKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
const where : any = options?.where ?? this.where
|
||||||
|
if (typeof where == 'string') {
|
||||||
|
const whereString = where as string
|
||||||
|
if (whereString.length > 0) {
|
||||||
|
filter = (filter != null) ? filter.where(where) : collection.where(where)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
filter = (filter != null) ? filter.where(where) : collection.where(where)
|
||||||
|
}
|
||||||
|
|
||||||
|
let query : UniCloudDBQuery | null = null
|
||||||
|
if (this.field.length > 0) {
|
||||||
|
query = (filter != null) ? filter.field(this.field) : collection.field(this.field)
|
||||||
|
}
|
||||||
|
if (this.groupby.length > 0) {
|
||||||
|
if (query != null) {
|
||||||
|
query = query.groupBy(this.groupby)
|
||||||
|
} else if (filter != null) {
|
||||||
|
query = filter.groupBy(this.groupby)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.groupField.length > 0) {
|
||||||
|
if (query != null) {
|
||||||
|
query = query.groupField(this.groupField)
|
||||||
|
} else if (filter != null) {
|
||||||
|
query = filter.groupField(this.groupField)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.distinct == true) {
|
||||||
|
if (query != null) {
|
||||||
|
query = query.distinct(this.field)
|
||||||
|
} else if (filter != null) {
|
||||||
|
query = filter.distinct(this.field)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.orderby.length > 0) {
|
||||||
|
if (query != null) {
|
||||||
|
query = query.orderBy(this.orderby)
|
||||||
|
} else if (filter != null) {
|
||||||
|
query = filter.orderBy(this.orderby)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const size = this.pagination.size
|
||||||
|
const current = this.pagination.current
|
||||||
|
if (query != null) {
|
||||||
|
query = query.skip(size * (current - 1)).limit(size)
|
||||||
|
} else if (filter != null) {
|
||||||
|
query = filter.skip(size * (current - 1)).limit(size)
|
||||||
|
} else {
|
||||||
|
query = collection.skip(size * (current - 1)).limit(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getOptions = {}
|
||||||
|
const treeOptions = {
|
||||||
|
limitLevel: this.limitlevel,
|
||||||
|
startWith: this.startwith
|
||||||
|
}
|
||||||
|
if (this.getcount == true) {
|
||||||
|
getOptions['getCount'] = this.getcount
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTree : any = options?.getTree ?? this.gettree
|
||||||
|
if (typeof getTree == 'string') {
|
||||||
|
const getTreeString = getTree as string
|
||||||
|
if (getTreeString.length > 0) {
|
||||||
|
getOptions['getTree'] = treeOptions
|
||||||
|
}
|
||||||
|
} else if (typeof getTree == 'object') {
|
||||||
|
getOptions['getTree'] = treeOptions
|
||||||
|
} else {
|
||||||
|
getOptions['getTree'] = getTree
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTreePath = options?.getTreePath ?? this.gettreepath
|
||||||
|
if (typeof getTreePath == 'string') {
|
||||||
|
const getTreePathString = getTreePath as string
|
||||||
|
if (getTreePathString.length > 0) {
|
||||||
|
getOptions['getTreePath'] = getTreePath
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getOptions['getTreePath'] = getTreePath
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.get(getOptions)
|
||||||
|
},
|
||||||
|
|
||||||
|
_checkIsNotNull(value : any) : boolean {
|
||||||
|
if (typeof value == 'string') {
|
||||||
|
const valueString = value as string
|
||||||
|
return (valueString.length > 0)
|
||||||
|
} else if (value instanceof UTSJSONObject) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
|
_checkIsLeafNode(nodeData : UTSJSONObject) : boolean {
|
||||||
|
if (this.selectedIndex >= this.limitlevel) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nodeData.getBoolean('isleaf', false)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
|
_checkHasChildren(nodeData : UTSJSONObject) : boolean {
|
||||||
|
const children = nodeData.getArray('children') ?? ([] as Array<any>)
|
||||||
|
return children.length > 0
|
||||||
|
},
|
||||||
|
|
||||||
|
_pushSelectedNodes(nodes : Array<UTSJSONObject>) {
|
||||||
|
this.selectedNodes.push(DefaultSelectedNode)
|
||||||
|
this.selectedPages.push(nodes)
|
||||||
|
this.selectedIndex = this.selectedPages.length - 1
|
||||||
|
},
|
||||||
|
|
||||||
|
_trimSelectedNodes(nodeData : UTSJSONObject) {
|
||||||
|
this.selectedNodes.splice(this.selectedIndex)
|
||||||
|
this.selectedNodes.push(nodeData)
|
||||||
|
|
||||||
|
if (this.selectedPages.length > 0) {
|
||||||
|
this.selectedPages.splice(this.selectedIndex + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const children = nodeData.getArray<UTSJSONObject>('children') ?? ([] as Array<UTSJSONObject>)
|
||||||
|
if (children.length > 0) {
|
||||||
|
this.selectedNodes.push(DefaultSelectedNode)
|
||||||
|
this.selectedPages.push(children)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selectedIndex = this.selectedPages.length - 1
|
||||||
|
},
|
||||||
|
|
||||||
|
_pushSelectedTreeNodes(paths : Array<UTSJSONObject>, nodes : Array<UTSJSONObject>) {
|
||||||
|
let children : Array<UTSJSONObject> = nodes
|
||||||
|
paths.forEach((node : UTSJSONObject) => {
|
||||||
|
const findNode = children.find((item : UTSJSONObject) : boolean => {
|
||||||
|
return (item.getString(this.mappingValueName) == node.getString(this.mappingValueName))
|
||||||
|
})
|
||||||
|
if (findNode != null) {
|
||||||
|
this.selectedPages.push(children)
|
||||||
|
this.selectedNodes.push(node)
|
||||||
|
children = findNode.getArray<UTSJSONObject>('children') ?? ([] as Array<UTSJSONObject>)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.selectedIndex = this.selectedPages.length - 1
|
||||||
|
},
|
||||||
|
|
||||||
|
_extractTreePath(nodes : Array<UTSJSONObject>, result : Array<UTSJSONObject>) {
|
||||||
|
if (nodes.length == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = nodes[0]
|
||||||
|
result.push(node)
|
||||||
|
|
||||||
|
const children = node.getArray<UTSJSONObject>('children')
|
||||||
|
if (Array.isArray(children) && children!.length > 0) {
|
||||||
|
this._extractTreePath(children, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
76
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.css
generated
vendored
Normal file
76
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.css
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
.uni-data-pickerview {
|
||||||
|
position: relative;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-cover {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background-color: rgba(150, 150, 150, .1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
color: #DD524D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-node-list {
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-node-item {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 8px 10px 8px 10px;
|
||||||
|
border-bottom: 2px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-node-item-active {
|
||||||
|
color: #007aff;
|
||||||
|
border-bottom-color: #007aff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-view {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-item {
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 12px 15px;
|
||||||
|
border-bottom: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text {
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text-disabled {
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text-overflow {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.check {
|
||||||
|
margin-right: 5px;
|
||||||
|
border: 2px solid #007aff;
|
||||||
|
border-left: 0;
|
||||||
|
border-top: 0;
|
||||||
|
height: 12px;
|
||||||
|
width: 6px;
|
||||||
|
transform-origin: center;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
69
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.uvue
generated
vendored
Normal file
69
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.uvue
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-data-pickerview">
|
||||||
|
<view v-if="error!=null" class="error">
|
||||||
|
<text class="error-text">{{error!.errMsg}}</text>
|
||||||
|
</view>
|
||||||
|
<scroll-view v-if="!isCloudDataList" :scroll-x="true">
|
||||||
|
<view class="selected-node-list">
|
||||||
|
<template v-for="(item, index) in selectedNodes">
|
||||||
|
<text class="selected-node-item" :class="{'selected-node-item-active':index==selectedIndex}"
|
||||||
|
@click="onTabSelect(index)">
|
||||||
|
{{item[mappingTextName]}}
|
||||||
|
</text>
|
||||||
|
</template>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<list-view class="list-view" :scroll-y="true">
|
||||||
|
<list-item class="list-item" v-for="(item, _) in currentDataList" @click="onNodeClick(item)">
|
||||||
|
<text class="item-text" :class="{'item-text-disabled': item['disable']}">{{item[mappingTextName]}}</text>
|
||||||
|
<text class="check" v-if="item[mappingValueName] == selectedNodes[selectedIndex][mappingValueName]"></text>
|
||||||
|
</list-item>
|
||||||
|
</list-view>
|
||||||
|
<view class="loading-cover" v-if="loading">
|
||||||
|
<slot name="pickerview-loading" :loading="loading"></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { dataPicker } from "./uni-data-picker.uts"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataPickerview
|
||||||
|
* @description uni-data-pickerview
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3796
|
||||||
|
* @property {Array} localdata 本地数据,参考
|
||||||
|
* @property {Boolean} step-searh = [true|false] 是否分布查询
|
||||||
|
* @value true 启用分布查询,仅查询当前选中节点
|
||||||
|
* @value false 关闭分布查询,一次查询出所有数据
|
||||||
|
* @property {String|DBFieldString} self-field 分布查询当前字段名称
|
||||||
|
* @property {String|DBFieldString} parent-field 分布查询父字段名称
|
||||||
|
* @property {String|DBCollectionString} collection 表名
|
||||||
|
* @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
|
||||||
|
* @property {String} orderby 排序字段及正序倒叙设置
|
||||||
|
* @property {String|JQLString} where 查询条件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniDataPickerView',
|
||||||
|
emits: ['nodeclick', 'change', 'update:modelValue'],
|
||||||
|
mixins: [dataPicker],
|
||||||
|
props: {
|
||||||
|
ellipsis: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.loadData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onFinish() {
|
||||||
|
this.$emit('change', this.getChangeNodes())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
@import url("uni-data-pickerview.css");
|
||||||
|
</style>
|
||||||
323
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue
generated
vendored
Normal file
323
node_modules/@dcloudio/uni-ui/lib/uni-data-pickerview/uni-data-pickerview.vue
generated
vendored
Normal file
@ -0,0 +1,323 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-data-pickerview">
|
||||||
|
<scroll-view v-if="!isCloudDataList" class="selected-area" scroll-x="true">
|
||||||
|
<view class="selected-list">
|
||||||
|
<view
|
||||||
|
class="selected-item"
|
||||||
|
v-for="(item,index) in selected"
|
||||||
|
:key="index"
|
||||||
|
:class="{
|
||||||
|
'selected-item-active':index == selectedIndex
|
||||||
|
}"
|
||||||
|
@click="handleSelect(index)"
|
||||||
|
>
|
||||||
|
<text>{{item.text || ''}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
<view class="tab-c">
|
||||||
|
<scroll-view class="list" :scroll-y="true">
|
||||||
|
<view class="item" :class="{'is-disabled': !!item.disable}" v-for="(item, j) in dataList[selectedIndex]" :key="j"
|
||||||
|
@click="handleNodeClick(item, selectedIndex, j)">
|
||||||
|
<text class="item-text">{{item[map.text]}}</text>
|
||||||
|
<view class="check" v-if="selected.length > selectedIndex && item[map.value] == selected[selectedIndex].value"></view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
|
<view class="loading-cover" v-if="loading">
|
||||||
|
<uni-load-more class="load-more" :contentText="loadMore" status="loading"></uni-load-more>
|
||||||
|
</view>
|
||||||
|
<view class="error-message" v-if="errorMessage">
|
||||||
|
<text class="error-text">{{errorMessage}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import dataPicker from "./uni-data-picker.js"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataPickerview
|
||||||
|
* @description uni-data-pickerview
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3796
|
||||||
|
* @property {Array} localdata 本地数据,参考
|
||||||
|
* @property {Boolean} step-searh = [true|false] 是否分布查询
|
||||||
|
* @value true 启用分布查询,仅查询当前选中节点
|
||||||
|
* @value false 关闭分布查询,一次查询出所有数据
|
||||||
|
* @property {String|DBFieldString} self-field 分布查询当前字段名称
|
||||||
|
* @property {String|DBFieldString} parent-field 分布查询父字段名称
|
||||||
|
* @property {String|DBCollectionString} collection 表名
|
||||||
|
* @property {String|DBFieldString} field 查询字段,多个字段用 `,` 分割
|
||||||
|
* @property {String} orderby 排序字段及正序倒叙设置
|
||||||
|
* @property {String|JQLString} where 查询条件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniDataPickerView',
|
||||||
|
emits: ['nodeclick', 'change', 'datachange', 'update:modelValue'],
|
||||||
|
mixins: [dataPicker],
|
||||||
|
props: {
|
||||||
|
managedMode: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
ellipsis: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
if (!this.managedMode) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.loadData();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onPropsChange() {
|
||||||
|
this._treeData = [];
|
||||||
|
this.selectedIndex = 0;
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.loadData();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleSelect(index) {
|
||||||
|
this.selectedIndex = index;
|
||||||
|
},
|
||||||
|
handleNodeClick(item, i, j) {
|
||||||
|
if (item.disable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = this.dataList[i][j];
|
||||||
|
const text = node[this.map.text];
|
||||||
|
const value = node[this.map.value];
|
||||||
|
|
||||||
|
if (i < this.selected.length - 1) {
|
||||||
|
this.selected.splice(i, this.selected.length - i)
|
||||||
|
this.selected.push({
|
||||||
|
text,
|
||||||
|
value
|
||||||
|
})
|
||||||
|
} else if (i === this.selected.length - 1) {
|
||||||
|
this.selected.splice(i, 1, {
|
||||||
|
text,
|
||||||
|
value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.isleaf) {
|
||||||
|
this.onSelectedChange(node, node.isleaf)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
isleaf,
|
||||||
|
hasNodes
|
||||||
|
} = this._updateBindData()
|
||||||
|
|
||||||
|
// 本地数据
|
||||||
|
if (this.isLocalData) {
|
||||||
|
this.onSelectedChange(node, (!hasNodes || isleaf))
|
||||||
|
} else if (this.isCloudDataList) { // Cloud 数据 (单列)
|
||||||
|
this.onSelectedChange(node, true)
|
||||||
|
} else if (this.isCloudDataTree) { // Cloud 数据 (树形)
|
||||||
|
if (isleaf) {
|
||||||
|
this.onSelectedChange(node, node.isleaf)
|
||||||
|
} else if (!hasNodes) { // 请求一次服务器以确定是否为叶子节点
|
||||||
|
this.loadCloudDataNode((data) => {
|
||||||
|
if (!data.length) {
|
||||||
|
node.isleaf = true
|
||||||
|
} else {
|
||||||
|
this._treeData.push(...data)
|
||||||
|
this._updateBindData(node)
|
||||||
|
}
|
||||||
|
this.onSelectedChange(node, node.isleaf)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateData(data) {
|
||||||
|
this._treeData = data.treeData
|
||||||
|
this.selected = data.selected
|
||||||
|
if (!this._treeData.length) {
|
||||||
|
this.loadData()
|
||||||
|
} else {
|
||||||
|
//this.selected = data.selected
|
||||||
|
this._updateBindData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDataChange() {
|
||||||
|
this.$emit('datachange');
|
||||||
|
},
|
||||||
|
onSelectedChange(node, isleaf) {
|
||||||
|
if (isleaf) {
|
||||||
|
this._dispatchEvent()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
this.$emit('nodeclick', node)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_dispatchEvent() {
|
||||||
|
this.$emit('change', this.selected.slice(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-primary: #007aff !default;
|
||||||
|
|
||||||
|
.uni-data-pickerview {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
color: #DD524D;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-cover {
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(255, 255, 255, .5);
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1001;
|
||||||
|
}
|
||||||
|
|
||||||
|
.load-more {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
margin: auto;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.error-message {
|
||||||
|
background-color: #fff;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
padding: 15px;
|
||||||
|
opacity: .9;
|
||||||
|
z-index: 102;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
.selected-area {
|
||||||
|
width: 750rpx;
|
||||||
|
}
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
.selected-list {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
padding: 0 5px;
|
||||||
|
border-bottom: 1px solid #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 10px;
|
||||||
|
padding: 12px 0;
|
||||||
|
text-align: center;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
white-space: nowrap;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item-text-overflow {
|
||||||
|
width: 168px;
|
||||||
|
/* fix nvue */
|
||||||
|
overflow: hidden;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: 6em;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-o-text-overflow: ellipsis;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item-active {
|
||||||
|
border-bottom: 2px solid $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selected-item-text {
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-c {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
padding: 12px 15px;
|
||||||
|
/* border-bottom: 1px solid #f0f0f0; */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-disabled {
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text {
|
||||||
|
/* flex: 1; */
|
||||||
|
color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-text-overflow {
|
||||||
|
width: 280px;
|
||||||
|
/* fix nvue */
|
||||||
|
overflow: hidden;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: 20em;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-o-text-overflow: ellipsis;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.check {
|
||||||
|
margin-right: 5px;
|
||||||
|
border: 2px solid $uni-primary;
|
||||||
|
border-left: 0;
|
||||||
|
border-top: 0;
|
||||||
|
height: 12px;
|
||||||
|
width: 6px;
|
||||||
|
transform-origin: center;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
transition: all 0.3s;
|
||||||
|
/* #endif */
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
560
node_modules/@dcloudio/uni-ui/lib/uni-data-select/uni-data-select.vue
generated
vendored
Normal file
560
node_modules/@dcloudio/uni-ui/lib/uni-data-select/uni-data-select.vue
generated
vendored
Normal file
@ -0,0 +1,560 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-stat__select">
|
||||||
|
<span v-if="label" class="uni-label-text hide-on-phone">{{label + ':'}}</span>
|
||||||
|
<view class="uni-stat-box" :class="{'uni-stat__actived': current}">
|
||||||
|
<view class="uni-select" :class="{'uni-select--disabled':disabled}">
|
||||||
|
<view class="uni-select__input-box" @click="toggleSelector">
|
||||||
|
<view v-if="current" class="uni-select__input-text">{{textShow}}</view>
|
||||||
|
<view v-else class="uni-select__input-text uni-select__input-placeholder">{{typePlaceholder}}</view>
|
||||||
|
<view v-if="current && clear && !disabled" @click.stop="clearVal">
|
||||||
|
<uni-icons type="clear" color="#c0c4cc" size="24" />
|
||||||
|
</view>
|
||||||
|
<view v-else>
|
||||||
|
<uni-icons :type="showSelector? 'top' : 'bottom'" size="14" color="#999" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-select--mask" v-if="showSelector" @click="toggleSelector" />
|
||||||
|
<view class="uni-select__selector" :style="getOffsetByPlacement" v-if="showSelector">
|
||||||
|
<view :class="placement=='bottom'?'uni-popper__arrow_bottom':'uni-popper__arrow_top'"></view>
|
||||||
|
<scroll-view scroll-y="true" class="uni-select__selector-scroll">
|
||||||
|
<view class="uni-select__selector-empty" v-if="mixinDatacomResData.length === 0">
|
||||||
|
<text>{{emptyTips}}</text>
|
||||||
|
</view>
|
||||||
|
<view v-else class="uni-select__selector-item" v-for="(item,index) in mixinDatacomResData" :key="index"
|
||||||
|
@click="change(item)">
|
||||||
|
<text :class="{'uni-select__selector__disabled': item.disable}">{{formatItemName(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* DataChecklist 数据选择器
|
||||||
|
* @description 通过数据渲染的下拉框组件
|
||||||
|
* @tutorial https://uniapp.dcloud.io/component/uniui/uni-data-select
|
||||||
|
* @property {String} value 默认值
|
||||||
|
* @property {Array} localdata 本地数据 ,格式 [{text:'',value:''}]
|
||||||
|
* @property {Boolean} clear 是否可以清空已选项
|
||||||
|
* @property {Boolean} emptyText 没有数据时显示的文字 ,本地数据无效
|
||||||
|
* @property {String} label 左侧标题
|
||||||
|
* @property {String} placeholder 输入框的提示文字
|
||||||
|
* @property {Boolean} disabled 是否禁用
|
||||||
|
* @property {String} placement 弹出位置
|
||||||
|
* @value top 顶部弹出
|
||||||
|
* @value bottom 底部弹出(default)
|
||||||
|
* @event {Function} change 选中发生变化触发
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "uni-data-select",
|
||||||
|
mixins: [uniCloud.mixinDatacom || {}],
|
||||||
|
props: {
|
||||||
|
localdata: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: '请选择'
|
||||||
|
},
|
||||||
|
emptyTips: {
|
||||||
|
type: String,
|
||||||
|
default: '无选项'
|
||||||
|
},
|
||||||
|
clear: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
defItem: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
// 格式化输出 用法 field="_id as value, version as text, uni_platform as label" format="{label} - {text}"
|
||||||
|
format: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
placement: {
|
||||||
|
type: String,
|
||||||
|
default: 'bottom'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
showSelector: false,
|
||||||
|
current: '',
|
||||||
|
mixinDatacomResData: [],
|
||||||
|
apps: [],
|
||||||
|
channels: [],
|
||||||
|
cacheKey: "uni-data-select-lastSelectedValue",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.debounceGet = this.debounce(() => {
|
||||||
|
this.query();
|
||||||
|
}, 300);
|
||||||
|
if (this.collection && !this.localdata.length) {
|
||||||
|
this.debounceGet();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
typePlaceholder() {
|
||||||
|
const text = {
|
||||||
|
'opendb-stat-app-versions': '版本',
|
||||||
|
'opendb-app-channels': '渠道',
|
||||||
|
'opendb-app-list': '应用'
|
||||||
|
}
|
||||||
|
const common = this.placeholder
|
||||||
|
const placeholder = text[this.collection]
|
||||||
|
return placeholder ?
|
||||||
|
common + placeholder :
|
||||||
|
common
|
||||||
|
},
|
||||||
|
valueCom() {
|
||||||
|
// #ifdef VUE3
|
||||||
|
return this.modelValue;
|
||||||
|
// #endif
|
||||||
|
// #ifndef VUE3
|
||||||
|
return this.value;
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
textShow() {
|
||||||
|
// 长文本显示
|
||||||
|
let text = this.current;
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
getOffsetByPlacement() {
|
||||||
|
switch (this.placement) {
|
||||||
|
case 'top':
|
||||||
|
return "bottom:calc(100% + 12px);";
|
||||||
|
case 'bottom':
|
||||||
|
return "top:calc(100% + 12px);";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
localdata: {
|
||||||
|
immediate: true,
|
||||||
|
handler(val, old) {
|
||||||
|
if (Array.isArray(val) && old !== val) {
|
||||||
|
this.mixinDatacomResData = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
valueCom(val, old) {
|
||||||
|
this.initDefVal()
|
||||||
|
},
|
||||||
|
mixinDatacomResData: {
|
||||||
|
immediate: true,
|
||||||
|
handler(val) {
|
||||||
|
if (val.length) {
|
||||||
|
this.initDefVal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
debounce(fn, time = 100) {
|
||||||
|
let timer = null
|
||||||
|
return function(...args) {
|
||||||
|
if (timer) clearTimeout(timer)
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
fn.apply(this, args)
|
||||||
|
}, time)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 执行数据库查询
|
||||||
|
query() {
|
||||||
|
this.mixinDatacomEasyGet();
|
||||||
|
},
|
||||||
|
// 监听查询条件变更事件
|
||||||
|
onMixinDatacomPropsChange() {
|
||||||
|
if (this.collection) {
|
||||||
|
this.debounceGet();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
initDefVal() {
|
||||||
|
let defValue = ''
|
||||||
|
if ((this.valueCom || this.valueCom === 0) && !this.isDisabled(this.valueCom)) {
|
||||||
|
defValue = this.valueCom
|
||||||
|
} else {
|
||||||
|
let strogeValue
|
||||||
|
if (this.collection) {
|
||||||
|
strogeValue = this.getCache()
|
||||||
|
}
|
||||||
|
if (strogeValue || strogeValue === 0) {
|
||||||
|
defValue = strogeValue
|
||||||
|
} else {
|
||||||
|
let defItem = ''
|
||||||
|
if (this.defItem > 0 && this.defItem <= this.mixinDatacomResData.length) {
|
||||||
|
defItem = this.mixinDatacomResData[this.defItem - 1].value
|
||||||
|
}
|
||||||
|
defValue = defItem
|
||||||
|
}
|
||||||
|
if (defValue || defValue === 0) {
|
||||||
|
this.emit(defValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const def = this.mixinDatacomResData.find(item => item.value === defValue)
|
||||||
|
this.current = def ? this.formatItemName(def) : ''
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {[String, Number]} value
|
||||||
|
* 判断用户给的 value 是否同时为禁用状态
|
||||||
|
*/
|
||||||
|
isDisabled(value) {
|
||||||
|
let isDisabled = false;
|
||||||
|
|
||||||
|
this.mixinDatacomResData.forEach(item => {
|
||||||
|
if (item.value === value) {
|
||||||
|
isDisabled = item.disable
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return isDisabled;
|
||||||
|
},
|
||||||
|
|
||||||
|
clearVal() {
|
||||||
|
this.emit('')
|
||||||
|
if (this.collection) {
|
||||||
|
this.removeCache()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
change(item) {
|
||||||
|
if (!item.disable) {
|
||||||
|
this.showSelector = false
|
||||||
|
this.current = this.formatItemName(item)
|
||||||
|
this.emit(item.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emit(val) {
|
||||||
|
this.$emit('input', val)
|
||||||
|
this.$emit('update:modelValue', val)
|
||||||
|
this.$emit('change', val)
|
||||||
|
if (this.collection) {
|
||||||
|
this.setCache(val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleSelector() {
|
||||||
|
if (this.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showSelector = !this.showSelector
|
||||||
|
},
|
||||||
|
formatItemName(item) {
|
||||||
|
let {
|
||||||
|
text,
|
||||||
|
value,
|
||||||
|
channel_code
|
||||||
|
} = item
|
||||||
|
channel_code = channel_code ? `(${channel_code})` : ''
|
||||||
|
|
||||||
|
if (this.format) {
|
||||||
|
// 格式化输出
|
||||||
|
let str = "";
|
||||||
|
str = this.format;
|
||||||
|
for (let key in item) {
|
||||||
|
str = str.replace(new RegExp(`{${key}}`, "g"), item[key]);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
} else {
|
||||||
|
return this.collection.indexOf('app-list') > 0 ?
|
||||||
|
`${text}(${value})` :
|
||||||
|
(
|
||||||
|
text ?
|
||||||
|
text :
|
||||||
|
`未命名${channel_code}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 获取当前加载的数据
|
||||||
|
getLoadData() {
|
||||||
|
return this.mixinDatacomResData;
|
||||||
|
},
|
||||||
|
// 获取当前缓存key
|
||||||
|
getCurrentCacheKey() {
|
||||||
|
return this.collection;
|
||||||
|
},
|
||||||
|
// 获取缓存
|
||||||
|
getCache(name = this.getCurrentCacheKey()) {
|
||||||
|
let cacheData = uni.getStorageSync(this.cacheKey) || {};
|
||||||
|
return cacheData[name];
|
||||||
|
},
|
||||||
|
// 设置缓存
|
||||||
|
setCache(value, name = this.getCurrentCacheKey()) {
|
||||||
|
let cacheData = uni.getStorageSync(this.cacheKey) || {};
|
||||||
|
cacheData[name] = value;
|
||||||
|
uni.setStorageSync(this.cacheKey, cacheData);
|
||||||
|
},
|
||||||
|
// 删除缓存
|
||||||
|
removeCache(name = this.getCurrentCacheKey()) {
|
||||||
|
let cacheData = uni.getStorageSync(this.cacheKey) || {};
|
||||||
|
delete cacheData[name];
|
||||||
|
uni.setStorageSync(this.cacheKey, cacheData);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-base-color: #6a6a6a !default;
|
||||||
|
$uni-main-color: #333 !default;
|
||||||
|
$uni-secondary-color: #909399 !default;
|
||||||
|
$uni-border-3: #e5e5e5;
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
@media screen and (max-width: 500px) {
|
||||||
|
.hide-on-phone {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
.uni-stat__select {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
// padding: 15px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-stat-box {
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-stat__actived {
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
// outline: 1px solid #2979ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-label-text {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: $uni-base-color;
|
||||||
|
margin: auto 0;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select {
|
||||||
|
font-size: 14px;
|
||||||
|
border: 1px solid $uni-border-3;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0 5px;
|
||||||
|
padding-left: 10px;
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
user-select: none;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
border-bottom: solid 1px $uni-border-3;
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
height: 35px;
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__label {
|
||||||
|
font-size: 16px;
|
||||||
|
// line-height: 22px;
|
||||||
|
height: 35px;
|
||||||
|
padding-right: 10px;
|
||||||
|
color: $uni-secondary-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__input-box {
|
||||||
|
height: 35px;
|
||||||
|
width: 0px;
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__input {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 14px;
|
||||||
|
height: 22px;
|
||||||
|
line-height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__input-plac {
|
||||||
|
font-size: 14px;
|
||||||
|
color: $uni-secondary-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__selector {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #FFFFFF;
|
||||||
|
border: 1px solid #EBEEF5;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
z-index: 3;
|
||||||
|
padding: 4px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__selector-scroll {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
max-height: 200px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef H5 */
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.uni-select__selector-scroll {
|
||||||
|
max-height: 600px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
.uni-select__selector-empty,
|
||||||
|
.uni-select__selector-item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
line-height: 35px;
|
||||||
|
font-size: 14px;
|
||||||
|
text-align: center;
|
||||||
|
/* border-bottom: solid 1px $uni-border-3; */
|
||||||
|
padding: 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__selector-item:hover {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__selector-empty:last-child,
|
||||||
|
.uni-select__selector-item:last-child {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
border-bottom: none;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__selector__disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* picker 弹出层通用的指示小三角 */
|
||||||
|
.uni-popper__arrow_bottom,
|
||||||
|
.uni-popper__arrow_bottom::after,
|
||||||
|
.uni-popper__arrow_top,
|
||||||
|
.uni-popper__arrow_top::after,
|
||||||
|
{
|
||||||
|
position: absolute;
|
||||||
|
display: block;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
border-color: transparent;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow_bottom {
|
||||||
|
filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
|
||||||
|
top: -6px;
|
||||||
|
left: 10%;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #EBEEF5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow_bottom::after {
|
||||||
|
content: " ";
|
||||||
|
top: 1px;
|
||||||
|
margin-left: -6px;
|
||||||
|
border-top-width: 0;
|
||||||
|
border-bottom-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow_top {
|
||||||
|
filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
|
||||||
|
bottom: -6px;
|
||||||
|
left: 10%;
|
||||||
|
margin-right: 3px;
|
||||||
|
border-bottom-width: 0;
|
||||||
|
border-top-color: #EBEEF5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-popper__arrow_top::after {
|
||||||
|
content: " ";
|
||||||
|
bottom: 1px;
|
||||||
|
margin-left: -6px;
|
||||||
|
border-bottom-width: 0;
|
||||||
|
border-top-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-select__input-text {
|
||||||
|
// width: 280px;
|
||||||
|
width: 100%;
|
||||||
|
color: $uni-main-color;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-o-text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select__input-placeholder {
|
||||||
|
color: $uni-base-color;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-select--mask {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
200
node_modules/@dcloudio/uni-ui/lib/uni-dateformat/date-format.js
generated
vendored
Normal file
200
node_modules/@dcloudio/uni-ui/lib/uni-dateformat/date-format.js
generated
vendored
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
// yyyy-MM-dd hh:mm:ss.SSS 所有支持的类型
|
||||||
|
function pad(str, length = 2) {
|
||||||
|
str += ''
|
||||||
|
while (str.length < length) {
|
||||||
|
str = '0' + str
|
||||||
|
}
|
||||||
|
return str.slice(-length)
|
||||||
|
}
|
||||||
|
|
||||||
|
const parser = {
|
||||||
|
yyyy: (dateObj) => {
|
||||||
|
return pad(dateObj.year, 4)
|
||||||
|
},
|
||||||
|
yy: (dateObj) => {
|
||||||
|
return pad(dateObj.year)
|
||||||
|
},
|
||||||
|
MM: (dateObj) => {
|
||||||
|
return pad(dateObj.month)
|
||||||
|
},
|
||||||
|
M: (dateObj) => {
|
||||||
|
return dateObj.month
|
||||||
|
},
|
||||||
|
dd: (dateObj) => {
|
||||||
|
return pad(dateObj.day)
|
||||||
|
},
|
||||||
|
d: (dateObj) => {
|
||||||
|
return dateObj.day
|
||||||
|
},
|
||||||
|
hh: (dateObj) => {
|
||||||
|
return pad(dateObj.hour)
|
||||||
|
},
|
||||||
|
h: (dateObj) => {
|
||||||
|
return dateObj.hour
|
||||||
|
},
|
||||||
|
mm: (dateObj) => {
|
||||||
|
return pad(dateObj.minute)
|
||||||
|
},
|
||||||
|
m: (dateObj) => {
|
||||||
|
return dateObj.minute
|
||||||
|
},
|
||||||
|
ss: (dateObj) => {
|
||||||
|
return pad(dateObj.second)
|
||||||
|
},
|
||||||
|
s: (dateObj) => {
|
||||||
|
return dateObj.second
|
||||||
|
},
|
||||||
|
SSS: (dateObj) => {
|
||||||
|
return pad(dateObj.millisecond, 3)
|
||||||
|
},
|
||||||
|
S: (dateObj) => {
|
||||||
|
return dateObj.millisecond
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 这都n年了iOS依然不认识2020-12-12,需要转换为2020/12/12
|
||||||
|
function getDate(time) {
|
||||||
|
if (time instanceof Date) {
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
switch (typeof time) {
|
||||||
|
case 'string':
|
||||||
|
{
|
||||||
|
// 2020-12-12T12:12:12.000Z、2020-12-12T12:12:12.000
|
||||||
|
if (time.indexOf('T') > -1) {
|
||||||
|
return new Date(time)
|
||||||
|
}
|
||||||
|
return new Date(time.replace(/-/g, '/'))
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return new Date(time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(date, format = 'yyyy/MM/dd hh:mm:ss') {
|
||||||
|
if (!date && date !== 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
date = getDate(date)
|
||||||
|
const dateObj = {
|
||||||
|
year: date.getFullYear(),
|
||||||
|
month: date.getMonth() + 1,
|
||||||
|
day: date.getDate(),
|
||||||
|
hour: date.getHours(),
|
||||||
|
minute: date.getMinutes(),
|
||||||
|
second: date.getSeconds(),
|
||||||
|
millisecond: date.getMilliseconds()
|
||||||
|
}
|
||||||
|
const tokenRegExp = /yyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S/
|
||||||
|
let flag = true
|
||||||
|
let result = format
|
||||||
|
while (flag) {
|
||||||
|
flag = false
|
||||||
|
result = result.replace(tokenRegExp, function(matched) {
|
||||||
|
flag = true
|
||||||
|
return parser[matched](dateObj)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export function friendlyDate(time, {
|
||||||
|
locale = 'zh',
|
||||||
|
threshold = [60000, 3600000],
|
||||||
|
format = 'yyyy/MM/dd hh:mm:ss'
|
||||||
|
}) {
|
||||||
|
if (time === '-') {
|
||||||
|
return time
|
||||||
|
}
|
||||||
|
if (!time && time !== 0) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
const localeText = {
|
||||||
|
zh: {
|
||||||
|
year: '年',
|
||||||
|
month: '月',
|
||||||
|
day: '天',
|
||||||
|
hour: '小时',
|
||||||
|
minute: '分钟',
|
||||||
|
second: '秒',
|
||||||
|
ago: '前',
|
||||||
|
later: '后',
|
||||||
|
justNow: '刚刚',
|
||||||
|
soon: '马上',
|
||||||
|
template: '{num}{unit}{suffix}'
|
||||||
|
},
|
||||||
|
en: {
|
||||||
|
year: 'year',
|
||||||
|
month: 'month',
|
||||||
|
day: 'day',
|
||||||
|
hour: 'hour',
|
||||||
|
minute: 'minute',
|
||||||
|
second: 'second',
|
||||||
|
ago: 'ago',
|
||||||
|
later: 'later',
|
||||||
|
justNow: 'just now',
|
||||||
|
soon: 'soon',
|
||||||
|
template: '{num} {unit} {suffix}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const text = localeText[locale] || localeText.zh
|
||||||
|
let date = getDate(time)
|
||||||
|
let ms = date.getTime() - Date.now()
|
||||||
|
let absMs = Math.abs(ms)
|
||||||
|
if (absMs < threshold[0]) {
|
||||||
|
return ms < 0 ? text.justNow : text.soon
|
||||||
|
}
|
||||||
|
if (absMs >= threshold[1]) {
|
||||||
|
return formatDate(date, format)
|
||||||
|
}
|
||||||
|
let num
|
||||||
|
let unit
|
||||||
|
let suffix = text.later
|
||||||
|
if (ms < 0) {
|
||||||
|
suffix = text.ago
|
||||||
|
ms = -ms
|
||||||
|
}
|
||||||
|
const seconds = Math.floor((ms) / 1000)
|
||||||
|
const minutes = Math.floor(seconds / 60)
|
||||||
|
const hours = Math.floor(minutes / 60)
|
||||||
|
const days = Math.floor(hours / 24)
|
||||||
|
const months = Math.floor(days / 30)
|
||||||
|
const years = Math.floor(months / 12)
|
||||||
|
switch (true) {
|
||||||
|
case years > 0:
|
||||||
|
num = years
|
||||||
|
unit = text.year
|
||||||
|
break
|
||||||
|
case months > 0:
|
||||||
|
num = months
|
||||||
|
unit = text.month
|
||||||
|
break
|
||||||
|
case days > 0:
|
||||||
|
num = days
|
||||||
|
unit = text.day
|
||||||
|
break
|
||||||
|
case hours > 0:
|
||||||
|
num = hours
|
||||||
|
unit = text.hour
|
||||||
|
break
|
||||||
|
case minutes > 0:
|
||||||
|
num = minutes
|
||||||
|
unit = text.minute
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
num = seconds
|
||||||
|
unit = text.second
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (locale === 'en') {
|
||||||
|
if (num === 1) {
|
||||||
|
num = 'a'
|
||||||
|
} else {
|
||||||
|
unit += 's'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.template.replace(/{\s*num\s*}/g, num + '').replace(/{\s*unit\s*}/g, unit).replace(/{\s*suffix\s*}/g,
|
||||||
|
suffix)
|
||||||
|
}
|
||||||
88
node_modules/@dcloudio/uni-ui/lib/uni-dateformat/uni-dateformat.vue
generated
vendored
Normal file
88
node_modules/@dcloudio/uni-ui/lib/uni-dateformat/uni-dateformat.vue
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<template>
|
||||||
|
<text>{{dateShow}}</text>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {friendlyDate} from './date-format.js'
|
||||||
|
/**
|
||||||
|
* Dateformat 日期格式化
|
||||||
|
* @description 日期格式化组件
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3279
|
||||||
|
* @property {Object|String|Number} date 日期对象/日期字符串/时间戳
|
||||||
|
* @property {String} locale 格式化使用的语言
|
||||||
|
* @value zh 中文
|
||||||
|
* @value en 英文
|
||||||
|
* @property {Array} threshold 应用不同类型格式化的阈值
|
||||||
|
* @property {String} format 输出日期字符串时的格式
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniDateformat',
|
||||||
|
props: {
|
||||||
|
date: {
|
||||||
|
type: [Object, String, Number],
|
||||||
|
default () {
|
||||||
|
return '-'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
locale: {
|
||||||
|
type: String,
|
||||||
|
default: 'zh',
|
||||||
|
},
|
||||||
|
threshold: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return [0, 0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
format: {
|
||||||
|
type: String,
|
||||||
|
default: 'yyyy/MM/dd hh:mm:ss'
|
||||||
|
},
|
||||||
|
// refreshRate使用不当可能导致性能问题,谨慎使用
|
||||||
|
refreshRate: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
refreshMark: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
dateShow() {
|
||||||
|
this.refreshMark
|
||||||
|
return friendlyDate(this.date, {
|
||||||
|
locale: this.locale,
|
||||||
|
threshold: this.threshold,
|
||||||
|
format: this.format
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
refreshRate: {
|
||||||
|
handler() {
|
||||||
|
this.setAutoRefresh()
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
refresh() {
|
||||||
|
this.refreshMark++
|
||||||
|
},
|
||||||
|
setAutoRefresh() {
|
||||||
|
clearInterval(this.refreshInterval)
|
||||||
|
if (this.refreshRate) {
|
||||||
|
this.refreshInterval = setInterval(() => {
|
||||||
|
this.refresh()
|
||||||
|
}, parseInt(this.refreshRate))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
177
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/calendar-item.vue
generated
vendored
Normal file
177
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/calendar-item.vue
generated
vendored
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-calendar-item__weeks-box" :class="{
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
'uni-calendar-item--before-checked-x':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked-x':weeks.afterMultiple,
|
||||||
|
}" @click="choiceDate(weeks)" @mouseenter="handleMousemove(weeks)">
|
||||||
|
<view class="uni-calendar-item__weeks-box-item" :class="{
|
||||||
|
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && (calendar.userChecked || !checkHover),
|
||||||
|
'uni-calendar-item--checked-range-text': checkHover,
|
||||||
|
'uni-calendar-item--before-checked':weeks.beforeMultiple,
|
||||||
|
'uni-calendar-item--multiple': weeks.multiple,
|
||||||
|
'uni-calendar-item--after-checked':weeks.afterMultiple,
|
||||||
|
'uni-calendar-item--disable':weeks.disable,
|
||||||
|
}">
|
||||||
|
<text v-if="selected && weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
|
||||||
|
<text class="uni-calendar-item__weeks-box-text uni-calendar-item__weeks-box-text-disable uni-calendar-item--checked-text">{{weeks.date}}</text>
|
||||||
|
</view>
|
||||||
|
<view :class="{'uni-calendar-item--today': weeks.isToday}"></view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
weeks: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
calendar: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selected: {
|
||||||
|
type: Array,
|
||||||
|
default: () => {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
checkHover: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
choiceDate(weeks) {
|
||||||
|
this.$emit('change', weeks)
|
||||||
|
},
|
||||||
|
handleMousemove(weeks) {
|
||||||
|
this.$emit('handleMouse', weeks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" >
|
||||||
|
$uni-primary: #007aff !default;
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
margin: 1px 0;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-text {
|
||||||
|
font-size: 14px;
|
||||||
|
// font-family: Lato-Bold, Lato;
|
||||||
|
font-weight: bold;
|
||||||
|
color: darken($color: $uni-primary, $amount: 40%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-item {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box-circle {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
right: 5px;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background-color: #dd524d;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box .uni-calendar-item--disable {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--disable .uni-calendar-item__weeks-box-text-disable {
|
||||||
|
color: #D1D1D1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--today {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 17%;
|
||||||
|
background-color: #dd524d;
|
||||||
|
width:6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--extra {
|
||||||
|
color: #dd524d;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item__weeks-box .uni-calendar-item--checked {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
border-radius: 50%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 3px solid #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--checked .uni-calendar-item--checked-text {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--multiple .uni-calendar-item--checked-range-text {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--multiple {
|
||||||
|
background-color: #F6F7FC;
|
||||||
|
// color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--multiple .uni-calendar-item--before-checked,
|
||||||
|
.uni-calendar-item--multiple .uni-calendar-item--after-checked {
|
||||||
|
background-color: $uni-primary;
|
||||||
|
border-radius: 50%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 3px solid #F6F7FC;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--before-checked .uni-calendar-item--checked-text,
|
||||||
|
.uni-calendar-item--after-checked .uni-calendar-item--checked-text {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--before-checked-x {
|
||||||
|
border-top-left-radius: 50px;
|
||||||
|
border-bottom-left-radius: 50px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background-color: #F6F7FC;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar-item--after-checked-x {
|
||||||
|
border-top-right-radius: 50px;
|
||||||
|
border-bottom-right-radius: 50px;
|
||||||
|
background-color: #F6F7FC;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
947
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/calendar.vue
generated
vendored
Normal file
947
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/calendar.vue
generated
vendored
Normal file
@ -0,0 +1,947 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-calendar" @mouseleave="leaveCale">
|
||||||
|
|
||||||
|
<view v-if="!insert && show" class="uni-calendar__mask" :class="{'uni-calendar--mask-show':aniMaskShow}"
|
||||||
|
@click="maskClick"></view>
|
||||||
|
|
||||||
|
<view v-if="insert || show" class="uni-calendar__content"
|
||||||
|
:class="{'uni-calendar--fixed':!insert,'uni-calendar--ani-show':aniMaskShow, 'uni-calendar__content-mobile': aniMaskShow}">
|
||||||
|
<view class="uni-calendar__header" :class="{'uni-calendar__header-mobile' :!insert}">
|
||||||
|
|
||||||
|
<view class="uni-calendar__header-btn-box" @click.stop="changeMonth('pre')">
|
||||||
|
<view class="uni-calendar__header-btn uni-calendar--left"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<picker mode="date" :value="date" fields="month" @change="bindDateChange">
|
||||||
|
<text
|
||||||
|
class="uni-calendar__header-text">{{ (nowDate.year||'') + yearText + ( nowDate.month||'') + monthText}}</text>
|
||||||
|
</picker>
|
||||||
|
|
||||||
|
<view class="uni-calendar__header-btn-box" @click.stop="changeMonth('next')">
|
||||||
|
<view class="uni-calendar__header-btn uni-calendar--right"></view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-if="!insert" class="dialog-close" @click="maskClick">
|
||||||
|
<view class="dialog-close-plus" data-id="close"></view>
|
||||||
|
<view class="dialog-close-plus dialog-close-rotate" data-id="close"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__box">
|
||||||
|
|
||||||
|
<view v-if="showMonth" class="uni-calendar__box-bg">
|
||||||
|
<text class="uni-calendar__box-bg-text">{{nowDate.month}}</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="uni-calendar__weeks" style="padding-bottom: 7px;">
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{SUNText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{MONText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{TUEText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{WEDText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{THUText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{FRIText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-calendar__weeks-day">
|
||||||
|
<text class="uni-calendar__weeks-day-text">{{SATText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
|
||||||
|
<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
|
||||||
|
<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected"
|
||||||
|
:checkHover="range" @change="choiceDate" @handleMouse="handleMouse">
|
||||||
|
</calendar-item>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-if="!insert && !range && hasTime" class="uni-date-changed uni-calendar--fixed-top"
|
||||||
|
style="padding: 0 80px;">
|
||||||
|
<view class="uni-date-changed--time-date">{{tempSingleDate ? tempSingleDate : selectDateText}}</view>
|
||||||
|
<time-picker type="time" :start="timepickerStartTime" :end="timepickerEndTime" v-model="time"
|
||||||
|
:disabled="!tempSingleDate" :border="false" :hide-second="hideSecond" class="time-picker-style">
|
||||||
|
</time-picker>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-if="!insert && range && hasTime" class="uni-date-changed uni-calendar--fixed-top">
|
||||||
|
<view class="uni-date-changed--time-start">
|
||||||
|
<view class="uni-date-changed--time-date">{{tempRange.before ? tempRange.before : startDateText}}
|
||||||
|
</view>
|
||||||
|
<time-picker type="time" :start="timepickerStartTime" v-model="timeRange.startTime" :border="false"
|
||||||
|
:hide-second="hideSecond" :disabled="!tempRange.before" class="time-picker-style">
|
||||||
|
</time-picker>
|
||||||
|
</view>
|
||||||
|
<view style="line-height: 50px;">
|
||||||
|
<uni-icons type="arrowthinright" color="#999"></uni-icons>
|
||||||
|
</view>
|
||||||
|
<view class="uni-date-changed--time-end">
|
||||||
|
<view class="uni-date-changed--time-date">{{tempRange.after ? tempRange.after : endDateText}}</view>
|
||||||
|
<time-picker type="time" :end="timepickerEndTime" v-model="timeRange.endTime" :border="false"
|
||||||
|
:hide-second="hideSecond" :disabled="!tempRange.after" class="time-picker-style">
|
||||||
|
</time-picker>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-if="!insert" class="uni-date-changed uni-date-btn--ok">
|
||||||
|
<view class="uni-datetime-picker--btn" @click="confirm">{{confirmText}}</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
getDate,
|
||||||
|
getTime
|
||||||
|
} from './util.js';
|
||||||
|
import calendarItem from './calendar-item.vue'
|
||||||
|
import timePicker from './time-picker.vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
initVueI18n
|
||||||
|
} from '@dcloudio/uni-i18n'
|
||||||
|
import i18nMessages from './i18n/index.js'
|
||||||
|
const {
|
||||||
|
t
|
||||||
|
} = initVueI18n(i18nMessages)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calendar 日历
|
||||||
|
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
|
||||||
|
* @property {String} date 自定义当前时间,默认为今天
|
||||||
|
* @property {String} startDate 日期选择范围-开始日期
|
||||||
|
* @property {String} endDate 日期选择范围-结束日期
|
||||||
|
* @property {Boolean} range 范围选择
|
||||||
|
* @property {Boolean} insert = [true|false] 插入模式,默认为false
|
||||||
|
* @value true 弹窗模式
|
||||||
|
* @value false 插入模式
|
||||||
|
* @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
|
||||||
|
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
|
||||||
|
* @property {Boolean} showMonth 是否选择月份为背景
|
||||||
|
* @property {[String} defaultValue 选择器打开时默认显示的时间
|
||||||
|
* @event {Function} change 日期改变,`insert :ture` 时生效
|
||||||
|
* @event {Function} confirm 确认选择`insert :false` 时生效
|
||||||
|
* @event {Function} monthSwitch 切换月份时触发
|
||||||
|
* @example <uni-calendar :insert="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
calendarItem,
|
||||||
|
timePicker
|
||||||
|
},
|
||||||
|
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
date: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
defTime: {
|
||||||
|
type: [String, Object],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
selectableTimes: {
|
||||||
|
type: [Object],
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selected: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
endDate: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
startPlaceholder: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
endPlaceholder: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
range: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
hasTime: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
insert: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
showMonth: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
clearDate: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
checkHover: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
hideSecond: {
|
||||||
|
type: [Boolean],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
pleStatus: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
before: '',
|
||||||
|
after: '',
|
||||||
|
data: [],
|
||||||
|
fulldate: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
defaultValue: {
|
||||||
|
type: [String, Object, Array],
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
show: false,
|
||||||
|
weeks: [],
|
||||||
|
calendar: {},
|
||||||
|
nowDate: {},
|
||||||
|
aniMaskShow: false,
|
||||||
|
firstEnter: true,
|
||||||
|
time: '',
|
||||||
|
timeRange: {
|
||||||
|
startTime: '',
|
||||||
|
endTime: ''
|
||||||
|
},
|
||||||
|
tempSingleDate: '',
|
||||||
|
tempRange: {
|
||||||
|
before: '',
|
||||||
|
after: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
date: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal) {
|
||||||
|
if (!this.range) {
|
||||||
|
this.tempSingleDate = newVal
|
||||||
|
setTimeout(() => {
|
||||||
|
this.init(newVal)
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
defTime: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal) {
|
||||||
|
if (!this.range) {
|
||||||
|
this.time = newVal
|
||||||
|
} else {
|
||||||
|
this.timeRange.startTime = newVal.start
|
||||||
|
this.timeRange.endTime = newVal.end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startDate(val) {
|
||||||
|
// 字节小程序 watch 早于 created
|
||||||
|
if (!this.cale) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cale.setStartDate(val)
|
||||||
|
this.cale.setDate(this.nowDate.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
},
|
||||||
|
endDate(val) {
|
||||||
|
// 字节小程序 watch 早于 created
|
||||||
|
if (!this.cale) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cale.setEndDate(val)
|
||||||
|
this.cale.setDate(this.nowDate.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
},
|
||||||
|
selected(newVal) {
|
||||||
|
// 字节小程序 watch 早于 created
|
||||||
|
if (!this.cale) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cale.setSelectInfo(this.nowDate.fullDate, newVal)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
},
|
||||||
|
pleStatus: {
|
||||||
|
immediate: true,
|
||||||
|
handler(newVal) {
|
||||||
|
const {
|
||||||
|
before,
|
||||||
|
after,
|
||||||
|
fulldate,
|
||||||
|
which
|
||||||
|
} = newVal
|
||||||
|
this.tempRange.before = before
|
||||||
|
this.tempRange.after = after
|
||||||
|
setTimeout(() => {
|
||||||
|
if (fulldate) {
|
||||||
|
this.cale.setHoverMultiple(fulldate)
|
||||||
|
if (before && after) {
|
||||||
|
this.cale.lastHover = true
|
||||||
|
if (this.rangeWithinMonth(after, before)) return
|
||||||
|
this.setDate(before)
|
||||||
|
} else {
|
||||||
|
this.cale.setMultiple(fulldate)
|
||||||
|
this.setDate(this.nowDate.fullDate)
|
||||||
|
this.calendar.fullDate = ''
|
||||||
|
this.cale.lastHover = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 字节小程序 watch 早于 created
|
||||||
|
if (!this.cale) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cale.setDefaultMultiple(before, after)
|
||||||
|
if (which === 'left' && before) {
|
||||||
|
this.setDate(before)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
} else if (after) {
|
||||||
|
this.setDate(after)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
}
|
||||||
|
this.cale.lastHover = true
|
||||||
|
}
|
||||||
|
}, 16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
timepickerStartTime() {
|
||||||
|
const activeDate = this.range ? this.tempRange.before : this.calendar.fullDate
|
||||||
|
return activeDate === this.startDate ? this.selectableTimes.start : ''
|
||||||
|
},
|
||||||
|
timepickerEndTime() {
|
||||||
|
const activeDate = this.range ? this.tempRange.after : this.calendar.fullDate
|
||||||
|
return activeDate === this.endDate ? this.selectableTimes.end : ''
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* for i18n
|
||||||
|
*/
|
||||||
|
selectDateText() {
|
||||||
|
return t("uni-datetime-picker.selectDate")
|
||||||
|
},
|
||||||
|
startDateText() {
|
||||||
|
return this.startPlaceholder || t("uni-datetime-picker.startDate")
|
||||||
|
},
|
||||||
|
endDateText() {
|
||||||
|
return this.endPlaceholder || t("uni-datetime-picker.endDate")
|
||||||
|
},
|
||||||
|
okText() {
|
||||||
|
return t("uni-datetime-picker.ok")
|
||||||
|
},
|
||||||
|
yearText() {
|
||||||
|
return t("uni-datetime-picker.year")
|
||||||
|
},
|
||||||
|
monthText() {
|
||||||
|
return t("uni-datetime-picker.month")
|
||||||
|
},
|
||||||
|
MONText() {
|
||||||
|
return t("uni-calender.MON")
|
||||||
|
},
|
||||||
|
TUEText() {
|
||||||
|
return t("uni-calender.TUE")
|
||||||
|
},
|
||||||
|
WEDText() {
|
||||||
|
return t("uni-calender.WED")
|
||||||
|
},
|
||||||
|
THUText() {
|
||||||
|
return t("uni-calender.THU")
|
||||||
|
},
|
||||||
|
FRIText() {
|
||||||
|
return t("uni-calender.FRI")
|
||||||
|
},
|
||||||
|
SATText() {
|
||||||
|
return t("uni-calender.SAT")
|
||||||
|
},
|
||||||
|
SUNText() {
|
||||||
|
return t("uni-calender.SUN")
|
||||||
|
},
|
||||||
|
confirmText() {
|
||||||
|
return t("uni-calender.confirm")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// 获取日历方法实例
|
||||||
|
this.cale = new Calendar({
|
||||||
|
selected: this.selected,
|
||||||
|
startDate: this.startDate,
|
||||||
|
endDate: this.endDate,
|
||||||
|
range: this.range,
|
||||||
|
})
|
||||||
|
// 选中某一天
|
||||||
|
this.init(this.date)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
leaveCale() {
|
||||||
|
this.firstEnter = true
|
||||||
|
},
|
||||||
|
handleMouse(weeks) {
|
||||||
|
if (weeks.disable) return
|
||||||
|
if (this.cale.lastHover) return
|
||||||
|
let {
|
||||||
|
before,
|
||||||
|
after
|
||||||
|
} = this.cale.multipleStatus
|
||||||
|
if (!before) return
|
||||||
|
this.calendar = weeks
|
||||||
|
// 设置范围选
|
||||||
|
this.cale.setHoverMultiple(this.calendar.fullDate)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
// hover时,进入一个日历,更新另一个
|
||||||
|
if (this.firstEnter) {
|
||||||
|
this.$emit('firstEnterCale', this.cale.multipleStatus)
|
||||||
|
this.firstEnter = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rangeWithinMonth(A, B) {
|
||||||
|
const [yearA, monthA] = A.split('-')
|
||||||
|
const [yearB, monthB] = B.split('-')
|
||||||
|
return yearA === yearB && monthA === monthB
|
||||||
|
},
|
||||||
|
// 蒙版点击事件
|
||||||
|
maskClick() {
|
||||||
|
this.close()
|
||||||
|
this.$emit('maskClose')
|
||||||
|
},
|
||||||
|
|
||||||
|
clearCalender() {
|
||||||
|
if (this.range) {
|
||||||
|
this.timeRange.startTime = ''
|
||||||
|
this.timeRange.endTime = ''
|
||||||
|
this.tempRange.before = ''
|
||||||
|
this.tempRange.after = ''
|
||||||
|
this.cale.multipleStatus.before = ''
|
||||||
|
this.cale.multipleStatus.after = ''
|
||||||
|
this.cale.multipleStatus.data = []
|
||||||
|
this.cale.lastHover = false
|
||||||
|
} else {
|
||||||
|
this.time = ''
|
||||||
|
this.tempSingleDate = ''
|
||||||
|
}
|
||||||
|
this.calendar.fullDate = ''
|
||||||
|
this.setDate(new Date())
|
||||||
|
},
|
||||||
|
|
||||||
|
bindDateChange(e) {
|
||||||
|
const value = e.detail.value + '-1'
|
||||||
|
this.setDate(value)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 初始化日期显示
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
init(date) {
|
||||||
|
// 字节小程序 watch 早于 created
|
||||||
|
if (!this.cale) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.cale.setDate(date || new Date())
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.nowDate = this.cale.getInfo(date)
|
||||||
|
this.calendar = {
|
||||||
|
...this.nowDate
|
||||||
|
}
|
||||||
|
if (!date) {
|
||||||
|
// 优化date为空默认不选中今天
|
||||||
|
this.calendar.fullDate = ''
|
||||||
|
if (this.defaultValue && !this.range) {
|
||||||
|
// 暂时只支持移动端非范围选择
|
||||||
|
const defaultDate = new Date(this.defaultValue)
|
||||||
|
const fullDate = getDate(defaultDate)
|
||||||
|
const year = defaultDate.getFullYear()
|
||||||
|
const month = defaultDate.getMonth() + 1
|
||||||
|
const date = defaultDate.getDate()
|
||||||
|
const day = defaultDate.getDay()
|
||||||
|
this.calendar = {
|
||||||
|
fullDate,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
date,
|
||||||
|
day
|
||||||
|
},
|
||||||
|
this.tempSingleDate = fullDate
|
||||||
|
this.time = getTime(defaultDate, this.hideSecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 打开日历弹窗
|
||||||
|
*/
|
||||||
|
open() {
|
||||||
|
// 弹窗模式并且清理数据
|
||||||
|
if (this.clearDate && !this.insert) {
|
||||||
|
this.cale.cleanMultipleStatus()
|
||||||
|
this.init(this.date)
|
||||||
|
}
|
||||||
|
this.show = true
|
||||||
|
this.$nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.aniMaskShow = true
|
||||||
|
}, 50)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 关闭日历弹窗
|
||||||
|
*/
|
||||||
|
close() {
|
||||||
|
this.aniMaskShow = false
|
||||||
|
this.$nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.show = false
|
||||||
|
this.$emit('close')
|
||||||
|
}, 300)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 确认按钮
|
||||||
|
*/
|
||||||
|
confirm() {
|
||||||
|
this.setEmit('confirm')
|
||||||
|
this.close()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 变化触发
|
||||||
|
*/
|
||||||
|
change(isSingleChange) {
|
||||||
|
if (!this.insert && !isSingleChange) return
|
||||||
|
this.setEmit('change')
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 选择月份触发
|
||||||
|
*/
|
||||||
|
monthSwitch() {
|
||||||
|
let {
|
||||||
|
year,
|
||||||
|
month
|
||||||
|
} = this.nowDate
|
||||||
|
this.$emit('monthSwitch', {
|
||||||
|
year,
|
||||||
|
month: Number(month)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 派发事件
|
||||||
|
* @param {Object} name
|
||||||
|
*/
|
||||||
|
setEmit(name) {
|
||||||
|
if (!this.range) {
|
||||||
|
if (!this.calendar.fullDate) {
|
||||||
|
this.calendar = this.cale.getInfo(new Date())
|
||||||
|
this.tempSingleDate = this.calendar.fullDate
|
||||||
|
}
|
||||||
|
if (this.hasTime && !this.time) {
|
||||||
|
this.time = getTime(new Date(), this.hideSecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let {
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
date,
|
||||||
|
fullDate,
|
||||||
|
extraInfo
|
||||||
|
} = this.calendar
|
||||||
|
this.$emit(name, {
|
||||||
|
range: this.cale.multipleStatus,
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
date,
|
||||||
|
time: this.time,
|
||||||
|
timeRange: this.timeRange,
|
||||||
|
fulldate: fullDate,
|
||||||
|
extraInfo: extraInfo || {}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 选择天触发
|
||||||
|
* @param {Object} weeks
|
||||||
|
*/
|
||||||
|
choiceDate(weeks) {
|
||||||
|
if (weeks.disable) return
|
||||||
|
this.calendar = weeks
|
||||||
|
this.calendar.userChecked = true
|
||||||
|
// 设置多选
|
||||||
|
this.cale.setMultiple(this.calendar.fullDate, true)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.tempSingleDate = this.calendar.fullDate
|
||||||
|
const beforeDate = new Date(this.cale.multipleStatus.before).getTime()
|
||||||
|
const afterDate = new Date(this.cale.multipleStatus.after).getTime()
|
||||||
|
if (beforeDate > afterDate && afterDate) {
|
||||||
|
this.tempRange.before = this.cale.multipleStatus.after
|
||||||
|
this.tempRange.after = this.cale.multipleStatus.before
|
||||||
|
} else {
|
||||||
|
this.tempRange.before = this.cale.multipleStatus.before
|
||||||
|
this.tempRange.after = this.cale.multipleStatus.after
|
||||||
|
}
|
||||||
|
this.change(true)
|
||||||
|
},
|
||||||
|
changeMonth(type) {
|
||||||
|
let newDate
|
||||||
|
if (type === 'pre') {
|
||||||
|
newDate = this.cale.getPreMonthObj(this.nowDate.fullDate).fullDate
|
||||||
|
} else if (type === 'next') {
|
||||||
|
newDate = this.cale.getNextMonthObj(this.nowDate.fullDate).fullDate
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setDate(newDate)
|
||||||
|
this.monthSwitch()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 设置日期
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
setDate(date) {
|
||||||
|
this.cale.setDate(date)
|
||||||
|
this.weeks = this.cale.weeks
|
||||||
|
this.nowDate = this.cale.getInfo(date)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-primary: #007aff !default;
|
||||||
|
|
||||||
|
.uni-calendar {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__mask {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
|
transition-property: opacity;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
opacity: 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
z-index: 99;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--mask-show {
|
||||||
|
opacity: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed {
|
||||||
|
position: fixed;
|
||||||
|
bottom: calc(var(--window-bottom));
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
transition-property: transform;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
transform: translateY(460px);
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
z-index: 99;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--ani-show {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__content {
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__content-mobile {
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
box-shadow: 0px 0px 5px 3px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-mobile {
|
||||||
|
padding: 10px;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed-top {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
border-top-color: rgba(0, 0, 0, 0.4);
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--fixed-width {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__backtoday {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 25rpx;
|
||||||
|
padding: 0 5px;
|
||||||
|
padding-left: 10px;
|
||||||
|
height: 25px;
|
||||||
|
line-height: 25px;
|
||||||
|
font-size: 12px;
|
||||||
|
border-top-left-radius: 25px;
|
||||||
|
border-bottom-left-radius: 25px;
|
||||||
|
color: #fff;
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-text {
|
||||||
|
text-align: center;
|
||||||
|
width: 100px;
|
||||||
|
font-size: 15px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__button-text {
|
||||||
|
text-align: center;
|
||||||
|
width: 100px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: $uni-primary;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
letter-spacing: 3px;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-btn-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__header-btn {
|
||||||
|
width: 9px;
|
||||||
|
height: 9px;
|
||||||
|
border-left-color: #808080;
|
||||||
|
border-left-style: solid;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-top-color: #555555;
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--left {
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar--right {
|
||||||
|
transform: rotate(135deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-calendar__weeks {
|
||||||
|
position: relative;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-item {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-day {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 40px;
|
||||||
|
border-bottom-color: #F5F5F5;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__weeks-day-text {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #B2B2B2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box {
|
||||||
|
position: relative;
|
||||||
|
// padding: 0 10px;
|
||||||
|
padding-bottom: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box-bg {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-calendar__box-bg-text {
|
||||||
|
font-size: 200px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #999;
|
||||||
|
opacity: 0.1;
|
||||||
|
text-align: center;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
line-height: 1;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-date-changed {
|
||||||
|
padding: 0 10px;
|
||||||
|
// line-height: 50px;
|
||||||
|
text-align: center;
|
||||||
|
color: #333;
|
||||||
|
border-top-color: #DCDCDC;
|
||||||
|
;
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 1px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-date-btn--ok {
|
||||||
|
padding: 20px 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-date-changed--time-start {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-date-changed--time-end {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-date-changed--time-date {
|
||||||
|
color: #999;
|
||||||
|
line-height: 50px;
|
||||||
|
/* #ifdef MP-TOUTIAO */
|
||||||
|
font-size: 16px;
|
||||||
|
/* #endif */
|
||||||
|
margin-right: 5px;
|
||||||
|
// opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-picker-style {
|
||||||
|
// width: 62px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center
|
||||||
|
}
|
||||||
|
|
||||||
|
.mr-10 {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 25px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-plus {
|
||||||
|
width: 16px;
|
||||||
|
height: 2px;
|
||||||
|
background-color: #737987;
|
||||||
|
border-radius: 2px;
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dialog-close-rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker--btn {
|
||||||
|
border-radius: 100px;
|
||||||
|
height: 40px;
|
||||||
|
line-height: 40px;
|
||||||
|
background-color: $uni-primary;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 16px;
|
||||||
|
letter-spacing: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
.uni-datetime-picker--btn:active {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
</style>
|
||||||
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/en.json
generated
vendored
Normal file
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/en.json
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"uni-datetime-picker.selectDate": "select date",
|
||||||
|
"uni-datetime-picker.selectTime": "select time",
|
||||||
|
"uni-datetime-picker.selectDateTime": "select date and time",
|
||||||
|
"uni-datetime-picker.startDate": "start date",
|
||||||
|
"uni-datetime-picker.endDate": "end date",
|
||||||
|
"uni-datetime-picker.startTime": "start time",
|
||||||
|
"uni-datetime-picker.endTime": "end time",
|
||||||
|
"uni-datetime-picker.ok": "ok",
|
||||||
|
"uni-datetime-picker.clear": "clear",
|
||||||
|
"uni-datetime-picker.cancel": "cancel",
|
||||||
|
"uni-datetime-picker.year": "-",
|
||||||
|
"uni-datetime-picker.month": "",
|
||||||
|
"uni-calender.MON": "MON",
|
||||||
|
"uni-calender.TUE": "TUE",
|
||||||
|
"uni-calender.WED": "WED",
|
||||||
|
"uni-calender.THU": "THU",
|
||||||
|
"uni-calender.FRI": "FRI",
|
||||||
|
"uni-calender.SAT": "SAT",
|
||||||
|
"uni-calender.SUN": "SUN",
|
||||||
|
"uni-calender.confirm": "confirm"
|
||||||
|
}
|
||||||
8
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/index.js
generated
vendored
Normal file
8
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import en from './en.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
||||||
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/zh-Hans.json
generated
vendored
Normal file
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/zh-Hans.json
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"uni-datetime-picker.selectDate": "选择日期",
|
||||||
|
"uni-datetime-picker.selectTime": "选择时间",
|
||||||
|
"uni-datetime-picker.selectDateTime": "选择日期时间",
|
||||||
|
"uni-datetime-picker.startDate": "开始日期",
|
||||||
|
"uni-datetime-picker.endDate": "结束日期",
|
||||||
|
"uni-datetime-picker.startTime": "开始时间",
|
||||||
|
"uni-datetime-picker.endTime": "结束时间",
|
||||||
|
"uni-datetime-picker.ok": "确定",
|
||||||
|
"uni-datetime-picker.clear": "清除",
|
||||||
|
"uni-datetime-picker.cancel": "取消",
|
||||||
|
"uni-datetime-picker.year": "年",
|
||||||
|
"uni-datetime-picker.month": "月",
|
||||||
|
"uni-calender.SUN": "日",
|
||||||
|
"uni-calender.MON": "一",
|
||||||
|
"uni-calender.TUE": "二",
|
||||||
|
"uni-calender.WED": "三",
|
||||||
|
"uni-calender.THU": "四",
|
||||||
|
"uni-calender.FRI": "五",
|
||||||
|
"uni-calender.SAT": "六",
|
||||||
|
"uni-calender.confirm": "确认"
|
||||||
|
}
|
||||||
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/zh-Hant.json
generated
vendored
Normal file
22
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/i18n/zh-Hant.json
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"uni-datetime-picker.selectDate": "選擇日期",
|
||||||
|
"uni-datetime-picker.selectTime": "選擇時間",
|
||||||
|
"uni-datetime-picker.selectDateTime": "選擇日期時間",
|
||||||
|
"uni-datetime-picker.startDate": "開始日期",
|
||||||
|
"uni-datetime-picker.endDate": "結束日期",
|
||||||
|
"uni-datetime-picker.startTime": "開始时间",
|
||||||
|
"uni-datetime-picker.endTime": "結束时间",
|
||||||
|
"uni-datetime-picker.ok": "確定",
|
||||||
|
"uni-datetime-picker.clear": "清除",
|
||||||
|
"uni-datetime-picker.cancel": "取消",
|
||||||
|
"uni-datetime-picker.year": "年",
|
||||||
|
"uni-datetime-picker.month": "月",
|
||||||
|
"uni-calender.SUN": "日",
|
||||||
|
"uni-calender.MON": "一",
|
||||||
|
"uni-calender.TUE": "二",
|
||||||
|
"uni-calender.WED": "三",
|
||||||
|
"uni-calender.THU": "四",
|
||||||
|
"uni-calender.FRI": "五",
|
||||||
|
"uni-calender.SAT": "六",
|
||||||
|
"uni-calender.confirm": "確認"
|
||||||
|
}
|
||||||
940
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/time-picker.vue
generated
vendored
Normal file
940
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/time-picker.vue
generated
vendored
Normal file
@ -0,0 +1,940 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-datetime-picker">
|
||||||
|
<view @click="initTimePicker">
|
||||||
|
<slot>
|
||||||
|
<view class="uni-datetime-picker-timebox-pointer"
|
||||||
|
:class="{'uni-datetime-picker-disabled': disabled, 'uni-datetime-picker-timebox': border}">
|
||||||
|
<text class="uni-datetime-picker-text">{{time}}</text>
|
||||||
|
<view v-if="!time" class="uni-datetime-picker-time">
|
||||||
|
<text class="uni-datetime-picker-text">{{selectTimeText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
</view>
|
||||||
|
<view v-if="visible" id="mask" class="uni-datetime-picker-mask" @click="tiggerTimePicker"></view>
|
||||||
|
<view v-if="visible" class="uni-datetime-picker-popup" :class="[dateShow && timeShow ? '' : 'fix-nvue-height']"
|
||||||
|
:style="fixNvueBug">
|
||||||
|
<view class="uni-title">
|
||||||
|
<text class="uni-datetime-picker-text">{{selectTimeText}}</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="dateShow" class="uni-datetime-picker__container-box">
|
||||||
|
<picker-view class="uni-datetime-picker-view" :indicator-style="indicatorStyle" :value="ymd"
|
||||||
|
@change="bindDateChange">
|
||||||
|
<picker-view-column>
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in years" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
<picker-view-column>
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in months" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
<picker-view-column>
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in days" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
</picker-view>
|
||||||
|
<!-- 兼容 nvue 不支持伪类 -->
|
||||||
|
<text class="uni-datetime-picker-sign sign-left">-</text>
|
||||||
|
<text class="uni-datetime-picker-sign sign-right">-</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="timeShow" class="uni-datetime-picker__container-box">
|
||||||
|
<picker-view class="uni-datetime-picker-view" :class="[hideSecond ? 'time-hide-second' : '']"
|
||||||
|
:indicator-style="indicatorStyle" :value="hms" @change="bindTimeChange">
|
||||||
|
<picker-view-column>
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in hours" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
<picker-view-column>
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in minutes" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
<picker-view-column v-if="!hideSecond">
|
||||||
|
<view class="uni-datetime-picker-item" v-for="(item,index) in seconds" :key="index">
|
||||||
|
<text class="uni-datetime-picker-item">{{lessThanTen(item)}}</text>
|
||||||
|
</view>
|
||||||
|
</picker-view-column>
|
||||||
|
</picker-view>
|
||||||
|
<!-- 兼容 nvue 不支持伪类 -->
|
||||||
|
<text class="uni-datetime-picker-sign" :class="[hideSecond ? 'sign-center' : 'sign-left']">:</text>
|
||||||
|
<text v-if="!hideSecond" class="uni-datetime-picker-sign sign-right">:</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-datetime-picker-btn">
|
||||||
|
<view @click="clearTime">
|
||||||
|
<text class="uni-datetime-picker-btn-text">{{clearText}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="uni-datetime-picker-btn-group">
|
||||||
|
<view class="uni-datetime-picker-cancel" @click="tiggerTimePicker">
|
||||||
|
<text class="uni-datetime-picker-btn-text">{{cancelText}}</text>
|
||||||
|
</view>
|
||||||
|
<view @click="setTime">
|
||||||
|
<text class="uni-datetime-picker-btn-text">{{okText}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
initVueI18n
|
||||||
|
} from '@dcloudio/uni-i18n'
|
||||||
|
import i18nMessages from './i18n/index.js'
|
||||||
|
const {
|
||||||
|
t
|
||||||
|
} = initVueI18n(i18nMessages)
|
||||||
|
import {
|
||||||
|
fixIosDateFormat
|
||||||
|
} from './util'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DatetimePicker 时间选择器
|
||||||
|
* @description 可以同时选择日期和时间的选择器
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=xxx
|
||||||
|
* @property {String} type = [datetime | date | time] 显示模式
|
||||||
|
* @property {Boolean} multiple = [true|false] 是否多选
|
||||||
|
* @property {String|Number} value 默认值
|
||||||
|
* @property {String|Number} start 起始日期或时间
|
||||||
|
* @property {String|Number} end 起始日期或时间
|
||||||
|
* @property {String} return-type = [timestamp | string]
|
||||||
|
* @event {Function} change 选中发生变化触发
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'UniDatetimePicker',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
indicatorStyle: `height: 50px;`,
|
||||||
|
visible: false,
|
||||||
|
fixNvueBug: {},
|
||||||
|
dateShow: true,
|
||||||
|
timeShow: true,
|
||||||
|
title: '日期和时间',
|
||||||
|
// 输入框当前时间
|
||||||
|
time: '',
|
||||||
|
// 当前的年月日时分秒
|
||||||
|
year: 1920,
|
||||||
|
month: 0,
|
||||||
|
day: 0,
|
||||||
|
hour: 0,
|
||||||
|
minute: 0,
|
||||||
|
second: 0,
|
||||||
|
// 起始时间
|
||||||
|
startYear: 1920,
|
||||||
|
startMonth: 1,
|
||||||
|
startDay: 1,
|
||||||
|
startHour: 0,
|
||||||
|
startMinute: 0,
|
||||||
|
startSecond: 0,
|
||||||
|
// 结束时间
|
||||||
|
endYear: 2120,
|
||||||
|
endMonth: 12,
|
||||||
|
endDay: 31,
|
||||||
|
endHour: 23,
|
||||||
|
endMinute: 59,
|
||||||
|
endSecond: 59,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'datetime'
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
returnType: {
|
||||||
|
type: String,
|
||||||
|
default: 'string'
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
hideSecond: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// #ifndef VUE3
|
||||||
|
value: {
|
||||||
|
handler(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
this.parseValue(fixIosDateFormat(newVal))
|
||||||
|
this.initTime(false)
|
||||||
|
} else {
|
||||||
|
this.time = ''
|
||||||
|
this.parseValue(Date.now())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
modelValue: {
|
||||||
|
handler(newVal) {
|
||||||
|
if (newVal) {
|
||||||
|
this.parseValue(fixIosDateFormat(newVal))
|
||||||
|
this.initTime(false)
|
||||||
|
} else {
|
||||||
|
this.time = ''
|
||||||
|
this.parseValue(Date.now())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
type: {
|
||||||
|
handler(newValue) {
|
||||||
|
if (newValue === 'date') {
|
||||||
|
this.dateShow = true
|
||||||
|
this.timeShow = false
|
||||||
|
this.title = '日期'
|
||||||
|
} else if (newValue === 'time') {
|
||||||
|
this.dateShow = false
|
||||||
|
this.timeShow = true
|
||||||
|
this.title = '时间'
|
||||||
|
} else {
|
||||||
|
this.dateShow = true
|
||||||
|
this.timeShow = true
|
||||||
|
this.title = '日期和时间'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
start: {
|
||||||
|
handler(newVal) {
|
||||||
|
this.parseDatetimeRange(fixIosDateFormat(newVal), 'start')
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
handler(newVal) {
|
||||||
|
this.parseDatetimeRange(fixIosDateFormat(newVal), 'end')
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
|
||||||
|
// 月、日、时、分、秒可选范围变化后,检查当前值是否在范围内,不在则当前值重置为可选范围第一项
|
||||||
|
months(newVal) {
|
||||||
|
this.checkValue('month', this.month, newVal)
|
||||||
|
},
|
||||||
|
days(newVal) {
|
||||||
|
this.checkValue('day', this.day, newVal)
|
||||||
|
},
|
||||||
|
hours(newVal) {
|
||||||
|
this.checkValue('hour', this.hour, newVal)
|
||||||
|
},
|
||||||
|
minutes(newVal) {
|
||||||
|
this.checkValue('minute', this.minute, newVal)
|
||||||
|
},
|
||||||
|
seconds(newVal) {
|
||||||
|
this.checkValue('second', this.second, newVal)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// 当前年、月、日、时、分、秒选择范围
|
||||||
|
years() {
|
||||||
|
return this.getCurrentRange('year')
|
||||||
|
},
|
||||||
|
|
||||||
|
months() {
|
||||||
|
return this.getCurrentRange('month')
|
||||||
|
},
|
||||||
|
|
||||||
|
days() {
|
||||||
|
return this.getCurrentRange('day')
|
||||||
|
},
|
||||||
|
|
||||||
|
hours() {
|
||||||
|
return this.getCurrentRange('hour')
|
||||||
|
},
|
||||||
|
|
||||||
|
minutes() {
|
||||||
|
return this.getCurrentRange('minute')
|
||||||
|
},
|
||||||
|
|
||||||
|
seconds() {
|
||||||
|
return this.getCurrentRange('second')
|
||||||
|
},
|
||||||
|
|
||||||
|
// picker 当前值数组
|
||||||
|
ymd() {
|
||||||
|
return [this.year - this.minYear, this.month - this.minMonth, this.day - this.minDay]
|
||||||
|
},
|
||||||
|
hms() {
|
||||||
|
return [this.hour - this.minHour, this.minute - this.minMinute, this.second - this.minSecond]
|
||||||
|
},
|
||||||
|
|
||||||
|
// 当前 date 是 start
|
||||||
|
currentDateIsStart() {
|
||||||
|
return this.year === this.startYear && this.month === this.startMonth && this.day === this.startDay
|
||||||
|
},
|
||||||
|
|
||||||
|
// 当前 date 是 end
|
||||||
|
currentDateIsEnd() {
|
||||||
|
return this.year === this.endYear && this.month === this.endMonth && this.day === this.endDay
|
||||||
|
},
|
||||||
|
|
||||||
|
// 当前年、月、日、时、分、秒的最小值和最大值
|
||||||
|
minYear() {
|
||||||
|
return this.startYear
|
||||||
|
},
|
||||||
|
maxYear() {
|
||||||
|
return this.endYear
|
||||||
|
},
|
||||||
|
minMonth() {
|
||||||
|
if (this.year === this.startYear) {
|
||||||
|
return this.startMonth
|
||||||
|
} else {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
maxMonth() {
|
||||||
|
if (this.year === this.endYear) {
|
||||||
|
return this.endMonth
|
||||||
|
} else {
|
||||||
|
return 12
|
||||||
|
}
|
||||||
|
},
|
||||||
|
minDay() {
|
||||||
|
if (this.year === this.startYear && this.month === this.startMonth) {
|
||||||
|
return this.startDay
|
||||||
|
} else {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
maxDay() {
|
||||||
|
if (this.year === this.endYear && this.month === this.endMonth) {
|
||||||
|
return this.endDay
|
||||||
|
} else {
|
||||||
|
return this.daysInMonth(this.year, this.month)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
minHour() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsStart) {
|
||||||
|
return this.startHour
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
return this.startHour
|
||||||
|
}
|
||||||
|
},
|
||||||
|
maxHour() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsEnd) {
|
||||||
|
return this.endHour
|
||||||
|
} else {
|
||||||
|
return 23
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
return this.endHour
|
||||||
|
}
|
||||||
|
},
|
||||||
|
minMinute() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsStart && this.hour === this.startHour) {
|
||||||
|
return this.startMinute
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
if (this.hour === this.startHour) {
|
||||||
|
return this.startMinute
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
maxMinute() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsEnd && this.hour === this.endHour) {
|
||||||
|
return this.endMinute
|
||||||
|
} else {
|
||||||
|
return 59
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
if (this.hour === this.endHour) {
|
||||||
|
return this.endMinute
|
||||||
|
} else {
|
||||||
|
return 59
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
minSecond() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsStart && this.hour === this.startHour && this.minute === this.startMinute) {
|
||||||
|
return this.startSecond
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
if (this.hour === this.startHour && this.minute === this.startMinute) {
|
||||||
|
return this.startSecond
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
maxSecond() {
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
if (this.currentDateIsEnd && this.hour === this.endHour && this.minute === this.endMinute) {
|
||||||
|
return this.endSecond
|
||||||
|
} else {
|
||||||
|
return 59
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
if (this.hour === this.endHour && this.minute === this.endMinute) {
|
||||||
|
return this.endSecond
|
||||||
|
} else {
|
||||||
|
return 59
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for i18n
|
||||||
|
*/
|
||||||
|
selectTimeText() {
|
||||||
|
return t("uni-datetime-picker.selectTime")
|
||||||
|
},
|
||||||
|
okText() {
|
||||||
|
return t("uni-datetime-picker.ok")
|
||||||
|
},
|
||||||
|
clearText() {
|
||||||
|
return t("uni-datetime-picker.clear")
|
||||||
|
},
|
||||||
|
cancelText() {
|
||||||
|
return t("uni-datetime-picker.cancel")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
const res = uni.getSystemInfoSync();
|
||||||
|
this.fixNvueBug = {
|
||||||
|
top: res.windowHeight / 2,
|
||||||
|
left: res.windowWidth / 2
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* @param {Object} item
|
||||||
|
* 小于 10 在前面加个 0
|
||||||
|
*/
|
||||||
|
|
||||||
|
lessThanTen(item) {
|
||||||
|
return item < 10 ? '0' + item : item
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析时分秒字符串,例如:00:00:00
|
||||||
|
* @param {String} timeString
|
||||||
|
*/
|
||||||
|
parseTimeType(timeString) {
|
||||||
|
if (timeString) {
|
||||||
|
let timeArr = timeString.split(':')
|
||||||
|
this.hour = Number(timeArr[0])
|
||||||
|
this.minute = Number(timeArr[1])
|
||||||
|
this.second = Number(timeArr[2])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析选择器初始值,类型可以是字符串、时间戳,例如:2000-10-02、'08:30:00'、 1610695109000
|
||||||
|
* @param {String | Number} datetime
|
||||||
|
*/
|
||||||
|
initPickerValue(datetime) {
|
||||||
|
let defaultValue = null
|
||||||
|
if (datetime) {
|
||||||
|
defaultValue = this.compareValueWithStartAndEnd(datetime, this.start, this.end)
|
||||||
|
} else {
|
||||||
|
defaultValue = Date.now()
|
||||||
|
defaultValue = this.compareValueWithStartAndEnd(defaultValue, this.start, this.end)
|
||||||
|
}
|
||||||
|
this.parseValue(defaultValue)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始值规则:
|
||||||
|
* - 用户设置初始值 value
|
||||||
|
* - 设置了起始时间 start、终止时间 end,并 start < value < end,初始值为 value, 否则初始值为 start
|
||||||
|
* - 只设置了起始时间 start,并 start < value,初始值为 value,否则初始值为 start
|
||||||
|
* - 只设置了终止时间 end,并 value < end,初始值为 value,否则初始值为 end
|
||||||
|
* - 无起始终止时间,则初始值为 value
|
||||||
|
* - 无初始值 value,则初始值为当前本地时间 Date.now()
|
||||||
|
* @param {Object} value
|
||||||
|
* @param {Object} dateBase
|
||||||
|
*/
|
||||||
|
compareValueWithStartAndEnd(value, start, end) {
|
||||||
|
let winner = null
|
||||||
|
value = this.superTimeStamp(value)
|
||||||
|
start = this.superTimeStamp(start)
|
||||||
|
end = this.superTimeStamp(end)
|
||||||
|
|
||||||
|
if (start && end) {
|
||||||
|
if (value < start) {
|
||||||
|
winner = new Date(start)
|
||||||
|
} else if (value > end) {
|
||||||
|
winner = new Date(end)
|
||||||
|
} else {
|
||||||
|
winner = new Date(value)
|
||||||
|
}
|
||||||
|
} else if (start && !end) {
|
||||||
|
winner = start <= value ? new Date(value) : new Date(start)
|
||||||
|
} else if (!start && end) {
|
||||||
|
winner = value <= end ? new Date(value) : new Date(end)
|
||||||
|
} else {
|
||||||
|
winner = new Date(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return winner
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为可比较的时间戳,接受日期、时分秒、时间戳
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
superTimeStamp(value) {
|
||||||
|
let dateBase = ''
|
||||||
|
if (this.type === 'time' && value && typeof value === 'string') {
|
||||||
|
const now = new Date()
|
||||||
|
const year = now.getFullYear()
|
||||||
|
const month = now.getMonth() + 1
|
||||||
|
const day = now.getDate()
|
||||||
|
dateBase = year + '/' + month + '/' + day + ' '
|
||||||
|
}
|
||||||
|
if (Number(value)) {
|
||||||
|
value = parseInt(value)
|
||||||
|
dateBase = 0
|
||||||
|
}
|
||||||
|
return this.createTimeStamp(dateBase + value)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析默认值 value,字符串、时间戳
|
||||||
|
* @param {Object} defaultTime
|
||||||
|
*/
|
||||||
|
parseValue(value) {
|
||||||
|
if (!value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.type === 'time' && typeof value === "string") {
|
||||||
|
this.parseTimeType(value)
|
||||||
|
} else {
|
||||||
|
let defaultDate = null
|
||||||
|
defaultDate = new Date(value)
|
||||||
|
if (this.type !== 'time') {
|
||||||
|
this.year = defaultDate.getFullYear()
|
||||||
|
this.month = defaultDate.getMonth() + 1
|
||||||
|
this.day = defaultDate.getDate()
|
||||||
|
}
|
||||||
|
if (this.type !== 'date') {
|
||||||
|
this.hour = defaultDate.getHours()
|
||||||
|
this.minute = defaultDate.getMinutes()
|
||||||
|
this.second = defaultDate.getSeconds()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.hideSecond) {
|
||||||
|
this.second = 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析可选择时间范围 start、end,年月日字符串、时间戳
|
||||||
|
* @param {Object} defaultTime
|
||||||
|
*/
|
||||||
|
parseDatetimeRange(point, pointType) {
|
||||||
|
// 时间为空,则重置为初始值
|
||||||
|
if (!point) {
|
||||||
|
if (pointType === 'start') {
|
||||||
|
this.startYear = 1920
|
||||||
|
this.startMonth = 1
|
||||||
|
this.startDay = 1
|
||||||
|
this.startHour = 0
|
||||||
|
this.startMinute = 0
|
||||||
|
this.startSecond = 0
|
||||||
|
}
|
||||||
|
if (pointType === 'end') {
|
||||||
|
this.endYear = 2120
|
||||||
|
this.endMonth = 12
|
||||||
|
this.endDay = 31
|
||||||
|
this.endHour = 23
|
||||||
|
this.endMinute = 59
|
||||||
|
this.endSecond = 59
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.type === 'time') {
|
||||||
|
const pointArr = point.split(':')
|
||||||
|
this[pointType + 'Hour'] = Number(pointArr[0])
|
||||||
|
this[pointType + 'Minute'] = Number(pointArr[1])
|
||||||
|
this[pointType + 'Second'] = Number(pointArr[2])
|
||||||
|
} else {
|
||||||
|
if (!point) {
|
||||||
|
pointType === 'start' ? this.startYear = this.year - 60 : this.endYear = this.year + 60
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (Number(point)) {
|
||||||
|
point = parseInt(point)
|
||||||
|
}
|
||||||
|
// datetime 的 end 没有时分秒, 则不限制
|
||||||
|
const hasTime = /[0-9]:[0-9]/
|
||||||
|
if (this.type === 'datetime' && pointType === 'end' && typeof point === 'string' && !hasTime.test(
|
||||||
|
point)) {
|
||||||
|
point = point + ' 23:59:59'
|
||||||
|
}
|
||||||
|
const pointDate = new Date(point)
|
||||||
|
this[pointType + 'Year'] = pointDate.getFullYear()
|
||||||
|
this[pointType + 'Month'] = pointDate.getMonth() + 1
|
||||||
|
this[pointType + 'Day'] = pointDate.getDate()
|
||||||
|
if (this.type === 'datetime') {
|
||||||
|
this[pointType + 'Hour'] = pointDate.getHours()
|
||||||
|
this[pointType + 'Minute'] = pointDate.getMinutes()
|
||||||
|
this[pointType + 'Second'] = pointDate.getSeconds()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取 年、月、日、时、分、秒 当前可选范围
|
||||||
|
getCurrentRange(value) {
|
||||||
|
const range = []
|
||||||
|
for (let i = this['min' + this.capitalize(value)]; i <= this['max' + this.capitalize(value)]; i++) {
|
||||||
|
range.push(i)
|
||||||
|
}
|
||||||
|
return range
|
||||||
|
},
|
||||||
|
|
||||||
|
// 字符串首字母大写
|
||||||
|
capitalize(str) {
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 检查当前值是否在范围内,不在则当前值重置为可选范围第一项
|
||||||
|
checkValue(name, value, values) {
|
||||||
|
if (values.indexOf(value) === -1) {
|
||||||
|
this[name] = values[0]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 每个月的实际天数
|
||||||
|
daysInMonth(year, month) { // Use 1 for January, 2 for February, etc.
|
||||||
|
return new Date(year, month, 0).getDate();
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成时间戳
|
||||||
|
* @param {Object} time
|
||||||
|
*/
|
||||||
|
createTimeStamp(time) {
|
||||||
|
if (!time) return
|
||||||
|
if (typeof time === "number") {
|
||||||
|
return time
|
||||||
|
} else {
|
||||||
|
time = time.replace(/-/g, '/')
|
||||||
|
if (this.type === 'date') {
|
||||||
|
time = time + ' ' + '00:00:00'
|
||||||
|
}
|
||||||
|
return Date.parse(time)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成日期或时间的字符串
|
||||||
|
*/
|
||||||
|
createDomSting() {
|
||||||
|
const yymmdd = this.year +
|
||||||
|
'-' +
|
||||||
|
this.lessThanTen(this.month) +
|
||||||
|
'-' +
|
||||||
|
this.lessThanTen(this.day)
|
||||||
|
|
||||||
|
let hhmmss = this.lessThanTen(this.hour) +
|
||||||
|
':' +
|
||||||
|
this.lessThanTen(this.minute)
|
||||||
|
|
||||||
|
if (!this.hideSecond) {
|
||||||
|
hhmmss = hhmmss + ':' + this.lessThanTen(this.second)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.type === 'date') {
|
||||||
|
return yymmdd
|
||||||
|
} else if (this.type === 'time') {
|
||||||
|
return hhmmss
|
||||||
|
} else {
|
||||||
|
return yymmdd + ' ' + hhmmss
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化返回值,并抛出 change 事件
|
||||||
|
*/
|
||||||
|
initTime(emit = true) {
|
||||||
|
this.time = this.createDomSting()
|
||||||
|
if (!emit) return
|
||||||
|
if (this.returnType === 'timestamp' && this.type !== 'time') {
|
||||||
|
this.$emit('change', this.createTimeStamp(this.time))
|
||||||
|
this.$emit('input', this.createTimeStamp(this.time))
|
||||||
|
this.$emit('update:modelValue', this.createTimeStamp(this.time))
|
||||||
|
} else {
|
||||||
|
this.$emit('change', this.time)
|
||||||
|
this.$emit('input', this.time)
|
||||||
|
this.$emit('update:modelValue', this.time)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户选择日期或时间更新 data
|
||||||
|
* @param {Object} e
|
||||||
|
*/
|
||||||
|
bindDateChange(e) {
|
||||||
|
const val = e.detail.value
|
||||||
|
this.year = this.years[val[0]]
|
||||||
|
this.month = this.months[val[1]]
|
||||||
|
this.day = this.days[val[2]]
|
||||||
|
},
|
||||||
|
bindTimeChange(e) {
|
||||||
|
const val = e.detail.value
|
||||||
|
this.hour = this.hours[val[0]]
|
||||||
|
this.minute = this.minutes[val[1]]
|
||||||
|
this.second = this.seconds[val[2]]
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化弹出层
|
||||||
|
*/
|
||||||
|
initTimePicker() {
|
||||||
|
if (this.disabled) return
|
||||||
|
const value = fixIosDateFormat(this.time)
|
||||||
|
this.initPickerValue(value)
|
||||||
|
this.visible = !this.visible
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发或关闭弹框
|
||||||
|
*/
|
||||||
|
tiggerTimePicker(e) {
|
||||||
|
this.visible = !this.visible
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点击“清空”按钮,清空当前值
|
||||||
|
*/
|
||||||
|
clearTime() {
|
||||||
|
this.time = ''
|
||||||
|
this.$emit('change', this.time)
|
||||||
|
this.$emit('input', this.time)
|
||||||
|
this.$emit('update:modelValue', this.time)
|
||||||
|
this.tiggerTimePicker()
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点击“确定”按钮
|
||||||
|
*/
|
||||||
|
setTime() {
|
||||||
|
this.initTime()
|
||||||
|
this.tiggerTimePicker()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-primary: #007aff !default;
|
||||||
|
|
||||||
|
.uni-datetime-picker {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
/* width: 100%; */
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-view {
|
||||||
|
height: 130px;
|
||||||
|
width: 270px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-item {
|
||||||
|
height: 50px;
|
||||||
|
line-height: 50px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-btn {
|
||||||
|
margin-top: 60px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-btn-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: $uni-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-btn-group {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-cancel {
|
||||||
|
margin-right: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-mask {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0px;
|
||||||
|
top: 0px;
|
||||||
|
left: 0px;
|
||||||
|
right: 0px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
z-index: 998;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-popup {
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 30px;
|
||||||
|
width: 270px;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
height: 500px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
width: 330px;
|
||||||
|
/* #endif */
|
||||||
|
background-color: #fff;
|
||||||
|
position: fixed;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fix-nvue-height {
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
height: 330px;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-time {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-column {
|
||||||
|
height: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-timebox {
|
||||||
|
|
||||||
|
border: 1px solid #E5E5E5;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 7px 10px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-timebox-pointer {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-datetime-picker-disabled {
|
||||||
|
opacity: 0.4;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: not-allowed !important;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-text {
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 50px
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker-sign {
|
||||||
|
position: absolute;
|
||||||
|
top: 53px;
|
||||||
|
/* 减掉 10px 的元素高度,兼容nvue */
|
||||||
|
color: #999;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
font-size: 16px;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-left {
|
||||||
|
left: 86px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-right {
|
||||||
|
right: 86px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sign-center {
|
||||||
|
left: 135px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-datetime-picker__container-box {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-hide-second {
|
||||||
|
width: 180px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
1064
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue
generated
vendored
Normal file
1064
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
421
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/util.js
generated
vendored
Normal file
421
node_modules/@dcloudio/uni-ui/lib/uni-datetime-picker/util.js
generated
vendored
Normal file
@ -0,0 +1,421 @@
|
|||||||
|
class Calendar {
|
||||||
|
constructor({
|
||||||
|
selected,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
range,
|
||||||
|
} = {}) {
|
||||||
|
// 当前日期
|
||||||
|
this.date = this.getDateObj(new Date()) // 当前初入日期
|
||||||
|
// 打点信息
|
||||||
|
this.selected = selected || [];
|
||||||
|
// 起始时间
|
||||||
|
this.startDate = startDate
|
||||||
|
// 终止时间
|
||||||
|
this.endDate = endDate
|
||||||
|
// 是否范围选择
|
||||||
|
this.range = range
|
||||||
|
// 多选状态
|
||||||
|
this.cleanMultipleStatus()
|
||||||
|
// 每周日期
|
||||||
|
this.weeks = {}
|
||||||
|
this.lastHover = false
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置日期
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
setDate(date) {
|
||||||
|
const selectDate = this.getDateObj(date)
|
||||||
|
this.getWeeks(selectDate.fullDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理多选状态
|
||||||
|
*/
|
||||||
|
cleanMultipleStatus() {
|
||||||
|
this.multipleStatus = {
|
||||||
|
before: '',
|
||||||
|
after: '',
|
||||||
|
data: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setStartDate(startDate) {
|
||||||
|
this.startDate = startDate
|
||||||
|
}
|
||||||
|
|
||||||
|
setEndDate(endDate) {
|
||||||
|
this.endDate = endDate
|
||||||
|
}
|
||||||
|
|
||||||
|
getPreMonthObj(date) {
|
||||||
|
date = fixIosDateFormat(date)
|
||||||
|
date = new Date(date)
|
||||||
|
|
||||||
|
const oldMonth = date.getMonth()
|
||||||
|
date.setMonth(oldMonth - 1)
|
||||||
|
const newMonth = date.getMonth()
|
||||||
|
if (oldMonth !== 0 && newMonth - oldMonth === 0) {
|
||||||
|
date.setMonth(newMonth - 1)
|
||||||
|
}
|
||||||
|
return this.getDateObj(date)
|
||||||
|
}
|
||||||
|
getNextMonthObj(date) {
|
||||||
|
date = fixIosDateFormat(date)
|
||||||
|
date = new Date(date)
|
||||||
|
|
||||||
|
const oldMonth = date.getMonth()
|
||||||
|
date.setMonth(oldMonth + 1)
|
||||||
|
const newMonth = date.getMonth()
|
||||||
|
if (newMonth - oldMonth > 1) {
|
||||||
|
date.setMonth(newMonth - 1)
|
||||||
|
}
|
||||||
|
return this.getDateObj(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定格式Date对象
|
||||||
|
*/
|
||||||
|
getDateObj(date) {
|
||||||
|
date = fixIosDateFormat(date)
|
||||||
|
date = new Date(date)
|
||||||
|
|
||||||
|
return {
|
||||||
|
fullDate: getDate(date),
|
||||||
|
year: date.getFullYear(),
|
||||||
|
month: addZero(date.getMonth() + 1),
|
||||||
|
date: addZero(date.getDate()),
|
||||||
|
day: date.getDay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上一个月日期集合
|
||||||
|
*/
|
||||||
|
getPreMonthDays(amount, dateObj) {
|
||||||
|
const result = []
|
||||||
|
for (let i = amount - 1; i >= 0; i--) {
|
||||||
|
const month = dateObj.month - 1
|
||||||
|
result.push({
|
||||||
|
date: new Date(dateObj.year, month, -i).getDate(),
|
||||||
|
month,
|
||||||
|
disable: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取本月日期集合
|
||||||
|
*/
|
||||||
|
getCurrentMonthDays(amount, dateObj) {
|
||||||
|
const result = []
|
||||||
|
const fullDate = this.date.fullDate
|
||||||
|
for (let i = 1; i <= amount; i++) {
|
||||||
|
const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}`
|
||||||
|
const isToday = fullDate === currentDate
|
||||||
|
// 获取打点信息
|
||||||
|
const info = this.selected && this.selected.find((item) => {
|
||||||
|
if (this.dateEqual(currentDate, item.date)) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 日期禁用
|
||||||
|
let disableBefore = true
|
||||||
|
let disableAfter = true
|
||||||
|
if (this.startDate) {
|
||||||
|
disableBefore = dateCompare(this.startDate, currentDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.endDate) {
|
||||||
|
disableAfter = dateCompare(currentDate, this.endDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
let multiples = this.multipleStatus.data
|
||||||
|
let multiplesStatus = -1
|
||||||
|
if (this.range && multiples) {
|
||||||
|
multiplesStatus = multiples.findIndex((item) => {
|
||||||
|
return this.dateEqual(item, currentDate)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const checked = multiplesStatus !== -1
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
fullDate: currentDate,
|
||||||
|
year: dateObj.year,
|
||||||
|
date: i,
|
||||||
|
multiple: this.range ? checked : false,
|
||||||
|
beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this.multipleStatus.after),
|
||||||
|
afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this.multipleStatus.after),
|
||||||
|
month: dateObj.month,
|
||||||
|
disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !dateCompare(
|
||||||
|
currentDate, this.endDate)),
|
||||||
|
isToday,
|
||||||
|
userChecked: false,
|
||||||
|
extraInfo: info
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取下一个月日期集合
|
||||||
|
*/
|
||||||
|
_getNextMonthDays(amount, dateObj) {
|
||||||
|
const result = []
|
||||||
|
const month = dateObj.month + 1
|
||||||
|
for (let i = 1; i <= amount; i++) {
|
||||||
|
result.push({
|
||||||
|
date: i,
|
||||||
|
month,
|
||||||
|
disable: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期详情
|
||||||
|
* @param {Object} date
|
||||||
|
*/
|
||||||
|
getInfo(date) {
|
||||||
|
if (!date) {
|
||||||
|
date = new Date()
|
||||||
|
}
|
||||||
|
const res = this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate)
|
||||||
|
return res ? res : this.getDateObj(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较时间是否相等
|
||||||
|
*/
|
||||||
|
dateEqual(before, after) {
|
||||||
|
before = new Date(fixIosDateFormat(before))
|
||||||
|
after = new Date(fixIosDateFormat(after))
|
||||||
|
return before.valueOf() === after.valueOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较真实起始日期
|
||||||
|
*/
|
||||||
|
|
||||||
|
isLogicBefore(currentDate, before, after) {
|
||||||
|
let logicBefore = before
|
||||||
|
if (before && after) {
|
||||||
|
logicBefore = dateCompare(before, after) ? before : after
|
||||||
|
}
|
||||||
|
return this.dateEqual(logicBefore, currentDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
isLogicAfter(currentDate, before, after) {
|
||||||
|
let logicAfter = after
|
||||||
|
if (before && after) {
|
||||||
|
logicAfter = dateCompare(before, after) ? after : before
|
||||||
|
}
|
||||||
|
return this.dateEqual(logicAfter, currentDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日期范围内所有日期
|
||||||
|
* @param {Object} begin
|
||||||
|
* @param {Object} end
|
||||||
|
*/
|
||||||
|
geDateAll(begin, end) {
|
||||||
|
var arr = []
|
||||||
|
var ab = begin.split('-')
|
||||||
|
var ae = end.split('-')
|
||||||
|
var db = new Date()
|
||||||
|
db.setFullYear(ab[0], ab[1] - 1, ab[2])
|
||||||
|
var de = new Date()
|
||||||
|
de.setFullYear(ae[0], ae[1] - 1, ae[2])
|
||||||
|
var unixDb = db.getTime() - 24 * 60 * 60 * 1000
|
||||||
|
var unixDe = de.getTime() - 24 * 60 * 60 * 1000
|
||||||
|
for (var k = unixDb; k <= unixDe;) {
|
||||||
|
k = k + 24 * 60 * 60 * 1000
|
||||||
|
arr.push(this.getDateObj(new Date(parseInt(k))).fullDate)
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取多选状态
|
||||||
|
*/
|
||||||
|
setMultiple(fullDate) {
|
||||||
|
if (!this.range) return
|
||||||
|
|
||||||
|
let {
|
||||||
|
before,
|
||||||
|
after
|
||||||
|
} = this.multipleStatus
|
||||||
|
if (before && after) {
|
||||||
|
if (!this.lastHover) {
|
||||||
|
this.lastHover = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.multipleStatus.before = fullDate
|
||||||
|
this.multipleStatus.after = ''
|
||||||
|
this.multipleStatus.data = []
|
||||||
|
this.multipleStatus.fulldate = ''
|
||||||
|
this.lastHover = false
|
||||||
|
} else {
|
||||||
|
if (!before) {
|
||||||
|
this.multipleStatus.before = fullDate
|
||||||
|
this.multipleStatus.after = undefined;
|
||||||
|
this.lastHover = false
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.after = fullDate
|
||||||
|
if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus
|
||||||
|
.after);
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus
|
||||||
|
.before);
|
||||||
|
}
|
||||||
|
this.lastHover = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.getWeeks(fullDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鼠标 hover 更新多选状态
|
||||||
|
*/
|
||||||
|
setHoverMultiple(fullDate) {
|
||||||
|
//抖音小程序点击会触发hover事件,需要避免一下
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
if (!this.range || this.lastHover) return
|
||||||
|
const {
|
||||||
|
before
|
||||||
|
} = this.multipleStatus
|
||||||
|
|
||||||
|
if (!before) {
|
||||||
|
this.multipleStatus.before = fullDate
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.after = fullDate
|
||||||
|
if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.getWeeks(fullDate)
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新默认值多选状态
|
||||||
|
*/
|
||||||
|
setDefaultMultiple(before, after) {
|
||||||
|
this.multipleStatus.before = before
|
||||||
|
this.multipleStatus.after = after
|
||||||
|
if (before && after) {
|
||||||
|
if (dateCompare(before, after)) {
|
||||||
|
this.multipleStatus.data = this.geDateAll(before, after);
|
||||||
|
this.getWeeks(after)
|
||||||
|
} else {
|
||||||
|
this.multipleStatus.data = this.geDateAll(after, before);
|
||||||
|
this.getWeeks(before)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取每周数据
|
||||||
|
* @param {Object} dateData
|
||||||
|
*/
|
||||||
|
getWeeks(dateData) {
|
||||||
|
const {
|
||||||
|
year,
|
||||||
|
month,
|
||||||
|
} = this.getDateObj(dateData)
|
||||||
|
|
||||||
|
const preMonthDayAmount = new Date(year, month - 1, 1).getDay()
|
||||||
|
const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData))
|
||||||
|
|
||||||
|
const currentMonthDayAmount = new Date(year, month, 0).getDate()
|
||||||
|
const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData))
|
||||||
|
|
||||||
|
const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount
|
||||||
|
const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData))
|
||||||
|
|
||||||
|
const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays]
|
||||||
|
|
||||||
|
const weeks = new Array(6)
|
||||||
|
for (let i = 0; i < calendarDays.length; i++) {
|
||||||
|
const index = Math.floor(i / 7)
|
||||||
|
if (!weeks[index]) {
|
||||||
|
weeks[index] = new Array(7)
|
||||||
|
}
|
||||||
|
weeks[index][i % 7] = calendarDays[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
this.calendar = calendarDays
|
||||||
|
this.weeks = weeks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDateTime(date, hideSecond) {
|
||||||
|
return `${getDate(date)} ${getTime(date, hideSecond)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDate(date) {
|
||||||
|
date = fixIosDateFormat(date)
|
||||||
|
date = new Date(date)
|
||||||
|
const year = date.getFullYear()
|
||||||
|
const month = date.getMonth() + 1
|
||||||
|
const day = date.getDate()
|
||||||
|
return `${year}-${addZero(month)}-${addZero(day)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTime(date, hideSecond) {
|
||||||
|
date = fixIosDateFormat(date)
|
||||||
|
date = new Date(date)
|
||||||
|
const hour = date.getHours()
|
||||||
|
const minute = date.getMinutes()
|
||||||
|
const second = date.getSeconds()
|
||||||
|
return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function addZero(num) {
|
||||||
|
if (num < 10) {
|
||||||
|
num = `0${num}`
|
||||||
|
}
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultSecond(hideSecond) {
|
||||||
|
return hideSecond ? '00:00' : '00:00:00'
|
||||||
|
}
|
||||||
|
|
||||||
|
function dateCompare(startDate, endDate) {
|
||||||
|
startDate = new Date(fixIosDateFormat(startDate))
|
||||||
|
endDate = new Date(fixIosDateFormat(endDate))
|
||||||
|
return startDate <= endDate
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkDate(date) {
|
||||||
|
const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g
|
||||||
|
return date.match(dateReg)
|
||||||
|
}
|
||||||
|
//ios低版本15及以下,无法匹配 没有 ’秒‘ 时的情况,所以需要在末尾 秒 加上 问号
|
||||||
|
const dateTimeReg = /^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/;
|
||||||
|
|
||||||
|
function fixIosDateFormat(value) {
|
||||||
|
if (typeof value === 'string' && dateTimeReg.test(value)) {
|
||||||
|
value = value.replace(/-/g, '/')
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Calendar,
|
||||||
|
getDateTime,
|
||||||
|
getDate,
|
||||||
|
getTime,
|
||||||
|
addZero,
|
||||||
|
getDefaultSecond,
|
||||||
|
dateCompare,
|
||||||
|
checkDate,
|
||||||
|
fixIosDateFormat
|
||||||
|
}
|
||||||
45
node_modules/@dcloudio/uni-ui/lib/uni-drawer/keypress.js
generated
vendored
Normal file
45
node_modules/@dcloudio/uni-ui/lib/uni-drawer/keypress.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// #ifdef H5
|
||||||
|
export default {
|
||||||
|
name: 'Keypress',
|
||||||
|
props: {
|
||||||
|
disable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
const keyNames = {
|
||||||
|
esc: ['Esc', 'Escape'],
|
||||||
|
tab: 'Tab',
|
||||||
|
enter: 'Enter',
|
||||||
|
space: [' ', 'Spacebar'],
|
||||||
|
up: ['Up', 'ArrowUp'],
|
||||||
|
left: ['Left', 'ArrowLeft'],
|
||||||
|
right: ['Right', 'ArrowRight'],
|
||||||
|
down: ['Down', 'ArrowDown'],
|
||||||
|
delete: ['Backspace', 'Delete', 'Del']
|
||||||
|
}
|
||||||
|
const listener = ($event) => {
|
||||||
|
if (this.disable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const keyName = Object.keys(keyNames).find(key => {
|
||||||
|
const keyName = $event.key
|
||||||
|
const value = keyNames[key]
|
||||||
|
return value === keyName || (Array.isArray(value) && value.includes(keyName))
|
||||||
|
})
|
||||||
|
if (keyName) {
|
||||||
|
// 避免和其他按键事件冲突
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$emit(keyName, {})
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener('keyup', listener)
|
||||||
|
// this.$once('hook:beforeDestroy', () => {
|
||||||
|
// document.removeEventListener('keyup', listener)
|
||||||
|
// })
|
||||||
|
},
|
||||||
|
render: () => {}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
183
node_modules/@dcloudio/uni-ui/lib/uni-drawer/uni-drawer.vue
generated
vendored
Normal file
183
node_modules/@dcloudio/uni-ui/lib/uni-drawer/uni-drawer.vue
generated
vendored
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
<template>
|
||||||
|
<view v-if="visibleSync" :class="{ 'uni-drawer--visible': showDrawer }" class="uni-drawer" @touchmove.stop.prevent="clear">
|
||||||
|
<view class="uni-drawer__mask" :class="{ 'uni-drawer__mask--visible': showDrawer && mask }" @tap="close('mask')" />
|
||||||
|
<view class="uni-drawer__content" :class="{'uni-drawer--right': rightMode,'uni-drawer--left': !rightMode, 'uni-drawer__content--visible': showDrawer}" :style="{width:drawerWidth+'px'}">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
<!-- #ifdef H5 -->
|
||||||
|
<keypress @esc="close('mask')" />
|
||||||
|
<!-- #endif -->
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// #ifdef H5
|
||||||
|
import keypress from './keypress.js'
|
||||||
|
// #endif
|
||||||
|
/**
|
||||||
|
* Drawer 抽屉
|
||||||
|
* @description 抽屉侧滑菜单
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=26
|
||||||
|
* @property {Boolean} mask = [true | false] 是否显示遮罩
|
||||||
|
* @property {Boolean} maskClick = [true | false] 点击遮罩是否关闭
|
||||||
|
* @property {Boolean} mode = [left | right] Drawer 滑出位置
|
||||||
|
* @value left 从左侧滑出
|
||||||
|
* @value right 从右侧侧滑出
|
||||||
|
* @property {Number} width 抽屉的宽度 ,仅 vue 页面生效
|
||||||
|
* @event {Function} close 组件关闭时触发事件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniDrawer',
|
||||||
|
components: {
|
||||||
|
// #ifdef H5
|
||||||
|
keypress
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
emits:['change'],
|
||||||
|
props: {
|
||||||
|
/**
|
||||||
|
* 显示模式(左、右),只在初始化生效
|
||||||
|
*/
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 蒙层显示状态
|
||||||
|
*/
|
||||||
|
mask: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 遮罩是否可点击关闭
|
||||||
|
*/
|
||||||
|
maskClick:{
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 抽屉宽度
|
||||||
|
*/
|
||||||
|
width: {
|
||||||
|
type: Number,
|
||||||
|
default: 220
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
visibleSync: false,
|
||||||
|
showDrawer: false,
|
||||||
|
rightMode: false,
|
||||||
|
watchTimer: null,
|
||||||
|
drawerWidth: 220
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
this.drawerWidth = this.width
|
||||||
|
// #endif
|
||||||
|
this.rightMode = this.mode === 'right'
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
clear(){},
|
||||||
|
close(type) {
|
||||||
|
// fixed by mehaotian 抽屉尚未完全关闭或遮罩禁止点击时不触发以下逻辑
|
||||||
|
if((type === 'mask' && !this.maskClick) || !this.visibleSync) return
|
||||||
|
this._change('showDrawer', 'visibleSync', false)
|
||||||
|
},
|
||||||
|
open() {
|
||||||
|
// fixed by mehaotian 处理重复点击打开的事件
|
||||||
|
if(this.visibleSync) return
|
||||||
|
this._change('visibleSync', 'showDrawer', true)
|
||||||
|
},
|
||||||
|
_change(param1, param2, status) {
|
||||||
|
this[param1] = status
|
||||||
|
if (this.watchTimer) {
|
||||||
|
clearTimeout(this.watchTimer)
|
||||||
|
}
|
||||||
|
this.watchTimer = setTimeout(() => {
|
||||||
|
this[param2] = status
|
||||||
|
this.$emit('change',status)
|
||||||
|
}, status ? 50 : 300)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
$uni-mask: rgba($color: #000000, $alpha: 0.4) ;
|
||||||
|
// 抽屉宽度
|
||||||
|
$drawer-width: 220px;
|
||||||
|
|
||||||
|
.uni-drawer {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: block;
|
||||||
|
/* #endif */
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-drawer__content {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: block;
|
||||||
|
/* #endif */
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
width: $drawer-width;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: $uni-bg-color;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-drawer--left {
|
||||||
|
left: 0;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
transform: translateX(-$drawer-width);
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
transform: translateX(-100%);
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-drawer--right {
|
||||||
|
right: 0;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
transform: translateX($drawer-width);
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
transform: translateX(100%);
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-drawer__content--visible {
|
||||||
|
transform: translateX(0px);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-drawer__mask {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: block;
|
||||||
|
/* #endif */
|
||||||
|
opacity: 0;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
background-color: $uni-mask;
|
||||||
|
transition: opacity 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-drawer__mask--visible {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: block;
|
||||||
|
/* #endif */
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
54
node_modules/@dcloudio/uni-ui/lib/uni-easyinput/common.js
generated
vendored
Normal file
54
node_modules/@dcloudio/uni-ui/lib/uni-easyinput/common.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* @desc 函数防抖
|
||||||
|
* @param func 目标函数
|
||||||
|
* @param wait 延迟执行毫秒数
|
||||||
|
* @param immediate true - 立即执行, false - 延迟执行
|
||||||
|
*/
|
||||||
|
export const debounce = function(func, wait = 1000, immediate = true) {
|
||||||
|
let timer;
|
||||||
|
return function() {
|
||||||
|
let context = this,
|
||||||
|
args = arguments;
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
if (immediate) {
|
||||||
|
let callNow = !timer;
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
timer = null;
|
||||||
|
}, wait);
|
||||||
|
if (callNow) func.apply(context, args);
|
||||||
|
} else {
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
func.apply(context, args);
|
||||||
|
}, wait)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @desc 函数节流
|
||||||
|
* @param func 函数
|
||||||
|
* @param wait 延迟执行毫秒数
|
||||||
|
* @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
|
||||||
|
*/
|
||||||
|
export const throttle = (func, wait = 1000, type = 1) => {
|
||||||
|
let previous = 0;
|
||||||
|
let timeout;
|
||||||
|
return function() {
|
||||||
|
let context = this;
|
||||||
|
let args = arguments;
|
||||||
|
if (type === 1) {
|
||||||
|
let now = Date.now();
|
||||||
|
|
||||||
|
if (now - previous > wait) {
|
||||||
|
func.apply(context, args);
|
||||||
|
previous = now;
|
||||||
|
}
|
||||||
|
} else if (type === 2) {
|
||||||
|
if (!timeout) {
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
timeout = null;
|
||||||
|
func.apply(context, args)
|
||||||
|
}, wait)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
676
node_modules/@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.vue
generated
vendored
Normal file
676
node_modules/@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.vue
generated
vendored
Normal file
@ -0,0 +1,676 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-easyinput" :class="{ 'uni-easyinput-error': msg }" :style="boxStyle">
|
||||||
|
<view class="uni-easyinput__content" :class="inputContentClass" :style="inputContentStyle">
|
||||||
|
<uni-icons v-if="prefixIcon" class="content-clear-icon" :type="prefixIcon" color="#c0c4cc" @click="onClickIcon('prefix')" size="22"></uni-icons>
|
||||||
|
<slot name="left">
|
||||||
|
</slot>
|
||||||
|
<!-- #ifdef MP-ALIPAY -->
|
||||||
|
<textarea :enableNative="enableNative" v-if="type === 'textarea'" class="uni-easyinput__content-textarea" :class="{ 'input-padding': inputBorder }" :name="name" :value="val" :placeholder="placeholder" :placeholderStyle="placeholderStyle" :disabled="disabled" placeholder-class="uni-easyinput__placeholder-class" :maxlength="inputMaxlength" :focus="focused" :autoHeight="autoHeight" :cursor-spacing="cursorSpacing" :adjust-position="adjustPosition" @input="onInput" @blur="_Blur" @focus="_Focus" @confirm="onConfirm" @keyboardheightchange="onkeyboardheightchange"></textarea>
|
||||||
|
<input :enableNative="enableNative" v-else :type="type === 'password' ? 'text' : type" class="uni-easyinput__content-input" :style="inputStyle" :name="name" :value="val" :password="!showPassword && type === 'password'" :placeholder="placeholder" :placeholderStyle="placeholderStyle" placeholder-class="uni-easyinput__placeholder-class" :disabled="disabled" :maxlength="inputMaxlength" :focus="focused" :confirmType="confirmType" :cursor-spacing="cursorSpacing" :adjust-position="adjustPosition" @focus="_Focus" @blur="_Blur" @input="onInput" @confirm="onConfirm" @keyboardheightchange="onkeyboardheightchange" />
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifndef MP-ALIPAY -->
|
||||||
|
<textarea v-if="type === 'textarea'" class="uni-easyinput__content-textarea" :class="{ 'input-padding': inputBorder }" :name="name" :value="val" :placeholder="placeholder" :placeholderStyle="placeholderStyle" :disabled="disabled" placeholder-class="uni-easyinput__placeholder-class" :maxlength="inputMaxlength" :focus="focused" :autoHeight="autoHeight" :cursor-spacing="cursorSpacing" :adjust-position="adjustPosition" @input="onInput" @blur="_Blur" @focus="_Focus" @confirm="onConfirm" @keyboardheightchange="onkeyboardheightchange"></textarea>
|
||||||
|
<input v-else :type="type === 'password' ? 'text' : type" class="uni-easyinput__content-input" :style="inputStyle" :name="name" :value="val" :password="!showPassword && type === 'password'" :placeholder="placeholder" :placeholderStyle="placeholderStyle" placeholder-class="uni-easyinput__placeholder-class" :disabled="disabled" :maxlength="inputMaxlength" :focus="focused" :confirmType="confirmType" :cursor-spacing="cursorSpacing" :adjust-position="adjustPosition" @focus="_Focus" @blur="_Blur" @input="onInput" @confirm="onConfirm" @keyboardheightchange="onkeyboardheightchange" />
|
||||||
|
<!-- #endif -->
|
||||||
|
|
||||||
|
<template v-if="type === 'password' && passwordIcon">
|
||||||
|
<!-- 开启密码时显示小眼睛 -->
|
||||||
|
<uni-icons v-if="isVal" class="content-clear-icon" :class="{ 'is-textarea-icon': type === 'textarea' }" :type="showPassword ? 'eye-slash-filled' : 'eye-filled'" :size="22" :color="focusShow ? primaryColor : '#c0c4cc'" @click="onEyes"></uni-icons>
|
||||||
|
</template>
|
||||||
|
<template v-if="suffixIcon">
|
||||||
|
<uni-icons v-if="suffixIcon" class="content-clear-icon" :type="suffixIcon" color="#c0c4cc" @click="onClickIcon('suffix')" size="22"></uni-icons>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<uni-icons v-if="clearable && isVal && !disabled && type !== 'textarea'" class="content-clear-icon" :class="{ 'is-textarea-icon': type === 'textarea' }" type="clear" :size="clearSize" :color="msg ? '#dd524d' : focusShow ? primaryColor : '#c0c4cc'" @click="onClear"></uni-icons>
|
||||||
|
</template>
|
||||||
|
<slot name="right"></slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Easyinput 输入框
|
||||||
|
* @description 此组件可以实现表单的输入与校验,包括 "text" 和 "textarea" 类型。
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3455
|
||||||
|
* @property {String} value 输入内容
|
||||||
|
* @property {String } type 输入框的类型(默认text) password/text/textarea/..
|
||||||
|
* @value text 文本输入键盘
|
||||||
|
* @value textarea 多行文本输入键盘
|
||||||
|
* @value password 密码输入键盘
|
||||||
|
* @value number 数字输入键盘,注意iOS上app-vue弹出的数字键盘并非9宫格方式
|
||||||
|
* @value idcard 身份证输入键盘,信、支付宝、百度、QQ小程序
|
||||||
|
* @value digit 带小数点的数字键盘 ,App的nvue页面、微信、支付宝、百度、头条、QQ小程序支持
|
||||||
|
* @property {Boolean} clearable 是否显示右侧清空内容的图标控件,点击可清空输入框内容(默认true)
|
||||||
|
* @property {Boolean} autoHeight 是否自动增高输入区域,type为textarea时有效(默认true)
|
||||||
|
* @property {String } placeholder 输入框的提示文字
|
||||||
|
* @property {String } placeholderStyle placeholder的样式(内联样式,字符串),如"color: #ddd"
|
||||||
|
* @property {Boolean} focus 是否自动获得焦点(默认false)
|
||||||
|
* @property {Boolean} disabled 是否禁用(默认false)
|
||||||
|
* @property {Number } maxlength 最大输入长度,设置为 -1 的时候不限制最大长度(默认140)
|
||||||
|
* @property {String } confirmType 设置键盘右下角按钮的文字,仅在type="text"时生效(默认done)
|
||||||
|
* @property {Number } clearSize 清除图标的大小,单位px(默认15)
|
||||||
|
* @property {String} prefixIcon 输入框头部图标
|
||||||
|
* @property {String} suffixIcon 输入框尾部图标
|
||||||
|
* @property {String} primaryColor 设置主题色(默认#2979ff)
|
||||||
|
* @property {Boolean} trim 是否自动去除两端的空格
|
||||||
|
* @property {Boolean} cursorSpacing 指定光标与键盘的距离,单位 px
|
||||||
|
* @property {Boolean} ajust-position 当键盘弹起时,是否上推内容,默认值:true
|
||||||
|
* @value both 去除两端空格
|
||||||
|
* @value left 去除左侧空格
|
||||||
|
* @value right 去除右侧空格
|
||||||
|
* @value start 去除左侧空格
|
||||||
|
* @value end 去除右侧空格
|
||||||
|
* @value all 去除全部空格
|
||||||
|
* @value none 不去除空格
|
||||||
|
* @property {Boolean} inputBorder 是否显示input输入框的边框(默认true)
|
||||||
|
* @property {Boolean} passwordIcon type=password时是否显示小眼睛图标
|
||||||
|
* @property {Object} styles 自定义颜色
|
||||||
|
* @event {Function} input 输入框内容发生变化时触发
|
||||||
|
* @event {Function} focus 输入框获得焦点时触发
|
||||||
|
* @event {Function} blur 输入框失去焦点时触发
|
||||||
|
* @event {Function} confirm 点击完成按钮时触发
|
||||||
|
* @event {Function} iconClick 点击图标时触发
|
||||||
|
* @example <uni-easyinput v-model="mobile"></uni-easyinput>
|
||||||
|
*/
|
||||||
|
function obj2strClass(obj) {
|
||||||
|
let classess = '';
|
||||||
|
for (let key in obj) {
|
||||||
|
const val = obj[key];
|
||||||
|
if (val) {
|
||||||
|
classess += `${key} `;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return classess;
|
||||||
|
}
|
||||||
|
|
||||||
|
function obj2strStyle(obj) {
|
||||||
|
let style = '';
|
||||||
|
for (let key in obj) {
|
||||||
|
const val = obj[key];
|
||||||
|
style += `${key}:${val};`;
|
||||||
|
}
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
export default {
|
||||||
|
name: 'uni-easyinput',
|
||||||
|
emits: [
|
||||||
|
'click',
|
||||||
|
'iconClick',
|
||||||
|
'update:modelValue',
|
||||||
|
'input',
|
||||||
|
'focus',
|
||||||
|
'blur',
|
||||||
|
'confirm',
|
||||||
|
'clear',
|
||||||
|
'eyes',
|
||||||
|
'change',
|
||||||
|
'keyboardheightchange'
|
||||||
|
],
|
||||||
|
model: {
|
||||||
|
prop: 'modelValue',
|
||||||
|
event: 'update:modelValue'
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
inject: {
|
||||||
|
form: {
|
||||||
|
from: 'uniForm',
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
formItem: {
|
||||||
|
from: 'uniFormItem',
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
name: String,
|
||||||
|
value: [Number, String],
|
||||||
|
modelValue: [Number, String],
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'text'
|
||||||
|
},
|
||||||
|
clearable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
autoHeight: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
type: String,
|
||||||
|
default: ' '
|
||||||
|
},
|
||||||
|
placeholderStyle: String,
|
||||||
|
focus: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
maxlength: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 140
|
||||||
|
},
|
||||||
|
confirmType: {
|
||||||
|
type: String,
|
||||||
|
default: 'done'
|
||||||
|
},
|
||||||
|
clearSize: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 24
|
||||||
|
},
|
||||||
|
inputBorder: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
prefixIcon: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
suffixIcon: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
trim: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
cursorSpacing: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
passwordIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
adjustPosition: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
primaryColor: {
|
||||||
|
type: String,
|
||||||
|
default: '#2979ff'
|
||||||
|
},
|
||||||
|
styles: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
color: '#333',
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
disableColor: '#F7F6F6',
|
||||||
|
borderColor: '#e5e5e5'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorMessage: {
|
||||||
|
type: [String, Boolean],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// #ifdef MP-ALIPAY
|
||||||
|
enableNative: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
focused: false,
|
||||||
|
val: '',
|
||||||
|
showMsg: '',
|
||||||
|
border: false,
|
||||||
|
isFirstBorder: false,
|
||||||
|
showClearIcon: false,
|
||||||
|
showPassword: false,
|
||||||
|
focusShow: false,
|
||||||
|
localMsg: '',
|
||||||
|
isEnter: false // 用于判断当前是否是使用回车操作
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// 输入框内是否有值
|
||||||
|
isVal() {
|
||||||
|
const val = this.val;
|
||||||
|
// fixed by mehaotian 处理值为0的情况,字符串0不在处理范围
|
||||||
|
if (val || val === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
msg() {
|
||||||
|
// console.log('computed', this.form, this.formItem);
|
||||||
|
// if (this.form) {
|
||||||
|
// return this.errorMessage || this.formItem.errMsg;
|
||||||
|
// }
|
||||||
|
// TODO 处理头条 formItem 中 errMsg 不更新的问题
|
||||||
|
return this.localMsg || this.errorMessage;
|
||||||
|
},
|
||||||
|
// 因为uniapp的input组件的maxlength组件必须要数值,这里转为数值,用户可以传入字符串数值
|
||||||
|
inputMaxlength() {
|
||||||
|
return Number(this.maxlength);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 处理外层样式的style
|
||||||
|
boxStyle() {
|
||||||
|
return `color:${
|
||||||
|
this.inputBorder && this.msg ? '#e43d33' : this.styles.color
|
||||||
|
};`;
|
||||||
|
},
|
||||||
|
// input 内容的类和样式处理
|
||||||
|
inputContentClass() {
|
||||||
|
return obj2strClass({
|
||||||
|
'is-input-border': this.inputBorder,
|
||||||
|
'is-input-error-border': this.inputBorder && this.msg,
|
||||||
|
'is-textarea': this.type === 'textarea',
|
||||||
|
'is-disabled': this.disabled,
|
||||||
|
'is-focused': this.focusShow
|
||||||
|
});
|
||||||
|
},
|
||||||
|
inputContentStyle() {
|
||||||
|
const focusColor = this.focusShow ?
|
||||||
|
this.primaryColor :
|
||||||
|
this.styles.borderColor;
|
||||||
|
const borderColor =
|
||||||
|
this.inputBorder && this.msg ? '#dd524d' : focusColor;
|
||||||
|
return obj2strStyle({
|
||||||
|
'border-color': borderColor || '#e5e5e5',
|
||||||
|
'background-color': this.disabled ?
|
||||||
|
this.styles.disableColor : this.styles.backgroundColor
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// input右侧样式
|
||||||
|
inputStyle() {
|
||||||
|
const paddingRight =
|
||||||
|
this.type === 'password' || this.clearable || this.prefixIcon ?
|
||||||
|
'' :
|
||||||
|
'10px';
|
||||||
|
return obj2strStyle({
|
||||||
|
'padding-right': paddingRight,
|
||||||
|
'padding-left': this.prefixIcon ? '' : '10px'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value(newVal) {
|
||||||
|
// fix by mehaotian 解决 值为null的情况下,input报错的bug
|
||||||
|
if (newVal === null) {
|
||||||
|
this.val = '';
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.val = newVal;
|
||||||
|
},
|
||||||
|
modelValue(newVal) {
|
||||||
|
if (newVal === null) {
|
||||||
|
this.val = '';
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.val = newVal;
|
||||||
|
},
|
||||||
|
focus(newVal) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.focused = this.focus;
|
||||||
|
this.focusShow = this.focus;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.init();
|
||||||
|
// TODO 处理头条vue3 computed 不监听 inject 更改的问题(formItem.errMsg)
|
||||||
|
if (this.form && this.formItem) {
|
||||||
|
this.$watch('formItem.errMsg', newVal => {
|
||||||
|
this.localMsg = newVal;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.focused = this.focus;
|
||||||
|
this.focusShow = this.focus;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 初始化变量值
|
||||||
|
*/
|
||||||
|
init() {
|
||||||
|
if (this.value || this.value === 0) {
|
||||||
|
this.val = this.value;
|
||||||
|
} else if (
|
||||||
|
this.modelValue ||
|
||||||
|
this.modelValue === 0 ||
|
||||||
|
this.modelValue === ''
|
||||||
|
) {
|
||||||
|
this.val = this.modelValue;
|
||||||
|
} else {
|
||||||
|
// fix by ht 如果初始值为null,则input报错,待框架修复
|
||||||
|
this.val = '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击图标时触发
|
||||||
|
* @param {Object} type
|
||||||
|
*/
|
||||||
|
onClickIcon(type) {
|
||||||
|
this.$emit('iconClick', type);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示隐藏内容,密码框时生效
|
||||||
|
*/
|
||||||
|
onEyes() {
|
||||||
|
this.showPassword = !this.showPassword;
|
||||||
|
this.$emit('eyes', this.showPassword);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入时触发
|
||||||
|
* @param {Object} event
|
||||||
|
*/
|
||||||
|
onInput(event) {
|
||||||
|
let value = event.detail.value;
|
||||||
|
// 判断是否去除空格
|
||||||
|
if (this.trim) {
|
||||||
|
if (typeof this.trim === 'boolean' && this.trim) {
|
||||||
|
value = this.trimStr(value);
|
||||||
|
}
|
||||||
|
if (typeof this.trim === 'string') {
|
||||||
|
value = this.trimStr(value, this.trim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.errMsg) this.errMsg = '';
|
||||||
|
this.val = value;
|
||||||
|
// TODO 兼容 vue2
|
||||||
|
this.$emit('input', value);
|
||||||
|
// TODO 兼容 vue3
|
||||||
|
this.$emit('update:modelValue', value);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 获取焦点时触发
|
||||||
|
* @param {Object} event
|
||||||
|
*/
|
||||||
|
onFocus() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.focused = true;
|
||||||
|
});
|
||||||
|
this.$emit('focus', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
_Focus(event) {
|
||||||
|
this.focusShow = true;
|
||||||
|
this.$emit('focus', event);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 失去焦点时触发
|
||||||
|
* @param {Object} event
|
||||||
|
*/
|
||||||
|
onBlur() {
|
||||||
|
this.focused = false;
|
||||||
|
this.$emit('blur', null);
|
||||||
|
},
|
||||||
|
_Blur(event) {
|
||||||
|
let value = event.detail.value;
|
||||||
|
this.focusShow = false;
|
||||||
|
this.$emit('blur', event);
|
||||||
|
// 根据类型返回值,在event中获取的值理论上讲都是string
|
||||||
|
if (this.isEnter === false) {
|
||||||
|
this.$emit('change', this.val);
|
||||||
|
}
|
||||||
|
// 失去焦点时参与表单校验
|
||||||
|
if (this.form && this.formItem) {
|
||||||
|
const { validateTrigger } = this.form;
|
||||||
|
if (validateTrigger === 'blur') {
|
||||||
|
this.formItem.onFieldChange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按下键盘的发送键
|
||||||
|
* @param {Object} e
|
||||||
|
*/
|
||||||
|
onConfirm(e) {
|
||||||
|
this.$emit('confirm', this.val);
|
||||||
|
this.isEnter = true;
|
||||||
|
this.$emit('change', this.val);
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.isEnter = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理内容
|
||||||
|
* @param {Object} event
|
||||||
|
*/
|
||||||
|
onClear(event) {
|
||||||
|
this.val = '';
|
||||||
|
// TODO 兼容 vue2
|
||||||
|
this.$emit('input', '');
|
||||||
|
// TODO 兼容 vue2
|
||||||
|
// TODO 兼容 vue3
|
||||||
|
this.$emit('update:modelValue', '');
|
||||||
|
// 点击叉号触发
|
||||||
|
this.$emit('clear');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 键盘高度发生变化的时候触发此事件
|
||||||
|
* 兼容性:微信小程序2.7.0+、App 3.1.0+
|
||||||
|
* @param {Object} event
|
||||||
|
*/
|
||||||
|
onkeyboardheightchange(event) {
|
||||||
|
this.$emit('keyboardheightchange', event);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去除空格
|
||||||
|
*/
|
||||||
|
trimStr(str, pos = 'both') {
|
||||||
|
if (pos === 'both') {
|
||||||
|
return str.trim();
|
||||||
|
} else if (pos === 'left') {
|
||||||
|
return str.trimLeft();
|
||||||
|
} else if (pos === 'right') {
|
||||||
|
return str.trimRight();
|
||||||
|
} else if (pos === 'start') {
|
||||||
|
return str.trimStart();
|
||||||
|
} else if (pos === 'end') {
|
||||||
|
return str.trimEnd();
|
||||||
|
} else if (pos === 'all') {
|
||||||
|
return str.replace(/\s+/g, '');
|
||||||
|
} else if (pos === 'none') {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
$uni-error: #e43d33;
|
||||||
|
$uni-border-1: #dcdfe6 !default;
|
||||||
|
|
||||||
|
.uni-easyinput {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: 100%;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
position: relative;
|
||||||
|
text-align: left;
|
||||||
|
color: #333;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput__content {
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
box-sizing: border-box;
|
||||||
|
// min-height: 36px;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
// 处理border动画刚开始显示黑色的问题
|
||||||
|
border-color: #fff;
|
||||||
|
transition-property: border-color;
|
||||||
|
transition-duration: 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput__content-input {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
width: auto;
|
||||||
|
/* #endif */
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
flex: 1;
|
||||||
|
line-height: 1;
|
||||||
|
font-size: 14px;
|
||||||
|
height: 35px;
|
||||||
|
// min-height: 36px;
|
||||||
|
|
||||||
|
/*ifdef H5*/
|
||||||
|
& ::-ms-reveal {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
& ::-ms-clear {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
& ::-o-clear {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*endif*/
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput__placeholder-class {
|
||||||
|
color: #999;
|
||||||
|
font-size: 12px;
|
||||||
|
// font-weight: 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-textarea {
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-textarea-icon {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput__content-textarea {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
flex: 1;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-size: 14px;
|
||||||
|
margin: 6px;
|
||||||
|
margin-left: 0;
|
||||||
|
height: 80px;
|
||||||
|
min-height: 80px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
min-height: 80px;
|
||||||
|
width: auto;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-padding {
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-clear-icon {
|
||||||
|
padding: 0 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label-icon {
|
||||||
|
margin-right: 5px;
|
||||||
|
margin-top: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示边框
|
||||||
|
.is-input-border {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
border: 1px solid $uni-border-1;
|
||||||
|
border-radius: 4px;
|
||||||
|
/* #ifdef MP-ALIPAY */
|
||||||
|
overflow: hidden;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-error-message {
|
||||||
|
position: absolute;
|
||||||
|
bottom: -17px;
|
||||||
|
left: 0;
|
||||||
|
line-height: 12px;
|
||||||
|
color: $uni-error;
|
||||||
|
font-size: 12px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-error-msg--boeder {
|
||||||
|
position: relative;
|
||||||
|
bottom: 0;
|
||||||
|
line-height: 22px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-input-error-border {
|
||||||
|
border-color: $uni-error;
|
||||||
|
|
||||||
|
.uni-easyinput__placeholder-class {
|
||||||
|
color: mix(#fff, $uni-error, 50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput--border {
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: 10px 15px;
|
||||||
|
// padding-bottom: 0;
|
||||||
|
border-top: 1px #eee solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-easyinput-error {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-first-border {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
border: none;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
border-width: 0;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-disabled {
|
||||||
|
background-color: #f7f6f6;
|
||||||
|
color: #d5d5d5;
|
||||||
|
|
||||||
|
.uni-easyinput__placeholder-class {
|
||||||
|
color: #d5d5d5;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
491
node_modules/@dcloudio/uni-ui/lib/uni-fab/uni-fab.vue
generated
vendored
Normal file
491
node_modules/@dcloudio/uni-ui/lib/uni-fab/uni-fab.vue
generated
vendored
Normal file
@ -0,0 +1,491 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-cursor-point">
|
||||||
|
<view v-if="popMenu && (leftBottom||rightBottom||leftTop||rightTop) && content.length > 0" :class="{
|
||||||
|
'uni-fab--leftBottom': leftBottom,
|
||||||
|
'uni-fab--rightBottom': rightBottom,
|
||||||
|
'uni-fab--leftTop': leftTop,
|
||||||
|
'uni-fab--rightTop': rightTop
|
||||||
|
}" class="uni-fab"
|
||||||
|
:style="nvueBottom"
|
||||||
|
>
|
||||||
|
<view :class="{
|
||||||
|
'uni-fab__content--left': horizontal === 'left',
|
||||||
|
'uni-fab__content--right': horizontal === 'right',
|
||||||
|
'uni-fab__content--flexDirection': direction === 'vertical',
|
||||||
|
'uni-fab__content--flexDirectionStart': flexDirectionStart,
|
||||||
|
'uni-fab__content--flexDirectionEnd': flexDirectionEnd,
|
||||||
|
'uni-fab__content--other-platform': !isAndroidNvue
|
||||||
|
}" :style="{ width: boxWidth, height: boxHeight, backgroundColor: styles.backgroundColor }"
|
||||||
|
class="uni-fab__content" elevation="5">
|
||||||
|
<view v-if="flexDirectionStart || horizontalLeft" class="uni-fab__item uni-fab__item--first" />
|
||||||
|
<view v-for="(item, index) in content" :key="index" :class="{ 'uni-fab__item--active': isShow }"
|
||||||
|
class="uni-fab__item" @click="_onItemClick(index, item)">
|
||||||
|
<image :src="item.active ? item.selectedIconPath : item.iconPath" class="uni-fab__item-image"
|
||||||
|
mode="aspectFit" />
|
||||||
|
<text class="uni-fab__item-text"
|
||||||
|
:style="{ color: item.active ? styles.selectedColor : styles.color }">{{ item.text }}</text>
|
||||||
|
</view>
|
||||||
|
<view v-if="flexDirectionEnd || horizontalRight" class="uni-fab__item uni-fab__item--first" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view :class="{
|
||||||
|
'uni-fab__circle--leftBottom': leftBottom,
|
||||||
|
'uni-fab__circle--rightBottom': rightBottom,
|
||||||
|
'uni-fab__circle--leftTop': leftTop,
|
||||||
|
'uni-fab__circle--rightTop': rightTop,
|
||||||
|
'uni-fab__content--other-platform': !isAndroidNvue
|
||||||
|
}" class="uni-fab__circle uni-fab__plus" :style="{ 'background-color': styles.buttonColor, 'bottom': nvueBottom }" @click="_onClick">
|
||||||
|
<uni-icons class="fab-circle-icon" :type="styles.icon" :color="styles.iconColor" size="32"
|
||||||
|
:class="{'uni-fab__plus--active': isShow && content.length > 0}"></uni-icons>
|
||||||
|
<!-- <view class="fab-circle-v" :class="{'uni-fab__plus--active': isShow && content.length > 0}"></view>
|
||||||
|
<view class="fab-circle-h" :class="{'uni-fab__plus--active': isShow && content.length > 0}"></view> -->
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let platform = 'other'
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
platform = uni.getSystemInfoSync().platform
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fab 悬浮按钮
|
||||||
|
* @description 点击可展开一个图形按钮菜单
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=144
|
||||||
|
* @property {Object} pattern 可选样式配置项
|
||||||
|
* @property {Object} horizontal = [left | right] 水平对齐方式
|
||||||
|
* @value left 左对齐
|
||||||
|
* @value right 右对齐
|
||||||
|
* @property {Object} vertical = [bottom | top] 垂直对齐方式
|
||||||
|
* @value bottom 下对齐
|
||||||
|
* @value top 上对齐
|
||||||
|
* @property {Object} direction = [horizontal | vertical] 展开菜单显示方式
|
||||||
|
* @value horizontal 水平显示
|
||||||
|
* @value vertical 垂直显示
|
||||||
|
* @property {Array} content 展开菜单内容配置项
|
||||||
|
* @property {Boolean} popMenu 是否使用弹出菜单
|
||||||
|
* @event {Function} trigger 展开菜单点击事件,返回点击信息
|
||||||
|
* @event {Function} fabClick 悬浮按钮点击事件
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniFab',
|
||||||
|
emits: ['fabClick', 'trigger'],
|
||||||
|
props: {
|
||||||
|
pattern: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
horizontal: {
|
||||||
|
type: String,
|
||||||
|
default: 'left'
|
||||||
|
},
|
||||||
|
vertical: {
|
||||||
|
type: String,
|
||||||
|
default: 'bottom'
|
||||||
|
},
|
||||||
|
direction: {
|
||||||
|
type: String,
|
||||||
|
default: 'horizontal'
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
popMenu: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
fabShow: false,
|
||||||
|
isShow: false,
|
||||||
|
isAndroidNvue: platform === 'android',
|
||||||
|
styles: {
|
||||||
|
color: '#3c3e49',
|
||||||
|
selectedColor: '#007AFF',
|
||||||
|
backgroundColor: '#fff',
|
||||||
|
buttonColor: '#007AFF',
|
||||||
|
iconColor: '#fff',
|
||||||
|
icon: 'plusempty'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
contentWidth(e) {
|
||||||
|
return (this.content.length + 1) * 55 + 15 + 'px'
|
||||||
|
},
|
||||||
|
contentWidthMin() {
|
||||||
|
return '55px'
|
||||||
|
},
|
||||||
|
// 动态计算宽度
|
||||||
|
boxWidth() {
|
||||||
|
return this.getPosition(3, 'horizontal')
|
||||||
|
},
|
||||||
|
// 动态计算高度
|
||||||
|
boxHeight() {
|
||||||
|
return this.getPosition(3, 'vertical')
|
||||||
|
},
|
||||||
|
// 计算左下位置
|
||||||
|
leftBottom() {
|
||||||
|
return this.getPosition(0, 'left', 'bottom')
|
||||||
|
},
|
||||||
|
// 计算右下位置
|
||||||
|
rightBottom() {
|
||||||
|
return this.getPosition(0, 'right', 'bottom')
|
||||||
|
},
|
||||||
|
// 计算左上位置
|
||||||
|
leftTop() {
|
||||||
|
return this.getPosition(0, 'left', 'top')
|
||||||
|
},
|
||||||
|
rightTop() {
|
||||||
|
return this.getPosition(0, 'right', 'top')
|
||||||
|
},
|
||||||
|
flexDirectionStart() {
|
||||||
|
return this.getPosition(1, 'vertical', 'top')
|
||||||
|
},
|
||||||
|
flexDirectionEnd() {
|
||||||
|
return this.getPosition(1, 'vertical', 'bottom')
|
||||||
|
},
|
||||||
|
horizontalLeft() {
|
||||||
|
return this.getPosition(2, 'horizontal', 'left')
|
||||||
|
},
|
||||||
|
horizontalRight() {
|
||||||
|
return this.getPosition(2, 'horizontal', 'right')
|
||||||
|
},
|
||||||
|
// 计算 nvue bottom
|
||||||
|
nvueBottom() {
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
const safeBottom = uni.getSystemInfoSync().windowBottom;
|
||||||
|
return 30 + safeBottom
|
||||||
|
// #endif
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
return 30
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
pattern: {
|
||||||
|
handler(val, oldVal) {
|
||||||
|
this.styles = Object.assign({}, this.styles, val)
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.isShow = this.show
|
||||||
|
if (this.top === 0) {
|
||||||
|
this.fabShow = true
|
||||||
|
}
|
||||||
|
// 初始化样式
|
||||||
|
this.styles = Object.assign({}, this.styles, this.pattern)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
_onClick() {
|
||||||
|
this.$emit('fabClick')
|
||||||
|
if (!this.popMenu) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.isShow = !this.isShow
|
||||||
|
},
|
||||||
|
open() {
|
||||||
|
this.isShow = true
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.isShow = false
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 按钮点击事件
|
||||||
|
*/
|
||||||
|
_onItemClick(index, item) {
|
||||||
|
if (!this.isShow) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.$emit('trigger', {
|
||||||
|
index,
|
||||||
|
item
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取 位置信息
|
||||||
|
*/
|
||||||
|
getPosition(types, paramA, paramB) {
|
||||||
|
if (types === 0) {
|
||||||
|
return this.horizontal === paramA && this.vertical === paramB
|
||||||
|
} else if (types === 1) {
|
||||||
|
return this.direction === paramA && this.vertical === paramB
|
||||||
|
} else if (types === 2) {
|
||||||
|
return this.direction === paramA && this.horizontal === paramB
|
||||||
|
} else {
|
||||||
|
return this.isShow && this.direction === paramA ? this.contentWidth : this.contentWidthMin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" >
|
||||||
|
$uni-shadow-base:0 1px 5px 2px rgba($color: #000000, $alpha: 0.3) !default;
|
||||||
|
|
||||||
|
.uni-fab {
|
||||||
|
position: fixed;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 10;
|
||||||
|
border-radius: 45px;
|
||||||
|
box-shadow: $uni-shadow-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-cursor-point {
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab--active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab--leftBottom {
|
||||||
|
left: 15px;
|
||||||
|
bottom: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
left: calc(15px + var(--window-left));
|
||||||
|
bottom: calc(30px + var(--window-bottom));
|
||||||
|
/* #endif */
|
||||||
|
// padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab--leftTop {
|
||||||
|
left: 15px;
|
||||||
|
top: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
left: calc(15px + var(--window-left));
|
||||||
|
top: calc(30px + var(--window-top));
|
||||||
|
/* #endif */
|
||||||
|
// padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab--rightBottom {
|
||||||
|
right: 15px;
|
||||||
|
bottom: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
right: calc(15px + var(--window-right));
|
||||||
|
bottom: calc(30px + var(--window-bottom));
|
||||||
|
/* #endif */
|
||||||
|
// padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab--rightTop {
|
||||||
|
right: 15px;
|
||||||
|
top: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
right: calc(15px + var(--window-right));
|
||||||
|
top: calc(30px + var(--window-top));
|
||||||
|
/* #endif */
|
||||||
|
// padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle {
|
||||||
|
position: fixed;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 55px;
|
||||||
|
height: 55px;
|
||||||
|
background-color: #3c3e49;
|
||||||
|
border-radius: 45px;
|
||||||
|
z-index: 11;
|
||||||
|
// box-shadow: $uni-shadow-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--leftBottom {
|
||||||
|
left: 15px;
|
||||||
|
bottom: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
left: calc(15px + var(--window-left));
|
||||||
|
bottom: calc(30px + var(--window-bottom));
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--leftTop {
|
||||||
|
left: 15px;
|
||||||
|
top: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
left: calc(15px + var(--window-left));
|
||||||
|
top: calc(30px + var(--window-top));
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--rightBottom {
|
||||||
|
right: 15px;
|
||||||
|
bottom: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
right: calc(15px + var(--window-right));
|
||||||
|
bottom: calc(30px + var(--window-bottom));
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--rightTop {
|
||||||
|
right: 15px;
|
||||||
|
top: 30px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
right: calc(15px + var(--window-right));
|
||||||
|
top: calc(30px + var(--window-top));
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--top {
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__circle--bottom {
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__plus {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
// .fab-circle-v {
|
||||||
|
// position: absolute;
|
||||||
|
// width: 2px;
|
||||||
|
// height: 24px;
|
||||||
|
// left: 0;
|
||||||
|
// top: 0;
|
||||||
|
// right: 0;
|
||||||
|
// bottom: 0;
|
||||||
|
// /* #ifndef APP-NVUE */
|
||||||
|
// margin: auto;
|
||||||
|
// /* #endif */
|
||||||
|
// background-color: white;
|
||||||
|
// transform: rotate(0deg);
|
||||||
|
// transition: transform 0.3s;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// .fab-circle-h {
|
||||||
|
// position: absolute;
|
||||||
|
// width: 24px;
|
||||||
|
// height: 2px;
|
||||||
|
// left: 0;
|
||||||
|
// top: 0;
|
||||||
|
// right: 0;
|
||||||
|
// bottom: 0;
|
||||||
|
// /* #ifndef APP-NVUE */
|
||||||
|
// margin: auto;
|
||||||
|
// /* #endif */
|
||||||
|
// background-color: white;
|
||||||
|
// transform: rotate(0deg);
|
||||||
|
// transition: transform 0.3s;
|
||||||
|
// }
|
||||||
|
|
||||||
|
.fab-circle-icon {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
transition: transform 0.3s;
|
||||||
|
font-weight: 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__plus--active {
|
||||||
|
transform: rotate(135deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
border-radius: 55px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition-property: width, height;
|
||||||
|
transition-duration: 0.2s;
|
||||||
|
width: 55px;
|
||||||
|
border-color: #DDDDDD;
|
||||||
|
border-width: 1rpx;
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--other-platform {
|
||||||
|
border-width: 0px;
|
||||||
|
box-shadow: $uni-shadow-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--left {
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--right {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--flexDirection {
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--flexDirectionStart {
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__content--flexDirectionEnd {
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 55px;
|
||||||
|
height: 55px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__item--active {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__item-image {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__item-text {
|
||||||
|
color: #FFFFFF;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 12px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fab__item--first {
|
||||||
|
width: 55px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/en.json
generated
vendored
Normal file
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/en.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"uni-fav.collect": "collect",
|
||||||
|
"uni-fav.collected": "collected"
|
||||||
|
}
|
||||||
8
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/index.js
generated
vendored
Normal file
8
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import en from './en.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
||||||
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/zh-Hans.json
generated
vendored
Normal file
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/zh-Hans.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"uni-fav.collect": "收藏",
|
||||||
|
"uni-fav.collected": "已收藏"
|
||||||
|
}
|
||||||
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/zh-Hant.json
generated
vendored
Normal file
4
node_modules/@dcloudio/uni-ui/lib/uni-fav/i18n/zh-Hant.json
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"uni-fav.collect": "收藏",
|
||||||
|
"uni-fav.collected": "已收藏"
|
||||||
|
}
|
||||||
161
node_modules/@dcloudio/uni-ui/lib/uni-fav/uni-fav.vue
generated
vendored
Normal file
161
node_modules/@dcloudio/uni-ui/lib/uni-fav/uni-fav.vue
generated
vendored
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<template>
|
||||||
|
<view :class="[circle === true || circle === 'true' ? 'uni-fav--circle' : '']" :style="[{ backgroundColor: checked ? bgColorChecked : bgColor }]"
|
||||||
|
@click="onClick" class="uni-fav">
|
||||||
|
<!-- #ifdef MP-ALIPAY -->
|
||||||
|
<view class="uni-fav-star" v-if="!checked && (star === true || star === 'true')">
|
||||||
|
<uni-icons :color="fgColor" :style="{color: checked ? fgColorChecked : fgColor}" size="14" type="star-filled" />
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifndef MP-ALIPAY -->
|
||||||
|
<uni-icons :color="fgColor" :style="{color: checked ? fgColorChecked : fgColor}" class="uni-fav-star" size="14" type="star-filled"
|
||||||
|
v-if="!checked && (star === true || star === 'true')" />
|
||||||
|
<!-- #endif -->
|
||||||
|
<text :style="{color: checked ? fgColorChecked : fgColor}" class="uni-fav-text">{{ checked ? contentFav : contentDefault }}</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fav 收藏按钮
|
||||||
|
* @description 用于收藏功能,可点击切换选中、不选中的状态
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=864
|
||||||
|
* @property {Boolean} star = [true|false] 按钮是否带星星
|
||||||
|
* @property {String} bgColor 未收藏时的背景色
|
||||||
|
* @property {String} bgColorChecked 已收藏时的背景色
|
||||||
|
* @property {String} fgColor 未收藏时的文字颜色
|
||||||
|
* @property {String} fgColorChecked 已收藏时的文字颜色
|
||||||
|
* @property {Boolean} circle = [true|false] 是否为圆角
|
||||||
|
* @property {Boolean} checked = [true|false] 是否为已收藏
|
||||||
|
* @property {Object} contentText = [true|false] 收藏按钮文字
|
||||||
|
* @property {Boolean} stat 是否开启统计功能
|
||||||
|
* @event {Function} click 点击 fav按钮触发事件
|
||||||
|
* @example <uni-fav :checked="true"/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
initVueI18n
|
||||||
|
} from '@dcloudio/uni-i18n'
|
||||||
|
import messages from './i18n/index.js'
|
||||||
|
const { t } = initVueI18n(messages)
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "UniFav",
|
||||||
|
// TODO 兼容 vue3,需要注册事件
|
||||||
|
emits: ['click'],
|
||||||
|
props: {
|
||||||
|
star: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
bgColor: {
|
||||||
|
type: String,
|
||||||
|
default: "#eeeeee"
|
||||||
|
},
|
||||||
|
fgColor: {
|
||||||
|
type: String,
|
||||||
|
default: "#666666"
|
||||||
|
},
|
||||||
|
bgColorChecked: {
|
||||||
|
type: String,
|
||||||
|
default: "#007aff"
|
||||||
|
},
|
||||||
|
fgColorChecked: {
|
||||||
|
type: String,
|
||||||
|
default: "#FFFFFF"
|
||||||
|
},
|
||||||
|
circle: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
checked: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
contentText: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
contentDefault: "",
|
||||||
|
contentFav: ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
stat:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
contentDefault() {
|
||||||
|
return this.contentText.contentDefault || t("uni-fav.collect")
|
||||||
|
},
|
||||||
|
contentFav() {
|
||||||
|
return this.contentText.contentFav || t("uni-fav.collected")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
checked() {
|
||||||
|
if (uni.report && this.stat) {
|
||||||
|
if (this.checked) {
|
||||||
|
uni.report("收藏", "收藏");
|
||||||
|
} else {
|
||||||
|
uni.report("取消收藏", "取消收藏");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick() {
|
||||||
|
this.$emit("click");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" >
|
||||||
|
$fav-height: 25px;
|
||||||
|
|
||||||
|
.uni-fav {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 60px;
|
||||||
|
height: $fav-height;
|
||||||
|
line-height: $fav-height;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 3px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fav--circle {
|
||||||
|
border-radius: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fav-star {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
height: $fav-height;
|
||||||
|
line-height: 24px;
|
||||||
|
margin-right: 3px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-fav-text {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
height: $fav-height;
|
||||||
|
line-height: $fav-height;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
287
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/choose-and-upload-file.js
generated
vendored
Normal file
287
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/choose-and-upload-file.js
generated
vendored
Normal file
@ -0,0 +1,287 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const ERR_MSG_OK = 'chooseAndUploadFile:ok';
|
||||||
|
const ERR_MSG_FAIL = 'chooseAndUploadFile:fail';
|
||||||
|
|
||||||
|
function chooseImage(opts) {
|
||||||
|
const {
|
||||||
|
count,
|
||||||
|
sizeType = ['original', 'compressed'],
|
||||||
|
sourceType,
|
||||||
|
extension
|
||||||
|
} = opts
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// 微信由于旧接口不再维护,针对微信小程序平台改用chooseMedia接口
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
uni.chooseMedia({
|
||||||
|
count,
|
||||||
|
sizeType,
|
||||||
|
sourceType,
|
||||||
|
mediaType: ['image'],
|
||||||
|
extension,
|
||||||
|
success(res) {
|
||||||
|
res.tempFiles.forEach(item => {
|
||||||
|
item.path = item.tempFilePath;
|
||||||
|
})
|
||||||
|
resolve(normalizeChooseAndUploadFileRes(res, 'image'));
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
reject({
|
||||||
|
errMsg: res.errMsg.replace('chooseImage:fail', ERR_MSG_FAIL),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-WEIXIN
|
||||||
|
uni.chooseImage({
|
||||||
|
count,
|
||||||
|
sizeType,
|
||||||
|
sourceType,
|
||||||
|
extension,
|
||||||
|
success(res) {
|
||||||
|
resolve(normalizeChooseAndUploadFileRes(res, 'image'));
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
reject({
|
||||||
|
errMsg: res.errMsg.replace('chooseImage:fail', ERR_MSG_FAIL),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function chooseVideo(opts) {
|
||||||
|
const {
|
||||||
|
count,
|
||||||
|
camera,
|
||||||
|
compressed,
|
||||||
|
maxDuration,
|
||||||
|
sourceType,
|
||||||
|
extension
|
||||||
|
} = opts;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// 微信由于旧接口不再维护,针对微信小程序平台改用chooseMedia接口
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
uni.chooseMedia({
|
||||||
|
count,
|
||||||
|
compressed,
|
||||||
|
maxDuration,
|
||||||
|
sourceType,
|
||||||
|
extension,
|
||||||
|
mediaType: ['video'],
|
||||||
|
success(res) {
|
||||||
|
const {
|
||||||
|
tempFiles,
|
||||||
|
} = res;
|
||||||
|
resolve(normalizeChooseAndUploadFileRes({
|
||||||
|
errMsg: 'chooseVideo:ok',
|
||||||
|
tempFiles: tempFiles.map(item => {
|
||||||
|
return {
|
||||||
|
name: item.name || '',
|
||||||
|
path: item.tempFilePath,
|
||||||
|
thumbTempFilePath: item.thumbTempFilePath,
|
||||||
|
size:item.size,
|
||||||
|
type: (res.tempFile && res.tempFile.type) || '',
|
||||||
|
width:item.width,
|
||||||
|
height:item.height,
|
||||||
|
duration:item.duration,
|
||||||
|
fileType: 'video',
|
||||||
|
cloudPath: '',
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}, 'video'));
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
reject({
|
||||||
|
errMsg: res.errMsg.replace('chooseVideo:fail', ERR_MSG_FAIL),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-WEIXIN
|
||||||
|
uni.chooseVideo({
|
||||||
|
camera,
|
||||||
|
compressed,
|
||||||
|
maxDuration,
|
||||||
|
sourceType,
|
||||||
|
extension,
|
||||||
|
success(res) {
|
||||||
|
const {
|
||||||
|
tempFilePath,
|
||||||
|
duration,
|
||||||
|
size,
|
||||||
|
height,
|
||||||
|
width
|
||||||
|
} = res;
|
||||||
|
resolve(normalizeChooseAndUploadFileRes({
|
||||||
|
errMsg: 'chooseVideo:ok',
|
||||||
|
tempFilePaths: [tempFilePath],
|
||||||
|
tempFiles: [{
|
||||||
|
name: (res.tempFile && res.tempFile.name) || '',
|
||||||
|
path: tempFilePath,
|
||||||
|
size,
|
||||||
|
type: (res.tempFile && res.tempFile.type) || '',
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
duration,
|
||||||
|
fileType: 'video',
|
||||||
|
cloudPath: '',
|
||||||
|
}, ],
|
||||||
|
}, 'video'));
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
reject({
|
||||||
|
errMsg: res.errMsg.replace('chooseVideo:fail', ERR_MSG_FAIL),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function chooseAll(opts) {
|
||||||
|
const {
|
||||||
|
count,
|
||||||
|
extension
|
||||||
|
} = opts;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let chooseFile = uni.chooseFile;
|
||||||
|
if (typeof wx !== 'undefined' &&
|
||||||
|
typeof wx.chooseMessageFile === 'function') {
|
||||||
|
chooseFile = wx.chooseMessageFile;
|
||||||
|
}
|
||||||
|
if (typeof chooseFile !== 'function') {
|
||||||
|
return reject({
|
||||||
|
errMsg: ERR_MSG_FAIL + ' 请指定 type 类型,该平台仅支持选择 image 或 video。',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
chooseFile({
|
||||||
|
type: 'all',
|
||||||
|
count,
|
||||||
|
extension,
|
||||||
|
success(res) {
|
||||||
|
resolve(normalizeChooseAndUploadFileRes(res));
|
||||||
|
},
|
||||||
|
fail(res) {
|
||||||
|
reject({
|
||||||
|
errMsg: res.errMsg.replace('chooseFile:fail', ERR_MSG_FAIL),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeChooseAndUploadFileRes(res, fileType) {
|
||||||
|
res.tempFiles.forEach((item, index) => {
|
||||||
|
if (!item.name) {
|
||||||
|
item.name = item.path.substring(item.path.lastIndexOf('/') + 1);
|
||||||
|
}
|
||||||
|
if (fileType) {
|
||||||
|
item.fileType = fileType;
|
||||||
|
}
|
||||||
|
item.cloudPath =
|
||||||
|
Date.now() + '_' + index + item.name.substring(item.name.lastIndexOf('.'));
|
||||||
|
});
|
||||||
|
if (!res.tempFilePaths) {
|
||||||
|
res.tempFilePaths = res.tempFiles.map((file) => file.path);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function uploadCloudFiles(files, max = 5, onUploadProgress) {
|
||||||
|
files = JSON.parse(JSON.stringify(files))
|
||||||
|
const len = files.length
|
||||||
|
let count = 0
|
||||||
|
let self = this
|
||||||
|
return new Promise(resolve => {
|
||||||
|
while (count < max) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
let cur = count++
|
||||||
|
if (cur >= len) {
|
||||||
|
!files.find(item => !item.url && !item.errMsg) && resolve(files)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fileItem = files[cur]
|
||||||
|
const index = self.files.findIndex(v => v.uuid === fileItem.uuid)
|
||||||
|
fileItem.url = ''
|
||||||
|
delete fileItem.errMsg
|
||||||
|
|
||||||
|
uniCloud
|
||||||
|
.uploadFile({
|
||||||
|
filePath: fileItem.path,
|
||||||
|
cloudPath: fileItem.cloudPath,
|
||||||
|
fileType: fileItem.fileType,
|
||||||
|
onUploadProgress: res => {
|
||||||
|
res.index = index
|
||||||
|
onUploadProgress && onUploadProgress(res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
fileItem.url = res.fileID
|
||||||
|
fileItem.index = index
|
||||||
|
if (cur < len) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(res => {
|
||||||
|
fileItem.errMsg = res.errMsg || res.message
|
||||||
|
fileItem.index = index
|
||||||
|
if (cur < len) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function uploadFiles(choosePromise, {
|
||||||
|
onChooseFile,
|
||||||
|
onUploadProgress
|
||||||
|
}) {
|
||||||
|
return choosePromise
|
||||||
|
.then((res) => {
|
||||||
|
if (onChooseFile) {
|
||||||
|
const customChooseRes = onChooseFile(res);
|
||||||
|
if (typeof customChooseRes !== 'undefined') {
|
||||||
|
return Promise.resolve(customChooseRes).then((chooseRes) => typeof chooseRes === 'undefined' ?
|
||||||
|
res : chooseRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res === false) {
|
||||||
|
return {
|
||||||
|
errMsg: ERR_MSG_OK,
|
||||||
|
tempFilePaths: [],
|
||||||
|
tempFiles: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function chooseAndUploadFile(opts = {
|
||||||
|
type: 'all'
|
||||||
|
}) {
|
||||||
|
if (opts.type === 'image') {
|
||||||
|
return uploadFiles(chooseImage(opts), opts);
|
||||||
|
} else if (opts.type === 'video') {
|
||||||
|
return uploadFiles(chooseVideo(opts), opts);
|
||||||
|
}
|
||||||
|
return uploadFiles(chooseAll(opts), opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
chooseAndUploadFile,
|
||||||
|
uploadCloudFiles
|
||||||
|
};
|
||||||
668
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/uni-file-picker.vue
generated
vendored
Normal file
668
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/uni-file-picker.vue
generated
vendored
Normal file
@ -0,0 +1,668 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-file-picker">
|
||||||
|
<view v-if="title" class="uni-file-picker__header">
|
||||||
|
<text class="file-title">{{ title }}</text>
|
||||||
|
<text class="file-count">{{ filesList.length }}/{{ limitLength }}</text>
|
||||||
|
</view>
|
||||||
|
<upload-image v-if="fileMediatype === 'image' && showType === 'grid'" :readonly="readonly"
|
||||||
|
:image-styles="imageStyles" :files-list="filesList" :limit="limitLength" :disablePreview="disablePreview"
|
||||||
|
:delIcon="delIcon" @uploadFiles="uploadFiles" @choose="choose" @delFile="delFile">
|
||||||
|
<slot>
|
||||||
|
<view class="is-add">
|
||||||
|
<view class="icon-add"></view>
|
||||||
|
<view class="icon-add rotate"></view>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
</upload-image>
|
||||||
|
<upload-file v-if="fileMediatype !== 'image' || showType !== 'grid'" :readonly="readonly"
|
||||||
|
:list-styles="listStyles" :files-list="filesList" :showType="showType" :delIcon="delIcon"
|
||||||
|
@uploadFiles="uploadFiles" @choose="choose" @delFile="delFile">
|
||||||
|
<slot><button type="primary" size="mini">选择文件</button></slot>
|
||||||
|
</upload-file>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
chooseAndUploadFile,
|
||||||
|
uploadCloudFiles
|
||||||
|
} from './choose-and-upload-file.js'
|
||||||
|
import {
|
||||||
|
get_file_ext,
|
||||||
|
get_extname,
|
||||||
|
get_files_and_is_max,
|
||||||
|
get_file_info,
|
||||||
|
get_file_data
|
||||||
|
} from './utils.js'
|
||||||
|
import uploadImage from './upload-image.vue'
|
||||||
|
import uploadFile from './upload-file.vue'
|
||||||
|
let fileInput = null
|
||||||
|
/**
|
||||||
|
* FilePicker 文件选择上传
|
||||||
|
* @description 文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=4079
|
||||||
|
* @property {Object|Array} value 组件数据,通常用来回显 ,类型由return-type属性决定
|
||||||
|
* @property {Boolean} disabled = [true|false] 组件禁用
|
||||||
|
* @value true 禁用
|
||||||
|
* @value false 取消禁用
|
||||||
|
* @property {Boolean} readonly = [true|false] 组件只读,不可选择,不显示进度,不显示删除按钮
|
||||||
|
* @value true 只读
|
||||||
|
* @value false 取消只读
|
||||||
|
* @property {String} return-type = [array|object] 限制 value 格式,当为 object 时 ,组件只能单选,且会覆盖
|
||||||
|
* @value array 规定 value 属性的类型为数组
|
||||||
|
* @value object 规定 value 属性的类型为对象
|
||||||
|
* @property {Boolean} disable-preview = [true|false] 禁用图片预览,仅 mode:grid 时生效
|
||||||
|
* @value true 禁用图片预览
|
||||||
|
* @value false 取消禁用图片预览
|
||||||
|
* @property {Boolean} del-icon = [true|false] 是否显示删除按钮
|
||||||
|
* @value true 显示删除按钮
|
||||||
|
* @value false 不显示删除按钮
|
||||||
|
* @property {Boolean} auto-upload = [true|false] 是否自动上传,值为true则只触发@select,可自行上传
|
||||||
|
* @value true 自动上传
|
||||||
|
* @value false 取消自动上传
|
||||||
|
* @property {Number|String} limit 最大选择个数 ,h5 会自动忽略多选的部分
|
||||||
|
* @property {String} title 组件标题,右侧显示上传计数
|
||||||
|
* @property {String} mode = [list|grid] 选择文件后的文件列表样式
|
||||||
|
* @value list 列表显示
|
||||||
|
* @value grid 宫格显示
|
||||||
|
* @property {String} file-mediatype = [image|video|all] 选择文件类型
|
||||||
|
* @value image 只选择图片
|
||||||
|
* @value video 只选择视频
|
||||||
|
* @value all 选择所有文件
|
||||||
|
* @property {Array} file-extname 选择文件后缀,根据 file-mediatype 属性而不同
|
||||||
|
* @property {Object} list-style mode:list 时的样式
|
||||||
|
* @property {Object} image-styles 选择文件后缀,根据 file-mediatype 属性而不同
|
||||||
|
* @event {Function} select 选择文件后触发
|
||||||
|
* @event {Function} progress 文件上传时触发
|
||||||
|
* @event {Function} success 上传成功触发
|
||||||
|
* @event {Function} fail 上传失败触发
|
||||||
|
* @event {Function} delete 文件从列表移除时触发
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniFilePicker',
|
||||||
|
components: {
|
||||||
|
uploadImage,
|
||||||
|
uploadFile
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
virtualHost: true
|
||||||
|
},
|
||||||
|
emits: ['select', 'success', 'fail', 'progress', 'delete', 'update:modelValue', 'input'],
|
||||||
|
props: {
|
||||||
|
modelValue: {
|
||||||
|
type: [Array, Object],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
type: [Array, Object],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
disablePreview: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
delIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// 自动上传
|
||||||
|
autoUpload: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// 最大选择个数 ,h5只能限制单选或是多选
|
||||||
|
limit: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 9
|
||||||
|
},
|
||||||
|
// 列表样式 grid | list | list-card
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'grid'
|
||||||
|
},
|
||||||
|
// 选择文件类型 image/video/all
|
||||||
|
fileMediatype: {
|
||||||
|
type: String,
|
||||||
|
default: 'image'
|
||||||
|
},
|
||||||
|
// 文件类型筛选
|
||||||
|
fileExtname: {
|
||||||
|
type: [Array, String],
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
listStyles: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
// 是否显示边框
|
||||||
|
border: true,
|
||||||
|
// 是否显示分隔线
|
||||||
|
dividline: true,
|
||||||
|
// 线条样式
|
||||||
|
borderStyle: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
imageStyles: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
width: 'auto',
|
||||||
|
height: 'auto'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
readonly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
returnType: {
|
||||||
|
type: String,
|
||||||
|
default: 'array'
|
||||||
|
},
|
||||||
|
sizeType: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return ['original', 'compressed']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sourceType: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return ['album', 'camera']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provider: {
|
||||||
|
type: String,
|
||||||
|
default: '' // 默认上传到 unicloud 内置存储 extStorage 扩展存储
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
files: [],
|
||||||
|
localValue: []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
value: {
|
||||||
|
handler(newVal, oldVal) {
|
||||||
|
this.setValue(newVal, oldVal)
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
modelValue: {
|
||||||
|
handler(newVal, oldVal) {
|
||||||
|
this.setValue(newVal, oldVal)
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
filesList() {
|
||||||
|
let files = []
|
||||||
|
this.files.forEach(v => {
|
||||||
|
files.push(v)
|
||||||
|
})
|
||||||
|
return files
|
||||||
|
},
|
||||||
|
showType() {
|
||||||
|
if (this.fileMediatype === 'image') {
|
||||||
|
return this.mode
|
||||||
|
}
|
||||||
|
return 'list'
|
||||||
|
},
|
||||||
|
limitLength() {
|
||||||
|
if (this.returnType === 'object') {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if (!this.limit) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if (this.limit >= 9) {
|
||||||
|
return 9
|
||||||
|
}
|
||||||
|
return this.limit
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// TODO 兼容不开通服务空间的情况
|
||||||
|
if (!(uniCloud.config && uniCloud.config.provider)) {
|
||||||
|
this.noSpace = true
|
||||||
|
uniCloud.chooseAndUploadFile = chooseAndUploadFile
|
||||||
|
}
|
||||||
|
this.form = this.getForm('uniForms')
|
||||||
|
this.formItem = this.getForm('uniFormsItem')
|
||||||
|
if (this.form && this.formItem) {
|
||||||
|
if (this.formItem.name) {
|
||||||
|
this.rename = this.formItem.name
|
||||||
|
this.form.inputChildrens.push(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 公开用户使用,清空文件
|
||||||
|
* @param {Object} index
|
||||||
|
*/
|
||||||
|
clearFiles(index) {
|
||||||
|
if (index !== 0 && !index) {
|
||||||
|
this.files = []
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.setEmit()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.files.splice(index, 1)
|
||||||
|
}
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.setEmit()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 公开用户使用,继续上传
|
||||||
|
*/
|
||||||
|
upload() {
|
||||||
|
let files = []
|
||||||
|
this.files.forEach((v, index) => {
|
||||||
|
if (v.status === 'ready' || v.status === 'error') {
|
||||||
|
files.push(Object.assign({}, v))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return this.uploadFiles(files)
|
||||||
|
},
|
||||||
|
async setValue(newVal, oldVal) {
|
||||||
|
const newData = async (v) => {
|
||||||
|
const reg = /cloud:\/\/([\w.]+\/?)\S*/
|
||||||
|
let url = ''
|
||||||
|
if(v.fileID){
|
||||||
|
url = v.fileID
|
||||||
|
}else{
|
||||||
|
url = v.url
|
||||||
|
}
|
||||||
|
if (reg.test(url)) {
|
||||||
|
v.fileID = url
|
||||||
|
v.url = await this.getTempFileURL(url)
|
||||||
|
}
|
||||||
|
if(v.url) v.path = v.url
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
if (this.returnType === 'object') {
|
||||||
|
if (newVal) {
|
||||||
|
await newData(newVal)
|
||||||
|
} else {
|
||||||
|
newVal = {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!newVal) newVal = []
|
||||||
|
for(let i =0 ;i < newVal.length ;i++){
|
||||||
|
let v = newVal[i]
|
||||||
|
await newData(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.localValue = newVal
|
||||||
|
if (this.form && this.formItem &&!this.is_reset) {
|
||||||
|
this.is_reset = false
|
||||||
|
this.formItem.setValue(this.localValue)
|
||||||
|
}
|
||||||
|
let filesData = Object.keys(newVal).length > 0 ? newVal : [];
|
||||||
|
this.files = [].concat(filesData)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择文件
|
||||||
|
*/
|
||||||
|
choose() {
|
||||||
|
if (this.disabled) return
|
||||||
|
if (this.files.length >= Number(this.limitLength) && this.showType !== 'grid' && this.returnType ===
|
||||||
|
'array') {
|
||||||
|
uni.showToast({
|
||||||
|
title: `您最多选择 ${this.limitLength} 个文件`,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.chooseFiles()
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择文件并上传
|
||||||
|
*/
|
||||||
|
chooseFiles() {
|
||||||
|
const _extname = get_extname(this.fileExtname)
|
||||||
|
// 获取后缀
|
||||||
|
uniCloud
|
||||||
|
.chooseAndUploadFile({
|
||||||
|
type: this.fileMediatype,
|
||||||
|
compressed: false,
|
||||||
|
sizeType: this.sizeType,
|
||||||
|
sourceType: this.sourceType,
|
||||||
|
// TODO 如果为空,video 有问题
|
||||||
|
extension: _extname.length > 0 ? _extname : undefined,
|
||||||
|
count: this.limitLength - this.files.length, //默认9
|
||||||
|
onChooseFile: this.chooseFileCallback,
|
||||||
|
onUploadProgress: progressEvent => {
|
||||||
|
this.setProgress(progressEvent, progressEvent.index)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
this.setSuccessAndError(result.tempFiles)
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log('选择失败', err)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择文件回调
|
||||||
|
* @param {Object} res
|
||||||
|
*/
|
||||||
|
async chooseFileCallback(res) {
|
||||||
|
const _extname = get_extname(this.fileExtname)
|
||||||
|
const is_one = (Number(this.limitLength) === 1 &&
|
||||||
|
this.disablePreview &&
|
||||||
|
!this.disabled) ||
|
||||||
|
this.returnType === 'object'
|
||||||
|
// 如果这有一个文件 ,需要清空本地缓存数据
|
||||||
|
if (is_one) {
|
||||||
|
this.files = []
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
filePaths,
|
||||||
|
files
|
||||||
|
} = get_files_and_is_max(res, _extname)
|
||||||
|
if (!(_extname && _extname.length > 0)) {
|
||||||
|
filePaths = res.tempFilePaths
|
||||||
|
files = res.tempFiles
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentData = []
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
if (this.limitLength - this.files.length <= 0) break
|
||||||
|
files[i].uuid = Date.now()
|
||||||
|
let filedata = await get_file_data(files[i], this.fileMediatype)
|
||||||
|
filedata.progress = 0
|
||||||
|
filedata.status = 'ready'
|
||||||
|
this.files.push(filedata)
|
||||||
|
currentData.push({
|
||||||
|
...filedata,
|
||||||
|
file: files[i]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.$emit('select', {
|
||||||
|
tempFiles: currentData,
|
||||||
|
tempFilePaths: filePaths
|
||||||
|
})
|
||||||
|
res.tempFiles = files
|
||||||
|
// 停止自动上传
|
||||||
|
if (!this.autoUpload || this.noSpace) {
|
||||||
|
res.tempFiles = []
|
||||||
|
}
|
||||||
|
res.tempFiles.forEach((fileItem, index) => {
|
||||||
|
this.provider && (fileItem.provider = this.provider);
|
||||||
|
const fileNameSplit = fileItem.name.split('.')
|
||||||
|
const ext = fileNameSplit.pop()
|
||||||
|
const fileName = fileNameSplit.join('.').replace(/[\s\/\?<>\\:\*\|":]/g, '_')
|
||||||
|
fileItem.cloudPath = fileName + '_' + Date.now() + '_' + index + '.' + ext
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批传
|
||||||
|
* @param {Object} e
|
||||||
|
*/
|
||||||
|
uploadFiles(files) {
|
||||||
|
files = [].concat(files)
|
||||||
|
return uploadCloudFiles.call(this, files, 5, res => {
|
||||||
|
this.setProgress(res, res.index, true)
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
this.setSuccessAndError(result)
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功或失败
|
||||||
|
*/
|
||||||
|
async setSuccessAndError(res, fn) {
|
||||||
|
let successData = []
|
||||||
|
let errorData = []
|
||||||
|
let tempFilePath = []
|
||||||
|
let errorTempFilePath = []
|
||||||
|
for (let i = 0; i < res.length; i++) {
|
||||||
|
const item = res[i]
|
||||||
|
const index = item.uuid ? this.files.findIndex(p => p.uuid === item.uuid) : item.index
|
||||||
|
|
||||||
|
if (index === -1 || !this.files) break
|
||||||
|
if (item.errMsg === 'request:fail') {
|
||||||
|
this.files[index].url = item.path
|
||||||
|
this.files[index].status = 'error'
|
||||||
|
this.files[index].errMsg = item.errMsg
|
||||||
|
// this.files[index].progress = -1
|
||||||
|
errorData.push(this.files[index])
|
||||||
|
errorTempFilePath.push(this.files[index].url)
|
||||||
|
} else {
|
||||||
|
this.files[index].errMsg = ''
|
||||||
|
this.files[index].fileID = item.url
|
||||||
|
const reg = /cloud:\/\/([\w.]+\/?)\S*/
|
||||||
|
if (reg.test(item.url)) {
|
||||||
|
this.files[index].url = await this.getTempFileURL(item.url)
|
||||||
|
}else{
|
||||||
|
this.files[index].url = item.url
|
||||||
|
}
|
||||||
|
|
||||||
|
this.files[index].status = 'success'
|
||||||
|
this.files[index].progress += 1
|
||||||
|
successData.push(this.files[index])
|
||||||
|
tempFilePath.push(this.files[index].fileID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successData.length > 0) {
|
||||||
|
this.setEmit()
|
||||||
|
// 状态改变返回
|
||||||
|
this.$emit('success', {
|
||||||
|
tempFiles: this.backObject(successData),
|
||||||
|
tempFilePaths: tempFilePath
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorData.length > 0) {
|
||||||
|
this.$emit('fail', {
|
||||||
|
tempFiles: this.backObject(errorData),
|
||||||
|
tempFilePaths: errorTempFilePath
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取进度
|
||||||
|
* @param {Object} progressEvent
|
||||||
|
* @param {Object} index
|
||||||
|
* @param {Object} type
|
||||||
|
*/
|
||||||
|
setProgress(progressEvent, index, type) {
|
||||||
|
const fileLenth = this.files.length
|
||||||
|
const percentNum = (index / fileLenth) * 100
|
||||||
|
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||||
|
let idx = index
|
||||||
|
if (!type) {
|
||||||
|
idx = this.files.findIndex(p => p.uuid === progressEvent.tempFile.uuid)
|
||||||
|
}
|
||||||
|
if (idx === -1 || !this.files[idx]) return
|
||||||
|
// fix by mehaotian 100 就会消失,-1 是为了让进度条消失
|
||||||
|
this.files[idx].progress = percentCompleted - 1
|
||||||
|
// 上传中
|
||||||
|
this.$emit('progress', {
|
||||||
|
index: idx,
|
||||||
|
progress: parseInt(percentCompleted),
|
||||||
|
tempFile: this.files[idx]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
* @param {Object} index
|
||||||
|
*/
|
||||||
|
delFile(index) {
|
||||||
|
this.$emit('delete', {
|
||||||
|
index,
|
||||||
|
tempFile: this.files[index],
|
||||||
|
tempFilePath: this.files[index].url
|
||||||
|
})
|
||||||
|
this.files.splice(index, 1)
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.setEmit()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件名和后缀
|
||||||
|
* @param {Object} name
|
||||||
|
*/
|
||||||
|
getFileExt(name) {
|
||||||
|
const last_len = name.lastIndexOf('.')
|
||||||
|
const len = name.length
|
||||||
|
return {
|
||||||
|
name: name.substring(0, last_len),
|
||||||
|
ext: name.substring(last_len + 1, len)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理返回事件
|
||||||
|
*/
|
||||||
|
setEmit() {
|
||||||
|
let data = []
|
||||||
|
if (this.returnType === 'object') {
|
||||||
|
data = this.backObject(this.files)[0]
|
||||||
|
this.localValue = data?data:null
|
||||||
|
} else {
|
||||||
|
data = this.backObject(this.files)
|
||||||
|
if (!this.localValue) {
|
||||||
|
this.localValue = []
|
||||||
|
}
|
||||||
|
this.localValue = [...data]
|
||||||
|
}
|
||||||
|
// #ifdef VUE3
|
||||||
|
this.$emit('update:modelValue', this.localValue)
|
||||||
|
// #endif
|
||||||
|
// #ifndef VUE3
|
||||||
|
this.$emit('input', this.localValue)
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理返回参数
|
||||||
|
* @param {Object} files
|
||||||
|
*/
|
||||||
|
backObject(files) {
|
||||||
|
let newFilesData = []
|
||||||
|
files.forEach(v => {
|
||||||
|
newFilesData.push({
|
||||||
|
extname: v.extname,
|
||||||
|
fileType: v.fileType,
|
||||||
|
image: v.image,
|
||||||
|
name: v.name,
|
||||||
|
path: v.path,
|
||||||
|
size: v.size,
|
||||||
|
fileID:v.fileID,
|
||||||
|
url: v.url,
|
||||||
|
// 修改删除一个文件后不能再上传的bug, #694
|
||||||
|
uuid: v.uuid,
|
||||||
|
status: v.status,
|
||||||
|
cloudPath: v.cloudPath
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return newFilesData
|
||||||
|
},
|
||||||
|
async getTempFileURL(fileList) {
|
||||||
|
fileList = {
|
||||||
|
fileList: [].concat(fileList)
|
||||||
|
}
|
||||||
|
const urls = await uniCloud.getTempFileURL(fileList)
|
||||||
|
return urls.fileList[0].tempFileURL || ''
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 获取父元素实例
|
||||||
|
*/
|
||||||
|
getForm(name = 'uniForms') {
|
||||||
|
let parent = this.$parent;
|
||||||
|
let parentName = parent.$options.name;
|
||||||
|
while (parentName !== name) {
|
||||||
|
parent = parent.$parent;
|
||||||
|
if (!parent) return false;
|
||||||
|
parentName = parent.$options.name;
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.uni-file-picker {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-file-picker__header {
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-title {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-count {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-add {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-add {
|
||||||
|
width: 50px;
|
||||||
|
height: 5px;
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
325
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/upload-file.vue
generated
vendored
Normal file
325
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/upload-file.vue
generated
vendored
Normal file
@ -0,0 +1,325 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-file-picker__files">
|
||||||
|
<view v-if="!readonly" class="files-button" @click="choose">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
<!-- :class="{'is-text-box':showType === 'list'}" -->
|
||||||
|
<view v-if="list.length > 0" class="uni-file-picker__lists is-text-box" :style="borderStyle">
|
||||||
|
<!-- ,'is-list-card':showType === 'list-card' -->
|
||||||
|
|
||||||
|
<view class="uni-file-picker__lists-box" v-for="(item ,index) in list" :key="index" :class="{
|
||||||
|
'files-border':index !== 0 && styles.dividline}"
|
||||||
|
:style="index !== 0 && styles.dividline &&borderLineStyle">
|
||||||
|
<view class="uni-file-picker__item">
|
||||||
|
<!-- :class="{'is-text-image':showType === 'list'}" -->
|
||||||
|
<!-- <view class="files__image is-text-image">
|
||||||
|
<image class="header-image" :src="item.logo" mode="aspectFit"></image>
|
||||||
|
</view> -->
|
||||||
|
<view class="files__name">{{item.name}}</view>
|
||||||
|
<view v-if="delIcon&&!readonly" class="icon-del-box icon-files" @click="delFile(index)">
|
||||||
|
<view class="icon-del icon-files"></view>
|
||||||
|
<view class="icon-del rotate"></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress">
|
||||||
|
<progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4"
|
||||||
|
:backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" />
|
||||||
|
</view>
|
||||||
|
<view v-if="item.status === 'error'" class="file-picker__mask" @click.stop="uploadFiles(item,index)">
|
||||||
|
点击重试
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "uploadFile",
|
||||||
|
emits:['uploadFiles','choose','delFile'],
|
||||||
|
props: {
|
||||||
|
filesList: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
delIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 9
|
||||||
|
},
|
||||||
|
showType: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
listStyles: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
// 是否显示边框
|
||||||
|
border: true,
|
||||||
|
// 是否显示分隔线
|
||||||
|
dividline: true,
|
||||||
|
// 线条样式
|
||||||
|
borderStyle: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
readonly:{
|
||||||
|
type:Boolean,
|
||||||
|
default:false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
list() {
|
||||||
|
let files = []
|
||||||
|
this.filesList.forEach(v => {
|
||||||
|
files.push(v)
|
||||||
|
})
|
||||||
|
return files
|
||||||
|
},
|
||||||
|
styles() {
|
||||||
|
let styles = {
|
||||||
|
border: true,
|
||||||
|
dividline: true,
|
||||||
|
'border-style': {}
|
||||||
|
}
|
||||||
|
return Object.assign(styles, this.listStyles)
|
||||||
|
},
|
||||||
|
borderStyle() {
|
||||||
|
let {
|
||||||
|
borderStyle,
|
||||||
|
border
|
||||||
|
} = this.styles
|
||||||
|
let obj = {}
|
||||||
|
if (!border) {
|
||||||
|
obj.border = 'none'
|
||||||
|
} else {
|
||||||
|
let width = (borderStyle && borderStyle.width) || 1
|
||||||
|
width = this.value2px(width)
|
||||||
|
let radius = (borderStyle && borderStyle.radius) || 5
|
||||||
|
radius = this.value2px(radius)
|
||||||
|
obj = {
|
||||||
|
'border-width': width,
|
||||||
|
'border-style': (borderStyle && borderStyle.style) || 'solid',
|
||||||
|
'border-color': (borderStyle && borderStyle.color) || '#eee',
|
||||||
|
'border-radius': radius
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let classles = ''
|
||||||
|
for (let i in obj) {
|
||||||
|
classles += `${i}:${obj[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
},
|
||||||
|
borderLineStyle() {
|
||||||
|
let obj = {}
|
||||||
|
let {
|
||||||
|
borderStyle
|
||||||
|
} = this.styles
|
||||||
|
if (borderStyle && borderStyle.color) {
|
||||||
|
obj['border-color'] = borderStyle.color
|
||||||
|
}
|
||||||
|
if (borderStyle && borderStyle.width) {
|
||||||
|
let width = borderStyle && borderStyle.width || 1
|
||||||
|
let style = borderStyle && borderStyle.style || 0
|
||||||
|
if (typeof width === 'number') {
|
||||||
|
width += 'px'
|
||||||
|
} else {
|
||||||
|
width = width.indexOf('px') ? width : width + 'px'
|
||||||
|
}
|
||||||
|
obj['border-width'] = width
|
||||||
|
|
||||||
|
if (typeof style === 'number') {
|
||||||
|
style += 'px'
|
||||||
|
} else {
|
||||||
|
style = style.indexOf('px') ? style : style + 'px'
|
||||||
|
}
|
||||||
|
obj['border-top-style'] = style
|
||||||
|
}
|
||||||
|
let classles = ''
|
||||||
|
for (let i in obj) {
|
||||||
|
classles += `${i}:${obj[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
uploadFiles(item, index) {
|
||||||
|
this.$emit("uploadFiles", {
|
||||||
|
item,
|
||||||
|
index
|
||||||
|
})
|
||||||
|
},
|
||||||
|
choose() {
|
||||||
|
this.$emit("choose")
|
||||||
|
},
|
||||||
|
delFile(index) {
|
||||||
|
this.$emit('delFile', index)
|
||||||
|
},
|
||||||
|
value2px(value) {
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
value += 'px'
|
||||||
|
} else {
|
||||||
|
value = value.indexOf('px') !== -1 ? value : value + 'px'
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-file-picker__files {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-button {
|
||||||
|
// border: 1px red solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-file-picker__lists {
|
||||||
|
position: relative;
|
||||||
|
margin-top: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__mask {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 14px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-file-picker__lists-box {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-file-picker__item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 10px;
|
||||||
|
padding-right: 5px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files-border {
|
||||||
|
border-top: 1px #eee solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files__name {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
margin-right: 25px;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
word-break: break-all;
|
||||||
|
word-wrap: break-word;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-files {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
position: static;
|
||||||
|
background-color: initial;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
// .icon-files .icon-del {
|
||||||
|
// background-color: #333;
|
||||||
|
// width: 12px;
|
||||||
|
// height: 1px;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
.is-list-card {
|
||||||
|
border: 1px #eee solid;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
border-radius: 5px;
|
||||||
|
box-shadow: 0 0 2px 0px rgba(0, 0, 0, 0.1);
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files__image {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-text-box {
|
||||||
|
border: 1px #eee solid;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-text-image {
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-del-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
margin: auto 0;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
bottom: 0;
|
||||||
|
right: 5px;
|
||||||
|
height: 26px;
|
||||||
|
width: 26px;
|
||||||
|
// border-radius: 50%;
|
||||||
|
// background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
z-index: 2;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-del {
|
||||||
|
width: 15px;
|
||||||
|
height: 1px;
|
||||||
|
background-color: #333;
|
||||||
|
// border-radius: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #ifdef H5 */
|
||||||
|
@media all and (min-width: 768px) {
|
||||||
|
.uni-file-picker__files {
|
||||||
|
max-width: 375px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
</style>
|
||||||
292
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/upload-image.vue
generated
vendored
Normal file
292
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/upload-image.vue
generated
vendored
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-file-picker__container">
|
||||||
|
<view class="file-picker__box" v-for="(item,index) in filesList" :key="index" :style="boxStyle">
|
||||||
|
<view class="file-picker__box-content" :style="borderStyle">
|
||||||
|
<image class="file-image" :src="item.url" mode="aspectFill" @click.stop="prviewImage(item,index)"></image>
|
||||||
|
<view v-if="delIcon && !readonly" class="icon-del-box" @click.stop="delFile(index)">
|
||||||
|
<view class="icon-del"></view>
|
||||||
|
<view class="icon-del rotate"></view>
|
||||||
|
</view>
|
||||||
|
<view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress">
|
||||||
|
<progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4"
|
||||||
|
:backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" />
|
||||||
|
</view>
|
||||||
|
<view v-if="item.errMsg" class="file-picker__mask" @click.stop="uploadFiles(item,index)">
|
||||||
|
点击重试
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view v-if="filesList.length < limit && !readonly" class="file-picker__box" :style="boxStyle">
|
||||||
|
<view class="file-picker__box-content is-add" :style="borderStyle" @click="choose">
|
||||||
|
<slot>
|
||||||
|
<view class="icon-add"></view>
|
||||||
|
<view class="icon-add rotate"></view>
|
||||||
|
</slot>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "uploadImage",
|
||||||
|
emits:['uploadFiles','choose','delFile'],
|
||||||
|
props: {
|
||||||
|
filesList: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
disabled:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
disablePreview: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
limit: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 9
|
||||||
|
},
|
||||||
|
imageStyles: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {
|
||||||
|
width: 'auto',
|
||||||
|
height: 'auto',
|
||||||
|
border: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
delIcon: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
readonly:{
|
||||||
|
type:Boolean,
|
||||||
|
default:false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
styles() {
|
||||||
|
let styles = {
|
||||||
|
width: 'auto',
|
||||||
|
height: 'auto',
|
||||||
|
border: {}
|
||||||
|
}
|
||||||
|
return Object.assign(styles, this.imageStyles)
|
||||||
|
},
|
||||||
|
boxStyle() {
|
||||||
|
const {
|
||||||
|
width = 'auto',
|
||||||
|
height = 'auto'
|
||||||
|
} = this.styles
|
||||||
|
let obj = {}
|
||||||
|
if (height === 'auto') {
|
||||||
|
if (width !== 'auto') {
|
||||||
|
obj.height = this.value2px(width)
|
||||||
|
obj['padding-top'] = 0
|
||||||
|
} else {
|
||||||
|
obj.height = 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obj.height = this.value2px(height)
|
||||||
|
obj['padding-top'] = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width === 'auto') {
|
||||||
|
if (height !== 'auto') {
|
||||||
|
obj.width = this.value2px(height)
|
||||||
|
} else {
|
||||||
|
obj.width = '33.3%'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obj.width = this.value2px(width)
|
||||||
|
}
|
||||||
|
|
||||||
|
let classles = ''
|
||||||
|
for(let i in obj){
|
||||||
|
classles+= `${i}:${obj[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
},
|
||||||
|
borderStyle() {
|
||||||
|
let {
|
||||||
|
border
|
||||||
|
} = this.styles
|
||||||
|
let obj = {}
|
||||||
|
const widthDefaultValue = 1
|
||||||
|
const radiusDefaultValue = 3
|
||||||
|
if (typeof border === 'boolean') {
|
||||||
|
obj.border = border ? '1px #eee solid' : 'none'
|
||||||
|
} else {
|
||||||
|
let width = (border && border.width) || widthDefaultValue
|
||||||
|
width = this.value2px(width)
|
||||||
|
let radius = (border && border.radius) || radiusDefaultValue
|
||||||
|
radius = this.value2px(radius)
|
||||||
|
obj = {
|
||||||
|
'border-width': width,
|
||||||
|
'border-style': (border && border.style) || 'solid',
|
||||||
|
'border-color': (border && border.color) || '#eee',
|
||||||
|
'border-radius': radius
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let classles = ''
|
||||||
|
for(let i in obj){
|
||||||
|
classles+= `${i}:${obj[i]};`
|
||||||
|
}
|
||||||
|
return classles
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
uploadFiles(item, index) {
|
||||||
|
this.$emit("uploadFiles", item)
|
||||||
|
},
|
||||||
|
choose() {
|
||||||
|
this.$emit("choose")
|
||||||
|
},
|
||||||
|
delFile(index) {
|
||||||
|
this.$emit('delFile', index)
|
||||||
|
},
|
||||||
|
prviewImage(img, index) {
|
||||||
|
let urls = []
|
||||||
|
if(Number(this.limit) === 1&&this.disablePreview&&!this.disabled){
|
||||||
|
this.$emit("choose")
|
||||||
|
}
|
||||||
|
if(this.disablePreview) return
|
||||||
|
this.filesList.forEach(i => {
|
||||||
|
urls.push(i.url)
|
||||||
|
})
|
||||||
|
|
||||||
|
uni.previewImage({
|
||||||
|
urls: urls,
|
||||||
|
current: index
|
||||||
|
});
|
||||||
|
},
|
||||||
|
value2px(value) {
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
value += 'px'
|
||||||
|
} else {
|
||||||
|
if (value.indexOf('%') === -1) {
|
||||||
|
value = value.indexOf('px') !== -1 ? value : value + 'px'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-file-picker__container {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: -5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__box {
|
||||||
|
position: relative;
|
||||||
|
// flex: 0 0 33.3%;
|
||||||
|
width: 33.3%;
|
||||||
|
height: 0;
|
||||||
|
padding-top: 33.33%;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__box-content {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
margin: 5px;
|
||||||
|
border: 1px #eee solid;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__progress {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
/* border: 1px red solid; */
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__progress-item {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-picker__mask {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-add {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-add {
|
||||||
|
width: 50px;
|
||||||
|
height: 5px;
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rotate {
|
||||||
|
position: absolute;
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-del-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
position: absolute;
|
||||||
|
top: 3px;
|
||||||
|
right: 3px;
|
||||||
|
height: 26px;
|
||||||
|
width: 26px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
z-index: 2;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-del {
|
||||||
|
width: 15px;
|
||||||
|
height: 2px;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
110
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/utils.js
generated
vendored
Normal file
110
node_modules/@dcloudio/uni-ui/lib/uni-file-picker/utils.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/**
|
||||||
|
* 获取文件名和后缀
|
||||||
|
* @param {String} name
|
||||||
|
*/
|
||||||
|
export const get_file_ext = (name) => {
|
||||||
|
const last_len = name.lastIndexOf('.')
|
||||||
|
const len = name.length
|
||||||
|
return {
|
||||||
|
name: name.substring(0, last_len),
|
||||||
|
ext: name.substring(last_len + 1, len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取扩展名
|
||||||
|
* @param {Array} fileExtname
|
||||||
|
*/
|
||||||
|
export const get_extname = (fileExtname) => {
|
||||||
|
if (!Array.isArray(fileExtname)) {
|
||||||
|
let extname = fileExtname.replace(/(\[|\])/g, '')
|
||||||
|
return extname.split(',')
|
||||||
|
} else {
|
||||||
|
return fileExtname
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件和检测是否可选
|
||||||
|
*/
|
||||||
|
export const get_files_and_is_max = (res, _extname) => {
|
||||||
|
let filePaths = []
|
||||||
|
let files = []
|
||||||
|
if(!_extname || _extname.length === 0){
|
||||||
|
return {
|
||||||
|
filePaths,
|
||||||
|
files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.tempFiles.forEach(v => {
|
||||||
|
let fileFullName = get_file_ext(v.name)
|
||||||
|
const extname = fileFullName.ext.toLowerCase()
|
||||||
|
if (_extname.indexOf(extname) !== -1) {
|
||||||
|
files.push(v)
|
||||||
|
filePaths.push(v.path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (files.length !== res.tempFiles.length) {
|
||||||
|
uni.showToast({
|
||||||
|
title: `当前选择了${res.tempFiles.length}个文件 ,${res.tempFiles.length - files.length} 个文件格式不正确`,
|
||||||
|
icon: 'none',
|
||||||
|
duration: 5000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePaths,
|
||||||
|
files
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图片信息
|
||||||
|
* @param {Object} filepath
|
||||||
|
*/
|
||||||
|
export const get_file_info = (filepath) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.getImageInfo({
|
||||||
|
src: filepath,
|
||||||
|
success(res) {
|
||||||
|
resolve(res)
|
||||||
|
},
|
||||||
|
fail(err) {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取封装数据
|
||||||
|
*/
|
||||||
|
export const get_file_data = async (files, type = 'image') => {
|
||||||
|
// 最终需要上传数据库的数据
|
||||||
|
let fileFullName = get_file_ext(files.name)
|
||||||
|
const extname = fileFullName.ext.toLowerCase()
|
||||||
|
let filedata = {
|
||||||
|
name: files.name,
|
||||||
|
uuid: files.uuid,
|
||||||
|
extname: extname || '',
|
||||||
|
cloudPath: files.cloudPath,
|
||||||
|
fileType: files.fileType,
|
||||||
|
thumbTempFilePath: files.thumbTempFilePath,
|
||||||
|
url: files.path || files.path,
|
||||||
|
size: files.size, //单位是字节
|
||||||
|
image: {},
|
||||||
|
path: files.path,
|
||||||
|
video: {}
|
||||||
|
}
|
||||||
|
if (type === 'image') {
|
||||||
|
const imageinfo = await get_file_info(files.path)
|
||||||
|
delete filedata.video
|
||||||
|
filedata.image.width = imageinfo.width
|
||||||
|
filedata.image.height = imageinfo.height
|
||||||
|
filedata.image.location = imageinfo.path
|
||||||
|
} else {
|
||||||
|
delete filedata.image
|
||||||
|
}
|
||||||
|
return filedata
|
||||||
|
}
|
||||||
632
node_modules/@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.vue
generated
vendored
Normal file
632
node_modules/@dcloudio/uni-ui/lib/uni-forms-item/uni-forms-item.vue
generated
vendored
Normal file
@ -0,0 +1,632 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-forms-item"
|
||||||
|
:class="['is-direction-' + localLabelPos ,border?'uni-forms-item--border':'' ,border && isFirstBorder?'is-first-border':'']">
|
||||||
|
<slot name="label">
|
||||||
|
<view class="uni-forms-item__label" :class="{'no-label':!label && !required}"
|
||||||
|
:style="{width:localLabelWidth,justifyContent: localLabelAlign}">
|
||||||
|
<text v-if="required" class="is-required">*</text>
|
||||||
|
<text>{{label}}</text>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
<!-- #ifndef APP-NVUE -->
|
||||||
|
<view class="uni-forms-item__content">
|
||||||
|
<slot></slot>
|
||||||
|
<view class="uni-forms-item__error" :class="{'msg--active':msg}">
|
||||||
|
<text>{{msg}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
<!-- #ifdef APP-NVUE -->
|
||||||
|
<view class="uni-forms-item__nuve-content">
|
||||||
|
<view class="uni-forms-item__content">
|
||||||
|
<slot></slot>
|
||||||
|
</view>
|
||||||
|
<view class="uni-forms-item__error" :class="{'msg--active':msg}">
|
||||||
|
<text class="error-text">{{msg}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<!-- #endif -->
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* uni-fomrs-item 表单子组件
|
||||||
|
* @description uni-fomrs-item 表单子组件,提供了基础布局已经校验能力
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=2773
|
||||||
|
* @property {Boolean} required 是否必填,左边显示红色"*"号
|
||||||
|
* @property {String } label 输入框左边的文字提示
|
||||||
|
* @property {Number } labelWidth label的宽度,单位px(默认70)
|
||||||
|
* @property {String } labelAlign = [left|center|right] label的文字对齐方式(默认left)
|
||||||
|
* @value left label 左侧显示
|
||||||
|
* @value center label 居中
|
||||||
|
* @value right label 右侧对齐
|
||||||
|
* @property {String } errorMessage 显示的错误提示内容,如果为空字符串或者false,则不显示错误信息
|
||||||
|
* @property {String } name 表单域的属性名,在使用校验规则时必填
|
||||||
|
* @property {String } leftIcon 【1.4.0废弃】label左边的图标,限 uni-ui 的图标名称
|
||||||
|
* @property {String } iconColor 【1.4.0废弃】左边通过icon配置的图标的颜色(默认#606266)
|
||||||
|
* @property {String} validateTrigger = [bind|submit|blur] 【1.4.0废弃】校验触发器方式 默认 submit
|
||||||
|
* @value bind 发生变化时触发
|
||||||
|
* @value submit 提交时触发
|
||||||
|
* @value blur 失去焦点触发
|
||||||
|
* @property {String } labelPosition = [top|left] 【1.4.0废弃】label的文字的位置(默认left)
|
||||||
|
* @value top 顶部显示 label
|
||||||
|
* @value left 左侧显示 label
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'uniFormsItem',
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
uniFormItem: this
|
||||||
|
}
|
||||||
|
},
|
||||||
|
inject: {
|
||||||
|
form: {
|
||||||
|
from: 'uniForm',
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
// 表单校验规则
|
||||||
|
rules: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 表单域的属性名,在使用校验规则时必填
|
||||||
|
name: {
|
||||||
|
type: [String, Array],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
required: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// label的宽度
|
||||||
|
labelWidth: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// label 居中方式,默认 left 取值 left/center/right
|
||||||
|
labelAlign: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 强制显示错误信息
|
||||||
|
errorMessage: {
|
||||||
|
type: [String, Boolean],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// 1.4.0 弃用,统一使用 form 的校验时机
|
||||||
|
// validateTrigger: {
|
||||||
|
// type: String,
|
||||||
|
// default: ''
|
||||||
|
// },
|
||||||
|
// 1.4.0 弃用,统一使用 form 的label 位置
|
||||||
|
// labelPosition: {
|
||||||
|
// type: String,
|
||||||
|
// default: ''
|
||||||
|
// },
|
||||||
|
// 1.4.0 以下属性已经废弃,请使用 #label 插槽代替
|
||||||
|
leftIcon: String,
|
||||||
|
iconColor: {
|
||||||
|
type: String,
|
||||||
|
default: '#606266'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
errMsg: '',
|
||||||
|
userRules: null,
|
||||||
|
localLabelAlign: 'left',
|
||||||
|
localLabelWidth: '70px',
|
||||||
|
localLabelPos: 'left',
|
||||||
|
border: false,
|
||||||
|
isFirstBorder: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// 处理错误信息
|
||||||
|
msg() {
|
||||||
|
return this.errorMessage || this.errMsg;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 规则发生变化通知子组件更新
|
||||||
|
'form.formRules'(val) {
|
||||||
|
// TODO 处理头条vue3 watch不生效的问题
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
this.init()
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
'form.labelWidth'(val) {
|
||||||
|
// 宽度
|
||||||
|
this.localLabelWidth = this._labelWidthUnit(val)
|
||||||
|
|
||||||
|
},
|
||||||
|
'form.labelPosition'(val) {
|
||||||
|
// 标签位置
|
||||||
|
this.localLabelPos = this._labelPosition()
|
||||||
|
},
|
||||||
|
'form.labelAlign'(val) {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.init(true)
|
||||||
|
if (this.name && this.form) {
|
||||||
|
// TODO 处理头条vue3 watch不生效的问题
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
this.$watch('form.formRules', () => {
|
||||||
|
this.init()
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// 监听变化
|
||||||
|
this.$watch(
|
||||||
|
() => {
|
||||||
|
const val = this.form._getDataValue(this.name, this.form.localData)
|
||||||
|
return val
|
||||||
|
},
|
||||||
|
(value, oldVal) => {
|
||||||
|
const isEqual = this.form._isEqual(value, oldVal)
|
||||||
|
// 简单判断前后值的变化,只有发生变化才会发生校验
|
||||||
|
// TODO 如果 oldVal = undefined ,那么大概率是源数据里没有值导致 ,这个情况不哦校验 ,可能不严谨 ,需要在做观察
|
||||||
|
// fix by mehaotian 暂时取消 && oldVal !== undefined ,如果formData 中不存在,可能会不校验
|
||||||
|
if (!isEqual) {
|
||||||
|
const val = this.itemSetValue(value)
|
||||||
|
this.onFieldChange(val, false)
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
immediate: false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
// #ifndef VUE3
|
||||||
|
destroyed() {
|
||||||
|
if (this.__isUnmounted) return
|
||||||
|
this.unInit()
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
// #ifdef VUE3
|
||||||
|
unmounted() {
|
||||||
|
this.__isUnmounted = true
|
||||||
|
this.unInit()
|
||||||
|
},
|
||||||
|
// #endif
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 设置规则 ,主要用于小程序自定义检验规则
|
||||||
|
* @param {Array} rules 规则源数据
|
||||||
|
*/
|
||||||
|
setRules(rules = null) {
|
||||||
|
this.userRules = rules
|
||||||
|
this.init(false)
|
||||||
|
},
|
||||||
|
// 兼容老版本表单组件
|
||||||
|
setValue() {
|
||||||
|
// console.log('setValue 方法已经弃用,请使用最新版本的 uni-forms 表单组件以及其他关联组件。');
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 校验数据
|
||||||
|
* @param {any} value 需要校验的数据
|
||||||
|
* @param {boolean} 是否立即校验
|
||||||
|
* @return {Array|null} 校验内容
|
||||||
|
*/
|
||||||
|
async onFieldChange(value, formtrigger = true) {
|
||||||
|
const {
|
||||||
|
formData,
|
||||||
|
localData,
|
||||||
|
errShowType,
|
||||||
|
validateCheck,
|
||||||
|
validateTrigger,
|
||||||
|
_isRequiredField,
|
||||||
|
_realName
|
||||||
|
} = this.form
|
||||||
|
const name = _realName(this.name)
|
||||||
|
if (!value) {
|
||||||
|
value = this.form.formData[name]
|
||||||
|
}
|
||||||
|
// fixd by mehaotian 不在校验前清空信息,解决闪屏的问题
|
||||||
|
// this.errMsg = '';
|
||||||
|
|
||||||
|
// fix by mehaotian 解决没有检验规则的情况下,抛出错误的问题
|
||||||
|
const ruleLen = this.itemRules.rules && this.itemRules.rules.length
|
||||||
|
if (!this.validator || !ruleLen || ruleLen === 0) return;
|
||||||
|
|
||||||
|
// 检验时机
|
||||||
|
// let trigger = this.isTrigger(this.itemRules.validateTrigger, this.validateTrigger, validateTrigger);
|
||||||
|
const isRequiredField = _isRequiredField(this.itemRules.rules || []);
|
||||||
|
let result = null;
|
||||||
|
// 只有等于 bind 时 ,才能开启时实校验
|
||||||
|
if (validateTrigger === 'bind' || formtrigger) {
|
||||||
|
// 校验当前表单项
|
||||||
|
result = await this.validator.validateUpdate({
|
||||||
|
[name]: value
|
||||||
|
},
|
||||||
|
formData
|
||||||
|
);
|
||||||
|
|
||||||
|
// 判断是否必填,非必填,不填不校验,填写才校验 ,暂时只处理 undefined 和空的情况
|
||||||
|
if (!isRequiredField && (value === undefined || value === '')) {
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断错误信息显示类型
|
||||||
|
if (result && result.errorMessage) {
|
||||||
|
if (errShowType === 'undertext') {
|
||||||
|
// 获取错误信息
|
||||||
|
this.errMsg = !result ? '' : result.errorMessage;
|
||||||
|
}
|
||||||
|
if (errShowType === 'toast') {
|
||||||
|
uni.showToast({
|
||||||
|
title: result.errorMessage || '校验错误',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (errShowType === 'modal') {
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: result.errorMessage || '校验错误'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.errMsg = ''
|
||||||
|
}
|
||||||
|
// 通知 form 组件更新事件
|
||||||
|
validateCheck(result ? result : null)
|
||||||
|
} else {
|
||||||
|
this.errMsg = ''
|
||||||
|
}
|
||||||
|
return result ? result : null;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 初始组件数据
|
||||||
|
*/
|
||||||
|
init(type = false) {
|
||||||
|
const {
|
||||||
|
validator,
|
||||||
|
formRules,
|
||||||
|
childrens,
|
||||||
|
formData,
|
||||||
|
localData,
|
||||||
|
_realName,
|
||||||
|
labelWidth,
|
||||||
|
_getDataValue,
|
||||||
|
_setDataValue
|
||||||
|
} = this.form || {}
|
||||||
|
// 对齐方式
|
||||||
|
this.localLabelAlign = this._justifyContent()
|
||||||
|
// 宽度
|
||||||
|
this.localLabelWidth = this._labelWidthUnit(labelWidth)
|
||||||
|
// 标签位置
|
||||||
|
this.localLabelPos = this._labelPosition()
|
||||||
|
// 将需要校验的子组件加入form 队列
|
||||||
|
this.form && type && childrens.push(this)
|
||||||
|
|
||||||
|
if (!validator || !formRules) return
|
||||||
|
// 判断第一个 item
|
||||||
|
if (!this.form.isFirstBorder) {
|
||||||
|
this.form.isFirstBorder = true;
|
||||||
|
this.isFirstBorder = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断 group 里的第一个 item
|
||||||
|
if (this.group) {
|
||||||
|
if (!this.group.isFirstBorder) {
|
||||||
|
this.group.isFirstBorder = true;
|
||||||
|
this.isFirstBorder = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.border = this.form.border;
|
||||||
|
// 获取子域的真实名称
|
||||||
|
const name = _realName(this.name)
|
||||||
|
const itemRule = this.userRules || this.rules
|
||||||
|
if (typeof formRules === 'object' && itemRule) {
|
||||||
|
// 子规则替换父规则
|
||||||
|
formRules[name] = {
|
||||||
|
rules: itemRule
|
||||||
|
}
|
||||||
|
validator.updateSchema(formRules);
|
||||||
|
}
|
||||||
|
// 注册校验规则
|
||||||
|
const itemRules = formRules[name] || {}
|
||||||
|
this.itemRules = itemRules
|
||||||
|
// 注册校验函数
|
||||||
|
this.validator = validator
|
||||||
|
// 默认值赋予
|
||||||
|
this.itemSetValue(_getDataValue(this.name, localData))
|
||||||
|
},
|
||||||
|
unInit() {
|
||||||
|
if (this.form) {
|
||||||
|
const {
|
||||||
|
childrens,
|
||||||
|
formData,
|
||||||
|
_realName
|
||||||
|
} = this.form
|
||||||
|
childrens.forEach((item, index) => {
|
||||||
|
if (item === this) {
|
||||||
|
this.form.childrens.splice(index, 1)
|
||||||
|
delete formData[_realName(item.name)]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 设置item 的值
|
||||||
|
itemSetValue(value) {
|
||||||
|
const name = this.form._realName(this.name)
|
||||||
|
const rules = this.itemRules.rules || []
|
||||||
|
const val = this.form._getValue(name, value, rules)
|
||||||
|
this.form._setDataValue(name, this.form.formData, val)
|
||||||
|
return val
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除该表单项的校验结果
|
||||||
|
*/
|
||||||
|
clearValidate() {
|
||||||
|
this.errMsg = '';
|
||||||
|
},
|
||||||
|
|
||||||
|
// 是否显示星号
|
||||||
|
_isRequired() {
|
||||||
|
// TODO 不根据规则显示 星号,考虑后续兼容
|
||||||
|
// if (this.form) {
|
||||||
|
// if (this.form._isRequiredField(this.itemRules.rules || []) && this.required) {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
return this.required
|
||||||
|
},
|
||||||
|
|
||||||
|
// 处理对齐方式
|
||||||
|
_justifyContent() {
|
||||||
|
if (this.form) {
|
||||||
|
const {
|
||||||
|
labelAlign
|
||||||
|
} = this.form
|
||||||
|
let labelAli = this.labelAlign ? this.labelAlign : labelAlign;
|
||||||
|
if (labelAli === 'left') return 'flex-start';
|
||||||
|
if (labelAli === 'center') return 'center';
|
||||||
|
if (labelAli === 'right') return 'flex-end';
|
||||||
|
}
|
||||||
|
return 'flex-start';
|
||||||
|
},
|
||||||
|
// 处理 label宽度单位 ,继承父元素的值
|
||||||
|
_labelWidthUnit(labelWidth) {
|
||||||
|
|
||||||
|
// if (this.form) {
|
||||||
|
// const {
|
||||||
|
// labelWidth
|
||||||
|
// } = this.form
|
||||||
|
return this.num2px(this.labelWidth ? this.labelWidth : (labelWidth || (this.label ? 70 : 'auto')))
|
||||||
|
// }
|
||||||
|
// return '70px'
|
||||||
|
},
|
||||||
|
// 处理 label 位置
|
||||||
|
_labelPosition() {
|
||||||
|
if (this.form) return this.form.labelPosition || 'left'
|
||||||
|
return 'left'
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发时机
|
||||||
|
* @param {Object} rule 当前规则内时机
|
||||||
|
* @param {Object} itemRlue 当前组件时机
|
||||||
|
* @param {Object} parentRule 父组件时机
|
||||||
|
*/
|
||||||
|
isTrigger(rule, itemRlue, parentRule) {
|
||||||
|
// bind submit
|
||||||
|
if (rule === 'submit' || !rule) {
|
||||||
|
if (rule === undefined) {
|
||||||
|
if (itemRlue !== 'bind') {
|
||||||
|
if (!itemRlue) {
|
||||||
|
return parentRule === '' ? 'bind' : 'submit';
|
||||||
|
}
|
||||||
|
return 'submit';
|
||||||
|
}
|
||||||
|
return 'bind';
|
||||||
|
}
|
||||||
|
return 'submit';
|
||||||
|
}
|
||||||
|
return 'bind';
|
||||||
|
},
|
||||||
|
num2px(num) {
|
||||||
|
if (typeof num === 'number') {
|
||||||
|
return `${num}px`
|
||||||
|
}
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-forms-item {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
// 在 nvue 中,使用 margin-bottom error 信息会被隐藏
|
||||||
|
padding-bottom: 22px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
margin-bottom: 22px;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
text-align: left;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #606266;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 12px 0 0;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
vertical-align: middle;
|
||||||
|
flex-shrink: 0;
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
&.no-label {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
/* #ifndef MP-TOUTIAO */
|
||||||
|
// display: flex;
|
||||||
|
// align-items: center;
|
||||||
|
/* #endif */
|
||||||
|
position: relative;
|
||||||
|
font-size: 14px;
|
||||||
|
flex: 1;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
box-sizing: border-box;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
|
||||||
|
/* #ifndef APP || H5 || MP-WEIXIN || APP-NVUE */
|
||||||
|
// TODO 因为小程序平台会多一层标签节点 ,所以需要在多余节点继承当前样式
|
||||||
|
&>uni-easyinput,
|
||||||
|
&>uni-data-picker {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
& .uni-forms-item__nuve-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__error {
|
||||||
|
color: #f56c6c;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1;
|
||||||
|
padding-top: 4px;
|
||||||
|
position: absolute;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
top: 100%;
|
||||||
|
left: 0;
|
||||||
|
transition: transform 0.3s;
|
||||||
|
transform: translateY(-100%);
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
bottom: 5px;
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
opacity: 0;
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
// 只有 nvue 下这个样式才生效
|
||||||
|
color: #f56c6c;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.msg--active {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 位置修饰样式
|
||||||
|
&.is-direction-left {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-direction-top {
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.uni-forms-item__label {
|
||||||
|
padding: 0 0 8px;
|
||||||
|
line-height: 1.5715;
|
||||||
|
text-align: left;
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
white-space: initial;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-required {
|
||||||
|
// color: $uni-color-error;
|
||||||
|
color: #dd524d;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-forms-item--border {
|
||||||
|
margin-bottom: 0;
|
||||||
|
padding: 10px 0;
|
||||||
|
// padding-bottom: 0;
|
||||||
|
border-top: 1px #eee solid;
|
||||||
|
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
.uni-forms-item__content {
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: flex-start;
|
||||||
|
|
||||||
|
.uni-forms-item__error {
|
||||||
|
position: relative;
|
||||||
|
top: 5px;
|
||||||
|
left: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
.uni-forms-item__error {
|
||||||
|
position: relative;
|
||||||
|
top: 0px;
|
||||||
|
left: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #endif */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-first-border {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
border: none;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
border-width: 0;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
404
node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue
generated
vendored
Normal file
404
node_modules/@dcloudio/uni-ui/lib/uni-forms/uni-forms.vue
generated
vendored
Normal file
@ -0,0 +1,404 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-forms">
|
||||||
|
<form>
|
||||||
|
<slot></slot>
|
||||||
|
</form>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Validator from './validate.js';
|
||||||
|
import {
|
||||||
|
deepCopy,
|
||||||
|
getValue,
|
||||||
|
isRequiredField,
|
||||||
|
setDataValue,
|
||||||
|
getDataValue,
|
||||||
|
realName,
|
||||||
|
isRealName,
|
||||||
|
rawData,
|
||||||
|
isEqual
|
||||||
|
} from './utils.js'
|
||||||
|
|
||||||
|
// #ifndef VUE3
|
||||||
|
// 后续会慢慢废弃这个方法
|
||||||
|
import Vue from 'vue';
|
||||||
|
Vue.prototype.binddata = function(name, value, formName) {
|
||||||
|
if (formName) {
|
||||||
|
this.$refs[formName].setValue(name, value);
|
||||||
|
} else {
|
||||||
|
let formVm;
|
||||||
|
for (let i in this.$refs) {
|
||||||
|
const vm = this.$refs[i];
|
||||||
|
if (vm && vm.$options && vm.$options.name === 'uniForms') {
|
||||||
|
formVm = vm;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!formVm) return console.error('当前 uni-froms 组件缺少 ref 属性');
|
||||||
|
formVm.setValue(name, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// #endif
|
||||||
|
/**
|
||||||
|
* Forms 表单
|
||||||
|
* @description 由输入框、选择器、单选框、多选框等控件组成,用以收集、校验、提交数据
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=2773
|
||||||
|
* @property {Object} rules 表单校验规则
|
||||||
|
* @property {String} validateTrigger = [bind|submit|blur] 校验触发器方式 默认 submit
|
||||||
|
* @value bind 发生变化时触发
|
||||||
|
* @value submit 提交时触发
|
||||||
|
* @value blur 失去焦点时触发
|
||||||
|
* @property {String} labelPosition = [top|left] label 位置 默认 left
|
||||||
|
* @value top 顶部显示 label
|
||||||
|
* @value left 左侧显示 label
|
||||||
|
* @property {String} labelWidth label 宽度,默认 70px
|
||||||
|
* @property {String} labelAlign = [left|center|right] label 居中方式 默认 left
|
||||||
|
* @value left label 左侧显示
|
||||||
|
* @value center label 居中
|
||||||
|
* @value right label 右侧对齐
|
||||||
|
* @property {String} errShowType = [undertext|toast|modal] 校验错误信息提示方式
|
||||||
|
* @value undertext 错误信息在底部显示
|
||||||
|
* @value toast 错误信息toast显示
|
||||||
|
* @value modal 错误信息modal显示
|
||||||
|
* @event {Function} submit 提交时触发
|
||||||
|
* @event {Function} validate 校验结果发生变化触发
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniForms',
|
||||||
|
emits: ['validate', 'submit'],
|
||||||
|
options: {
|
||||||
|
// #ifdef MP-TOUTIAO
|
||||||
|
virtualHost: false,
|
||||||
|
// #endif
|
||||||
|
// #ifndef MP-TOUTIAO
|
||||||
|
virtualHost: true
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
// 即将弃用
|
||||||
|
value: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// vue3 替换 value 属性
|
||||||
|
modelValue: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 1.4.0 开始将不支持 v-model ,且废弃 value 和 modelValue
|
||||||
|
model: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 表单校验规则
|
||||||
|
rules: {
|
||||||
|
type: Object,
|
||||||
|
default () {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
//校验错误信息提示方式 默认 undertext 取值 [undertext|toast|modal]
|
||||||
|
errShowType: {
|
||||||
|
type: String,
|
||||||
|
default: 'undertext'
|
||||||
|
},
|
||||||
|
// 校验触发器方式 默认 bind 取值 [bind|submit]
|
||||||
|
validateTrigger: {
|
||||||
|
type: String,
|
||||||
|
default: 'submit'
|
||||||
|
},
|
||||||
|
// label 位置,默认 left 取值 top/left
|
||||||
|
labelPosition: {
|
||||||
|
type: String,
|
||||||
|
default: 'left'
|
||||||
|
},
|
||||||
|
// label 宽度
|
||||||
|
labelWidth: {
|
||||||
|
type: [String, Number],
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
// label 居中方式,默认 left 取值 left/center/right
|
||||||
|
labelAlign: {
|
||||||
|
type: String,
|
||||||
|
default: 'left'
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
uniForm: this
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
// 表单本地值的记录,不应该与传如的值进行关联
|
||||||
|
formData: {},
|
||||||
|
formRules: {}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
// 计算数据源变化的
|
||||||
|
localData() {
|
||||||
|
const localVal = this.model || this.modelValue || this.value
|
||||||
|
if (localVal) {
|
||||||
|
return deepCopy(localVal)
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
// 监听数据变化 ,暂时不使用,需要单独赋值
|
||||||
|
// localData: {},
|
||||||
|
// 监听规则变化
|
||||||
|
rules: {
|
||||||
|
handler: function(val, oldVal) {
|
||||||
|
this.setRules(val)
|
||||||
|
},
|
||||||
|
deep: true,
|
||||||
|
immediate: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// #ifdef VUE3
|
||||||
|
let getbinddata = getApp().$vm.$.appContext.config.globalProperties.binddata
|
||||||
|
if (!getbinddata) {
|
||||||
|
getApp().$vm.$.appContext.config.globalProperties.binddata = function(name, value, formName) {
|
||||||
|
if (formName) {
|
||||||
|
this.$refs[formName].setValue(name, value);
|
||||||
|
} else {
|
||||||
|
let formVm;
|
||||||
|
for (let i in this.$refs) {
|
||||||
|
const vm = this.$refs[i];
|
||||||
|
if (vm && vm.$options && vm.$options.name === 'uniForms') {
|
||||||
|
formVm = vm;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!formVm) return console.error('当前 uni-froms 组件缺少 ref 属性');
|
||||||
|
if(formVm.model)formVm.model[name] = value
|
||||||
|
if(formVm.modelValue)formVm.modelValue[name] = value
|
||||||
|
if(formVm.value)formVm.value[name] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// 子组件实例数组
|
||||||
|
this.childrens = []
|
||||||
|
// TODO 兼容旧版 uni-data-picker ,新版本中无效,只是避免报错
|
||||||
|
this.inputChildrens = []
|
||||||
|
this.setRules(this.rules)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 设置规则 ,主要用于小程序自定义检验规则
|
||||||
|
* @param {Array} rules 规则源数据
|
||||||
|
*/
|
||||||
|
setRules(rules) {
|
||||||
|
// TODO 有可能子组件合并规则的时机比这个要早,所以需要合并对象 ,而不是直接赋值,可能会被覆盖
|
||||||
|
this.formRules = Object.assign({}, this.formRules, rules)
|
||||||
|
// 初始化校验函数
|
||||||
|
this.validator = new Validator(rules);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 设置数据,用于设置表单数据,公开给用户使用 , 不支持在动态表单中使用
|
||||||
|
* @param {Object} key
|
||||||
|
* @param {Object} value
|
||||||
|
*/
|
||||||
|
setValue(key, value) {
|
||||||
|
let example = this.childrens.find(child => child.name === key);
|
||||||
|
if (!example) return null;
|
||||||
|
this.formData[key] = getValue(key, value, (this.formRules[key] && this.formRules[key].rules) || [])
|
||||||
|
return example.onFieldChange(this.formData[key]);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 手动提交校验表单
|
||||||
|
* 对整个表单进行校验的方法,参数为一个回调函数。
|
||||||
|
* @param {Array} keepitem 保留不参与校验的字段
|
||||||
|
* @param {type} callback 方法回调
|
||||||
|
*/
|
||||||
|
validate(keepitem, callback) {
|
||||||
|
return this.checkAll(this.formData, keepitem, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 部分表单校验
|
||||||
|
* @param {Array|String} props 需要校验的字段
|
||||||
|
* @param {Function} 回调函数
|
||||||
|
*/
|
||||||
|
validateField(props = [], callback) {
|
||||||
|
props = [].concat(props);
|
||||||
|
let invalidFields = {};
|
||||||
|
this.childrens.forEach(item => {
|
||||||
|
const name = realName(item.name)
|
||||||
|
if (props.indexOf(name) !== -1) {
|
||||||
|
invalidFields = Object.assign({}, invalidFields, {
|
||||||
|
[name]: this.formData[name]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this.checkAll(invalidFields, [], callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法
|
||||||
|
* 移除表单项的校验结果。传入待移除的表单项的 prop 属性或者 prop 组成的数组,如不传则移除整个表单的校验结果
|
||||||
|
* @param {Array|String} props 需要移除校验的字段 ,不填为所有
|
||||||
|
*/
|
||||||
|
clearValidate(props = []) {
|
||||||
|
props = [].concat(props);
|
||||||
|
this.childrens.forEach(item => {
|
||||||
|
if (props.length === 0) {
|
||||||
|
item.errMsg = '';
|
||||||
|
} else {
|
||||||
|
const name = realName(item.name)
|
||||||
|
if (props.indexOf(name) !== -1) {
|
||||||
|
item.errMsg = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部调用方法 ,即将废弃
|
||||||
|
* 手动提交校验表单
|
||||||
|
* 对整个表单进行校验的方法,参数为一个回调函数。
|
||||||
|
* @param {Array} keepitem 保留不参与校验的字段
|
||||||
|
* @param {type} callback 方法回调
|
||||||
|
*/
|
||||||
|
submit(keepitem, callback, type) {
|
||||||
|
for (let i in this.dataValue) {
|
||||||
|
const itemData = this.childrens.find(v => v.name === i);
|
||||||
|
if (itemData) {
|
||||||
|
if (this.formData[i] === undefined) {
|
||||||
|
this.formData[i] = this._getValue(i, this.dataValue[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!type) {
|
||||||
|
console.warn('submit 方法即将废弃,请使用validate方法代替!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.checkAll(this.formData, keepitem, callback, 'submit');
|
||||||
|
},
|
||||||
|
|
||||||
|
// 校验所有
|
||||||
|
async checkAll(invalidFields, keepitem, callback, type) {
|
||||||
|
// 不存在校验规则 ,则停止校验流程
|
||||||
|
if (!this.validator) return
|
||||||
|
let childrens = []
|
||||||
|
// 处理参与校验的item实例
|
||||||
|
for (let i in invalidFields) {
|
||||||
|
const item = this.childrens.find(v => realName(v.name) === i)
|
||||||
|
if (item) {
|
||||||
|
childrens.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果validate第一个参数是funciont ,那就走回调
|
||||||
|
if (!callback && typeof keepitem === 'function') {
|
||||||
|
callback = keepitem;
|
||||||
|
}
|
||||||
|
|
||||||
|
let promise;
|
||||||
|
// 如果不存在回调,那么使用 Promise 方式返回
|
||||||
|
if (!callback && typeof callback !== 'function' && Promise) {
|
||||||
|
promise = new Promise((resolve, reject) => {
|
||||||
|
callback = function(valid, invalidFields) {
|
||||||
|
!valid ? resolve(invalidFields) : reject(valid);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let results = [];
|
||||||
|
// 避免引用错乱 ,建议拷贝对象处理
|
||||||
|
let tempFormData = JSON.parse(JSON.stringify(invalidFields))
|
||||||
|
// 所有子组件参与校验,使用 for 可以使用 awiat
|
||||||
|
for (let i in childrens) {
|
||||||
|
const child = childrens[i]
|
||||||
|
let name = realName(child.name);
|
||||||
|
const result = await child.onFieldChange(tempFormData[name]);
|
||||||
|
if (result) {
|
||||||
|
results.push(result);
|
||||||
|
// toast ,modal 只需要执行第一次就可以
|
||||||
|
if (this.errShowType === 'toast' || this.errShowType === 'modal') break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Array.isArray(results)) {
|
||||||
|
if (results.length === 0) results = null;
|
||||||
|
}
|
||||||
|
if (Array.isArray(keepitem)) {
|
||||||
|
keepitem.forEach(v => {
|
||||||
|
let vName = realName(v);
|
||||||
|
let value = getDataValue(v, this.localData)
|
||||||
|
if (value !== undefined) {
|
||||||
|
tempFormData[vName] = value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO submit 即将废弃
|
||||||
|
if (type === 'submit') {
|
||||||
|
this.$emit('submit', {
|
||||||
|
detail: {
|
||||||
|
value: tempFormData,
|
||||||
|
errors: results
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$emit('validate', results);
|
||||||
|
}
|
||||||
|
|
||||||
|
// const resetFormData = rawData(tempFormData, this.localData, this.name)
|
||||||
|
let resetFormData = {}
|
||||||
|
resetFormData = rawData(tempFormData, this.name)
|
||||||
|
callback && typeof callback === 'function' && callback(results, resetFormData);
|
||||||
|
|
||||||
|
if (promise && callback) {
|
||||||
|
return promise;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回validate事件
|
||||||
|
* @param {Object} result
|
||||||
|
*/
|
||||||
|
validateCheck(result) {
|
||||||
|
this.$emit('validate', result);
|
||||||
|
},
|
||||||
|
_getValue: getValue,
|
||||||
|
_isRequiredField: isRequiredField,
|
||||||
|
_setDataValue: setDataValue,
|
||||||
|
_getDataValue: getDataValue,
|
||||||
|
_realName: realName,
|
||||||
|
_isRealName: isRealName,
|
||||||
|
_isEqual: isEqual
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.uni-forms {}
|
||||||
|
</style>
|
||||||
293
node_modules/@dcloudio/uni-ui/lib/uni-forms/utils.js
generated
vendored
Normal file
293
node_modules/@dcloudio/uni-ui/lib/uni-forms/utils.js
generated
vendored
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
/**
|
||||||
|
* 简单处理对象拷贝
|
||||||
|
* @param {Obejct} 被拷贝对象
|
||||||
|
* @@return {Object} 拷贝对象
|
||||||
|
*/
|
||||||
|
export const deepCopy = (val) => {
|
||||||
|
return JSON.parse(JSON.stringify(val))
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 过滤数字类型
|
||||||
|
* @param {String} format 数字类型
|
||||||
|
* @@return {Boolean} 返回是否为数字类型
|
||||||
|
*/
|
||||||
|
export const typeFilter = (format) => {
|
||||||
|
return format === 'int' || format === 'double' || format === 'number' || format === 'timestamp';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把 value 转换成指定的类型,用于处理初始值,原因是初始值需要入库不能为 undefined
|
||||||
|
* @param {String} key 字段名
|
||||||
|
* @param {any} value 字段值
|
||||||
|
* @param {Object} rules 表单校验规则
|
||||||
|
*/
|
||||||
|
export const getValue = (key, value, rules) => {
|
||||||
|
const isRuleNumType = rules.find(val => val.format && typeFilter(val.format));
|
||||||
|
const isRuleBoolType = rules.find(val => (val.format && val.format === 'boolean') || val.format === 'bool');
|
||||||
|
// 输入类型为 number
|
||||||
|
if (!!isRuleNumType) {
|
||||||
|
if (!value && value !== 0) {
|
||||||
|
value = null
|
||||||
|
} else {
|
||||||
|
value = isNumber(Number(value)) ? Number(value) : value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输入类型为 boolean
|
||||||
|
if (!!isRuleBoolType) {
|
||||||
|
value = isBoolean(value) ? value : false
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单数据
|
||||||
|
* @param {String|Array} name 真实名称,需要使用 realName 获取
|
||||||
|
* @param {Object} data 原始数据
|
||||||
|
* @param {any} value 需要设置的值
|
||||||
|
*/
|
||||||
|
export const setDataValue = (field, formdata, value) => {
|
||||||
|
formdata[field] = value
|
||||||
|
return value || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单数据
|
||||||
|
* @param {String|Array} field 真实名称,需要使用 realName 获取
|
||||||
|
* @param {Object} data 原始数据
|
||||||
|
*/
|
||||||
|
export const getDataValue = (field, data) => {
|
||||||
|
return objGet(data, field)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单类型
|
||||||
|
* @param {String|Array} field 真实名称,需要使用 realName 获取
|
||||||
|
*/
|
||||||
|
export const getDataValueType = (field, data) => {
|
||||||
|
const value = getDataValue(field, data)
|
||||||
|
return {
|
||||||
|
type: type(value),
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单可用的真实name
|
||||||
|
* @param {String|Array} name 表单name
|
||||||
|
* @@return {String} 表单可用的真实name
|
||||||
|
*/
|
||||||
|
export const realName = (name, data = {}) => {
|
||||||
|
const base_name = _basePath(name)
|
||||||
|
if (typeof base_name === 'object' && Array.isArray(base_name) && base_name.length > 1) {
|
||||||
|
const realname = base_name.reduce((a, b) => a += `#${b}`, '_formdata_')
|
||||||
|
return realname
|
||||||
|
}
|
||||||
|
return base_name[0] || name
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否表单可用的真实name
|
||||||
|
* @param {String|Array} name 表单name
|
||||||
|
* @@return {String} 表单可用的真实name
|
||||||
|
*/
|
||||||
|
export const isRealName = (name) => {
|
||||||
|
const reg = /^_formdata_#*/
|
||||||
|
return reg.test(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取表单数据的原始格式
|
||||||
|
* @@return {Object|Array} object 需要解析的数据
|
||||||
|
*/
|
||||||
|
export const rawData = (object = {}, name) => {
|
||||||
|
let newData = JSON.parse(JSON.stringify(object))
|
||||||
|
let formData = {}
|
||||||
|
for(let i in newData){
|
||||||
|
let path = name2arr(i)
|
||||||
|
objSet(formData,path,newData[i])
|
||||||
|
}
|
||||||
|
return formData
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 真实name还原为 array
|
||||||
|
* @param {*} name
|
||||||
|
*/
|
||||||
|
export const name2arr = (name) => {
|
||||||
|
let field = name.replace('_formdata_#', '')
|
||||||
|
field = field.split('#').map(v => (isNumber(v) ? Number(v) : v))
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象中设置值
|
||||||
|
* @param {Object|Array} object 源数据
|
||||||
|
* @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
|
||||||
|
* @param {String} value 需要设置的值
|
||||||
|
*/
|
||||||
|
export const objSet = (object, path, value) => {
|
||||||
|
if (typeof object !== 'object') return object;
|
||||||
|
_basePath(path).reduce((o, k, i, _) => {
|
||||||
|
if (i === _.length - 1) {
|
||||||
|
// 若遍历结束直接赋值
|
||||||
|
o[k] = value
|
||||||
|
return null
|
||||||
|
} else if (k in o) {
|
||||||
|
// 若存在对应路径,则返回找到的对象,进行下一次遍历
|
||||||
|
return o[k]
|
||||||
|
} else {
|
||||||
|
// 若不存在对应路径,则创建对应对象,若下一路径是数字,新对象赋值为空数组,否则赋值为空对象
|
||||||
|
o[k] = /^[0-9]{1,}$/.test(_[i + 1]) ? [] : {}
|
||||||
|
return o[k]
|
||||||
|
}
|
||||||
|
}, object)
|
||||||
|
// 返回object
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 path, path有三种形式:'a[0].b.c'、'a.0.b.c' 和 ['a','0','b','c'],需要统一处理成数组,便于后续使用
|
||||||
|
function _basePath(path) {
|
||||||
|
// 若是数组,则直接返回
|
||||||
|
if (Array.isArray(path)) return path
|
||||||
|
// 若有 '[',']',则替换成将 '[' 替换成 '.',去掉 ']'
|
||||||
|
return path.replace(/\[/g, '.').replace(/\]/g, '').split('.')
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从对象中获取值
|
||||||
|
* @param {Object|Array} object 源数据
|
||||||
|
* @param {String| Array} path 'a.b.c' 或 ['a',0,'b','c']
|
||||||
|
* @param {String} defaultVal 如果无法从调用链中获取值的默认值
|
||||||
|
*/
|
||||||
|
export const objGet = (object, path, defaultVal = 'undefined') => {
|
||||||
|
// 先将path处理成统一格式
|
||||||
|
let newPath = _basePath(path)
|
||||||
|
// 递归处理,返回最后结果
|
||||||
|
let val = newPath.reduce((o, k) => {
|
||||||
|
return (o || {})[k]
|
||||||
|
}, object);
|
||||||
|
return !val || val !== undefined ? val : defaultVal
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为 number 类型
|
||||||
|
* @param {any} num 需要判断的值
|
||||||
|
* @return {Boolean} 是否为 number
|
||||||
|
*/
|
||||||
|
export const isNumber = (num) => {
|
||||||
|
return !isNaN(Number(num))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为 boolean 类型
|
||||||
|
* @param {any} bool 需要判断的值
|
||||||
|
* @return {Boolean} 是否为 boolean
|
||||||
|
*/
|
||||||
|
export const isBoolean = (bool) => {
|
||||||
|
return (typeof bool === 'boolean')
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 是否有必填字段
|
||||||
|
* @param {Object} rules 规则
|
||||||
|
* @return {Boolean} 是否有必填字段
|
||||||
|
*/
|
||||||
|
export const isRequiredField = (rules) => {
|
||||||
|
let isNoField = false;
|
||||||
|
for (let i = 0; i < rules.length; i++) {
|
||||||
|
const ruleData = rules[i];
|
||||||
|
if (ruleData.required) {
|
||||||
|
isNoField = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isNoField;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据类型
|
||||||
|
* @param {Any} obj 需要获取数据类型的值
|
||||||
|
*/
|
||||||
|
export const type = (obj) => {
|
||||||
|
var class2type = {};
|
||||||
|
|
||||||
|
// 生成class2type映射
|
||||||
|
"Boolean Number String Function Array Date RegExp Object Error".split(" ").map(function(item, index) {
|
||||||
|
class2type["[object " + item + "]"] = item.toLowerCase();
|
||||||
|
})
|
||||||
|
if (obj == null) {
|
||||||
|
return obj + "";
|
||||||
|
}
|
||||||
|
return typeof obj === "object" || typeof obj === "function" ?
|
||||||
|
class2type[Object.prototype.toString.call(obj)] || "object" :
|
||||||
|
typeof obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断两个值是否相等
|
||||||
|
* @param {any} a 值
|
||||||
|
* @param {any} b 值
|
||||||
|
* @return {Boolean} 是否相等
|
||||||
|
*/
|
||||||
|
export const isEqual = (a, b) => {
|
||||||
|
//如果a和b本来就全等
|
||||||
|
if (a === b) {
|
||||||
|
//判断是否为0和-0
|
||||||
|
return a !== 0 || 1 / a === 1 / b;
|
||||||
|
}
|
||||||
|
//判断是否为null和undefined
|
||||||
|
if (a == null || b == null) {
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
//接下来判断a和b的数据类型
|
||||||
|
var classNameA = toString.call(a),
|
||||||
|
classNameB = toString.call(b);
|
||||||
|
//如果数据类型不相等,则返回false
|
||||||
|
if (classNameA !== classNameB) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//如果数据类型相等,再根据不同数据类型分别判断
|
||||||
|
switch (classNameA) {
|
||||||
|
case '[object RegExp]':
|
||||||
|
case '[object String]':
|
||||||
|
//进行字符串转换比较
|
||||||
|
return '' + a === '' + b;
|
||||||
|
case '[object Number]':
|
||||||
|
//进行数字转换比较,判断是否为NaN
|
||||||
|
if (+a !== +a) {
|
||||||
|
return +b !== +b;
|
||||||
|
}
|
||||||
|
//判断是否为0或-0
|
||||||
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
||||||
|
case '[object Date]':
|
||||||
|
case '[object Boolean]':
|
||||||
|
return +a === +b;
|
||||||
|
}
|
||||||
|
//如果是对象类型
|
||||||
|
if (classNameA == '[object Object]') {
|
||||||
|
//获取a和b的属性长度
|
||||||
|
var propsA = Object.getOwnPropertyNames(a),
|
||||||
|
propsB = Object.getOwnPropertyNames(b);
|
||||||
|
if (propsA.length != propsB.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < propsA.length; i++) {
|
||||||
|
var propName = propsA[i];
|
||||||
|
//如果对应属性对应值不相等,则返回false
|
||||||
|
if (a[propName] !== b[propName]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//如果是数组类型
|
||||||
|
if (classNameA == '[object Array]') {
|
||||||
|
if (a.toString() == b.toString()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
486
node_modules/@dcloudio/uni-ui/lib/uni-forms/validate.js
generated
vendored
Normal file
486
node_modules/@dcloudio/uni-ui/lib/uni-forms/validate.js
generated
vendored
Normal file
@ -0,0 +1,486 @@
|
|||||||
|
var pattern = {
|
||||||
|
email: /^\S+?@\S+?\.\S+?$/,
|
||||||
|
idcard: /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
||||||
|
url: new RegExp(
|
||||||
|
"^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$",
|
||||||
|
'i')
|
||||||
|
};
|
||||||
|
|
||||||
|
const FORMAT_MAPPING = {
|
||||||
|
"int": 'integer',
|
||||||
|
"bool": 'boolean',
|
||||||
|
"double": 'number',
|
||||||
|
"long": 'number',
|
||||||
|
"password": 'string'
|
||||||
|
// "fileurls": 'array'
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatMessage(args, resources = '') {
|
||||||
|
var defaultMessage = ['label']
|
||||||
|
defaultMessage.forEach((item) => {
|
||||||
|
if (args[item] === undefined) {
|
||||||
|
args[item] = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let str = resources
|
||||||
|
for (let key in args) {
|
||||||
|
let reg = new RegExp('{' + key + '}')
|
||||||
|
str = str.replace(reg, args[key])
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEmptyValue(value, type) {
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value === 'string' && !value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(value) && !value.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'object' && !Object.keys(value).length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const types = {
|
||||||
|
integer(value) {
|
||||||
|
return types.number(value) && parseInt(value, 10) === value;
|
||||||
|
},
|
||||||
|
string(value) {
|
||||||
|
return typeof value === 'string';
|
||||||
|
},
|
||||||
|
number(value) {
|
||||||
|
if (isNaN(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return typeof value === 'number';
|
||||||
|
},
|
||||||
|
"boolean": function(value) {
|
||||||
|
return typeof value === 'boolean';
|
||||||
|
},
|
||||||
|
"float": function(value) {
|
||||||
|
return types.number(value) && !types.integer(value);
|
||||||
|
},
|
||||||
|
array(value) {
|
||||||
|
return Array.isArray(value);
|
||||||
|
},
|
||||||
|
object(value) {
|
||||||
|
return typeof value === 'object' && !types.array(value);
|
||||||
|
},
|
||||||
|
date(value) {
|
||||||
|
return value instanceof Date;
|
||||||
|
},
|
||||||
|
timestamp(value) {
|
||||||
|
if (!this.integer(value) || Math.abs(value).toString().length > 16) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
file(value) {
|
||||||
|
return typeof value.url === 'string';
|
||||||
|
},
|
||||||
|
email(value) {
|
||||||
|
return typeof value === 'string' && !!value.match(pattern.email) && value.length < 255;
|
||||||
|
},
|
||||||
|
url(value) {
|
||||||
|
return typeof value === 'string' && !!value.match(pattern.url);
|
||||||
|
},
|
||||||
|
pattern(reg, value) {
|
||||||
|
try {
|
||||||
|
return new RegExp(reg).test(value);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
method(value) {
|
||||||
|
return typeof value === 'function';
|
||||||
|
},
|
||||||
|
idcard(value) {
|
||||||
|
return typeof value === 'string' && !!value.match(pattern.idcard);
|
||||||
|
},
|
||||||
|
'url-https'(value) {
|
||||||
|
return this.url(value) && value.startsWith('https://');
|
||||||
|
},
|
||||||
|
'url-scheme'(value) {
|
||||||
|
return value.startsWith('://');
|
||||||
|
},
|
||||||
|
'url-web'(value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RuleValidator {
|
||||||
|
|
||||||
|
constructor(message) {
|
||||||
|
this._message = message
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateRule(fieldKey, fieldValue, value, data, allData) {
|
||||||
|
var result = null
|
||||||
|
|
||||||
|
let rules = fieldValue.rules
|
||||||
|
|
||||||
|
let hasRequired = rules.findIndex((item) => {
|
||||||
|
return item.required
|
||||||
|
})
|
||||||
|
if (hasRequired < 0) {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
if (typeof value === 'string' && !value.length) {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = this._message
|
||||||
|
|
||||||
|
if (rules === undefined) {
|
||||||
|
return message['default']
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < rules.length; i++) {
|
||||||
|
let rule = rules[i]
|
||||||
|
let vt = this._getValidateType(rule)
|
||||||
|
|
||||||
|
Object.assign(rule, {
|
||||||
|
label: fieldValue.label || `["${fieldKey}"]`
|
||||||
|
})
|
||||||
|
|
||||||
|
if (RuleValidatorHelper[vt]) {
|
||||||
|
result = RuleValidatorHelper[vt](rule, value, message)
|
||||||
|
if (result != null) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.validateExpr) {
|
||||||
|
let now = Date.now()
|
||||||
|
let resultExpr = rule.validateExpr(value, allData, now)
|
||||||
|
if (resultExpr === false) {
|
||||||
|
result = this._getMessage(rule, rule.errorMessage || this._message['default'])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.validateFunction) {
|
||||||
|
result = await this.validateFunction(rule, value, data, allData, vt)
|
||||||
|
if (result !== null) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result !== null) {
|
||||||
|
result = message.TAG + result
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateFunction(rule, value, data, allData, vt) {
|
||||||
|
let result = null
|
||||||
|
try {
|
||||||
|
let callbackMessage = null
|
||||||
|
const res = await rule.validateFunction(rule, value, allData || data, (message) => {
|
||||||
|
callbackMessage = message
|
||||||
|
})
|
||||||
|
if (callbackMessage || (typeof res === 'string' && res) || res === false) {
|
||||||
|
result = this._getMessage(rule, callbackMessage || res, vt)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
result = this._getMessage(rule, e.message, vt)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
_getMessage(rule, message, vt) {
|
||||||
|
return formatMessage(rule, message || rule.errorMessage || this._message[vt] || message['default'])
|
||||||
|
}
|
||||||
|
|
||||||
|
_getValidateType(rule) {
|
||||||
|
var result = ''
|
||||||
|
if (rule.required) {
|
||||||
|
result = 'required'
|
||||||
|
} else if (rule.format) {
|
||||||
|
result = 'format'
|
||||||
|
} else if (rule.arrayType) {
|
||||||
|
result = 'arrayTypeFormat'
|
||||||
|
} else if (rule.range) {
|
||||||
|
result = 'range'
|
||||||
|
} else if (rule.maximum !== undefined || rule.minimum !== undefined) {
|
||||||
|
result = 'rangeNumber'
|
||||||
|
} else if (rule.maxLength !== undefined || rule.minLength !== undefined) {
|
||||||
|
result = 'rangeLength'
|
||||||
|
} else if (rule.pattern) {
|
||||||
|
result = 'pattern'
|
||||||
|
} else if (rule.validateFunction) {
|
||||||
|
result = 'validateFunction'
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const RuleValidatorHelper = {
|
||||||
|
required(rule, value, message) {
|
||||||
|
if (rule.required && isEmptyValue(value, rule.format || typeof value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.required);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
range(rule, value, message) {
|
||||||
|
const {
|
||||||
|
range,
|
||||||
|
errorMessage
|
||||||
|
} = rule;
|
||||||
|
|
||||||
|
let list = new Array(range.length);
|
||||||
|
for (let i = 0; i < range.length; i++) {
|
||||||
|
const item = range[i];
|
||||||
|
if (types.object(item) && item.value !== undefined) {
|
||||||
|
list[i] = item.value;
|
||||||
|
} else {
|
||||||
|
list[i] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = false
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
result = (new Set(value.concat(list)).size === list.length);
|
||||||
|
} else {
|
||||||
|
if (list.indexOf(value) > -1) {
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return formatMessage(rule, errorMessage || message['enum']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
rangeNumber(rule, value, message) {
|
||||||
|
if (!types.number(value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
let {
|
||||||
|
minimum,
|
||||||
|
maximum,
|
||||||
|
exclusiveMinimum,
|
||||||
|
exclusiveMaximum
|
||||||
|
} = rule;
|
||||||
|
let min = exclusiveMinimum ? value <= minimum : value < minimum;
|
||||||
|
let max = exclusiveMaximum ? value >= maximum : value > maximum;
|
||||||
|
|
||||||
|
if (minimum !== undefined && min) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['number'][exclusiveMinimum ?
|
||||||
|
'exclusiveMinimum' : 'minimum'
|
||||||
|
])
|
||||||
|
} else if (maximum !== undefined && max) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['number'][exclusiveMaximum ?
|
||||||
|
'exclusiveMaximum' : 'maximum'
|
||||||
|
])
|
||||||
|
} else if (minimum !== undefined && maximum !== undefined && (min || max)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['number'].range)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
rangeLength(rule, value, message) {
|
||||||
|
if (!types.string(value) && !types.array(value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
let min = rule.minLength;
|
||||||
|
let max = rule.maxLength;
|
||||||
|
let val = value.length;
|
||||||
|
|
||||||
|
if (min !== undefined && val < min) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['length'].minLength)
|
||||||
|
} else if (max !== undefined && val > max) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['length'].maxLength)
|
||||||
|
} else if (min !== undefined && max !== undefined && (val < min || val > max)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message['length'].range)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
pattern(rule, value, message) {
|
||||||
|
if (!types['pattern'](rule.pattern, value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.pattern.mismatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
format(rule, value, message) {
|
||||||
|
var customTypes = Object.keys(types);
|
||||||
|
var format = FORMAT_MAPPING[rule.format] ? FORMAT_MAPPING[rule.format] : (rule.format || rule.arrayType);
|
||||||
|
|
||||||
|
if (customTypes.indexOf(format) > -1) {
|
||||||
|
if (!types[format](value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.typeError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
|
||||||
|
arrayTypeFormat(rule, value, message) {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
return formatMessage(rule, rule.errorMessage || message.typeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
const element = value[i];
|
||||||
|
let formatResult = this.format(rule, element, message)
|
||||||
|
if (formatResult !== null) {
|
||||||
|
return formatResult
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SchemaValidator extends RuleValidator {
|
||||||
|
|
||||||
|
constructor(schema, options) {
|
||||||
|
super(SchemaValidator.message);
|
||||||
|
|
||||||
|
this._schema = schema
|
||||||
|
this._options = options || null
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSchema(schema) {
|
||||||
|
this._schema = schema
|
||||||
|
}
|
||||||
|
|
||||||
|
async validate(data, allData) {
|
||||||
|
let result = this._checkFieldInSchema(data)
|
||||||
|
if (!result) {
|
||||||
|
result = await this.invokeValidate(data, false, allData)
|
||||||
|
}
|
||||||
|
return result.length ? result[0] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateAll(data, allData) {
|
||||||
|
let result = this._checkFieldInSchema(data)
|
||||||
|
if (!result) {
|
||||||
|
result = await this.invokeValidate(data, true, allData)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async validateUpdate(data, allData) {
|
||||||
|
let result = this._checkFieldInSchema(data)
|
||||||
|
if (!result) {
|
||||||
|
result = await this.invokeValidateUpdate(data, false, allData)
|
||||||
|
}
|
||||||
|
return result.length ? result[0] : null
|
||||||
|
}
|
||||||
|
|
||||||
|
async invokeValidate(data, all, allData) {
|
||||||
|
let result = []
|
||||||
|
let schema = this._schema
|
||||||
|
for (let key in schema) {
|
||||||
|
let value = schema[key]
|
||||||
|
let errorMessage = await this.validateRule(key, value, data[key], data, allData)
|
||||||
|
if (errorMessage != null) {
|
||||||
|
result.push({
|
||||||
|
key,
|
||||||
|
errorMessage
|
||||||
|
})
|
||||||
|
if (!all) break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
async invokeValidateUpdate(data, all, allData) {
|
||||||
|
let result = []
|
||||||
|
for (let key in data) {
|
||||||
|
let errorMessage = await this.validateRule(key, this._schema[key], data[key], data, allData)
|
||||||
|
if (errorMessage != null) {
|
||||||
|
result.push({
|
||||||
|
key,
|
||||||
|
errorMessage
|
||||||
|
})
|
||||||
|
if (!all) break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
_checkFieldInSchema(data) {
|
||||||
|
var keys = Object.keys(data)
|
||||||
|
var keys2 = Object.keys(this._schema)
|
||||||
|
if (new Set(keys.concat(keys2)).size === keys2.length) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
var noExistFields = keys.filter((key) => {
|
||||||
|
return keys2.indexOf(key) < 0;
|
||||||
|
})
|
||||||
|
var errorMessage = formatMessage({
|
||||||
|
field: JSON.stringify(noExistFields)
|
||||||
|
}, SchemaValidator.message.TAG + SchemaValidator.message['defaultInvalid'])
|
||||||
|
return [{
|
||||||
|
key: 'invalid',
|
||||||
|
errorMessage
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Message() {
|
||||||
|
return {
|
||||||
|
TAG: "",
|
||||||
|
default: '验证错误',
|
||||||
|
defaultInvalid: '提交的字段{field}在数据库中并不存在',
|
||||||
|
validateFunction: '验证无效',
|
||||||
|
required: '{label}必填',
|
||||||
|
'enum': '{label}超出范围',
|
||||||
|
timestamp: '{label}格式无效',
|
||||||
|
whitespace: '{label}不能为空',
|
||||||
|
typeError: '{label}类型无效',
|
||||||
|
date: {
|
||||||
|
format: '{label}日期{value}格式无效',
|
||||||
|
parse: '{label}日期无法解析,{value}无效',
|
||||||
|
invalid: '{label}日期{value}无效'
|
||||||
|
},
|
||||||
|
length: {
|
||||||
|
minLength: '{label}长度不能少于{minLength}',
|
||||||
|
maxLength: '{label}长度不能超过{maxLength}',
|
||||||
|
range: '{label}必须介于{minLength}和{maxLength}之间'
|
||||||
|
},
|
||||||
|
number: {
|
||||||
|
minimum: '{label}不能小于{minimum}',
|
||||||
|
maximum: '{label}不能大于{maximum}',
|
||||||
|
exclusiveMinimum: '{label}不能小于等于{minimum}',
|
||||||
|
exclusiveMaximum: '{label}不能大于等于{maximum}',
|
||||||
|
range: '{label}必须介于{minimum}and{maximum}之间'
|
||||||
|
},
|
||||||
|
pattern: {
|
||||||
|
mismatch: '{label}格式不匹配'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SchemaValidator.message = new Message();
|
||||||
|
|
||||||
|
export default SchemaValidator
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/en.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/en.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-goods-nav.options.shop": "shop",
|
||||||
|
"uni-goods-nav.options.cart": "cart",
|
||||||
|
"uni-goods-nav.buttonGroup.addToCart": "add to cart",
|
||||||
|
"uni-goods-nav.buttonGroup.buyNow": "buy now"
|
||||||
|
}
|
||||||
8
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/index.js
generated
vendored
Normal file
8
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/index.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import en from './en.json'
|
||||||
|
import zhHans from './zh-Hans.json'
|
||||||
|
import zhHant from './zh-Hant.json'
|
||||||
|
export default {
|
||||||
|
en,
|
||||||
|
'zh-Hans': zhHans,
|
||||||
|
'zh-Hant': zhHant
|
||||||
|
}
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/zh-Hans.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/zh-Hans.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-goods-nav.options.shop": "店铺",
|
||||||
|
"uni-goods-nav.options.cart": "购物车",
|
||||||
|
"uni-goods-nav.buttonGroup.addToCart": "加入购物车",
|
||||||
|
"uni-goods-nav.buttonGroup.buyNow": "立即购买"
|
||||||
|
}
|
||||||
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/zh-Hant.json
generated
vendored
Normal file
6
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/i18n/zh-Hant.json
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"uni-goods-nav.options.shop": "店鋪",
|
||||||
|
"uni-goods-nav.options.cart": "購物車",
|
||||||
|
"uni-goods-nav.buttonGroup.addToCart": "加入購物車",
|
||||||
|
"uni-goods-nav.buttonGroup.buyNow": "立即購買"
|
||||||
|
}
|
||||||
231
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue
generated
vendored
Normal file
231
node_modules/@dcloudio/uni-ui/lib/uni-goods-nav/uni-goods-nav.vue
generated
vendored
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-goods-nav">
|
||||||
|
<!-- 底部占位 -->
|
||||||
|
<view class="uni-tab__seat" />
|
||||||
|
<view class="uni-tab__cart-box flex">
|
||||||
|
<view class="flex uni-tab__cart-sub-left">
|
||||||
|
<view v-for="(item,index) in options" :key="index" class="flex uni-tab__cart-button-left uni-tab__shop-cart" @click="onClick(index,item)">
|
||||||
|
<view class="uni-tab__icon">
|
||||||
|
<uni-icons :type="item.icon" size="20" color="#646566"></uni-icons>
|
||||||
|
<!-- <image class="image" :src="item.icon" mode="widthFix" /> -->
|
||||||
|
</view>
|
||||||
|
<text class="uni-tab__text">{{ item.text }}</text>
|
||||||
|
<view class="flex uni-tab__dot-box">
|
||||||
|
<text v-if="item.info" :class="{ 'uni-tab__dots': item.info > 9 }" class="uni-tab__dot " :style="{'backgroundColor':item.infoBackgroundColor?item.infoBackgroundColor:'#ff0000',
|
||||||
|
color:item.infoColor?item.infoColor:'#fff'
|
||||||
|
}">{{ item.info }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view :class="{'uni-tab__right':fill}" class="flex uni-tab__cart-sub-right ">
|
||||||
|
<view v-for="(item,index) in buttonGroup" :key="index" :style="{background:item.backgroundColor,color:item.color}"
|
||||||
|
class="flex uni-tab__cart-button-right" @click="buttonClick(index,item)"><text :style="{color:item.color}" class="uni-tab__cart-button-right-text">{{ item.text }}</text></view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
initVueI18n
|
||||||
|
} from '@dcloudio/uni-i18n'
|
||||||
|
import messages from './i18n/index.js'
|
||||||
|
const { t } = initVueI18n(messages)
|
||||||
|
/**
|
||||||
|
* GoodsNav 商品导航
|
||||||
|
* @description 商品加入购物车、立即购买等
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=865
|
||||||
|
* @property {Array} options 组件参数
|
||||||
|
* @property {Array} buttonGroup 组件按钮组参数
|
||||||
|
* @property {Boolean} fill = [true | false] 组件按钮组参数
|
||||||
|
* @property {Boolean} stat 是否开启统计功能
|
||||||
|
* @event {Function} click 左侧点击事件
|
||||||
|
* @event {Function} buttonClick 右侧按钮组点击事件
|
||||||
|
* @example <uni-goods-nav :fill="true" options="" buttonGroup="buttonGroup" @click="" @buttonClick="" />
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniGoodsNav',
|
||||||
|
emits:['click','buttonClick'],
|
||||||
|
props: {
|
||||||
|
options: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return [{
|
||||||
|
icon: 'shop',
|
||||||
|
text: t("uni-goods-nav.options.shop"),
|
||||||
|
}, {
|
||||||
|
icon: 'cart',
|
||||||
|
text: t("uni-goods-nav.options.cart")
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonGroup: {
|
||||||
|
type: Array,
|
||||||
|
default () {
|
||||||
|
return [{
|
||||||
|
text: t("uni-goods-nav.buttonGroup.addToCart"),
|
||||||
|
backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
|
||||||
|
color: '#fff'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: t("uni-goods-nav.buttonGroup.buyNow"),
|
||||||
|
backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fill: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
stat:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onClick(index, item) {
|
||||||
|
this.$emit('click', {
|
||||||
|
index,
|
||||||
|
content: item,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
buttonClick(index, item) {
|
||||||
|
if (uni.report && this.stat) {
|
||||||
|
uni.report(item.text, item.text)
|
||||||
|
}
|
||||||
|
this.$emit('buttonClick', {
|
||||||
|
index,
|
||||||
|
content: item
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" >
|
||||||
|
.flex {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-goods-nav {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-box {
|
||||||
|
flex: 1;
|
||||||
|
height: 50px;
|
||||||
|
background-color: #fff;
|
||||||
|
z-index: 900;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-sub-left {
|
||||||
|
padding: 0 5px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-sub-right {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__right {
|
||||||
|
margin: 5px 0;
|
||||||
|
margin-right: 10px;
|
||||||
|
border-radius: 100px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-button-left {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
// flex: 1;
|
||||||
|
position: relative;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
margin: 0 10px;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__icon {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__text {
|
||||||
|
margin-top: 3px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #646566;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-button-right {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-button-right-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__cart-button-right:active {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__dot-box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
/* #endif */
|
||||||
|
position: absolute;
|
||||||
|
right: -2px;
|
||||||
|
top: 2px;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
// width: 0;
|
||||||
|
// height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__dot {
|
||||||
|
// width: 30rpx;
|
||||||
|
// height: 30rpx;
|
||||||
|
padding: 0 4px;
|
||||||
|
line-height: 15px;
|
||||||
|
color: #ffffff;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
background-color: #ff0000;
|
||||||
|
border-radius: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-tab__dots {
|
||||||
|
padding: 0 4px;
|
||||||
|
// width: auto;
|
||||||
|
border-radius: 15px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
127
node_modules/@dcloudio/uni-ui/lib/uni-grid-item/uni-grid-item.vue
generated
vendored
Normal file
127
node_modules/@dcloudio/uni-ui/lib/uni-grid-item/uni-grid-item.vue
generated
vendored
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
<template>
|
||||||
|
<view v-if="width" :style="'width:'+width+';'+(square?'height:'+width:'')" class="uni-grid-item">
|
||||||
|
<view :class="{ 'uni-grid-item--border': showBorder, 'uni-grid-item--border-top': showBorder && index < column, 'uni-highlight': highlight }"
|
||||||
|
:style="{'border-right-color': borderColor ,'border-bottom-color': borderColor ,'border-top-color': borderColor }"
|
||||||
|
class="uni-grid-item__box" @click="_onClick">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* GridItem 宫格
|
||||||
|
* @description 宫格组件
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=27
|
||||||
|
* @property {Number} index 子组件的唯一标识 ,点击gird会返回当前的标识
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniGridItem',
|
||||||
|
inject: ['grid'],
|
||||||
|
props: {
|
||||||
|
index: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
column: 0,
|
||||||
|
showBorder: true,
|
||||||
|
square: true,
|
||||||
|
highlight: true,
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
openNum: 2,
|
||||||
|
width: 0,
|
||||||
|
borderColor: '#e5e5e5'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.column = this.grid.column
|
||||||
|
this.showBorder = this.grid.showBorder
|
||||||
|
this.square = this.grid.square
|
||||||
|
this.highlight = this.grid.highlight
|
||||||
|
this.top = this.hor === 0 ? this.grid.hor : this.hor
|
||||||
|
this.left = this.ver === 0 ? this.grid.ver : this.ver
|
||||||
|
this.borderColor = this.grid.borderColor
|
||||||
|
this.grid.children.push(this)
|
||||||
|
// this.grid.init()
|
||||||
|
this.width = this.grid.width
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.grid.children.forEach((item, index) => {
|
||||||
|
if (item === this) {
|
||||||
|
this.grid.children.splice(index, 1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
_onClick() {
|
||||||
|
this.grid.change({
|
||||||
|
detail: {
|
||||||
|
index: this.index
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.uni-grid-item {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifdef H5 */
|
||||||
|
cursor: pointer;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-grid-item__box {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
/* #endif */
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: column;
|
||||||
|
// justify-content: center;
|
||||||
|
// align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-grid-item--border {
|
||||||
|
position: relative;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
border-bottom-color: #D2D2D2;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-bottom-width: 0.5px;
|
||||||
|
border-right-color: #D2D2D2;
|
||||||
|
border-right-style: solid;
|
||||||
|
border-right-width: 0.5px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
z-index: 0;
|
||||||
|
border-bottom: 1px #D2D2D2 solid;
|
||||||
|
border-right: 1px #D2D2D2 solid;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
.uni-grid-item--border-top {
|
||||||
|
position: relative;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
border-top-color: #D2D2D2;
|
||||||
|
border-top-style: solid;
|
||||||
|
border-top-width: 0.5px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
border-top: 1px #D2D2D2 solid;
|
||||||
|
z-index: 0;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.uni-highlight:active {
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
142
node_modules/@dcloudio/uni-ui/lib/uni-grid/uni-grid.vue
generated
vendored
Normal file
142
node_modules/@dcloudio/uni-ui/lib/uni-grid/uni-grid.vue
generated
vendored
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-grid-wrap">
|
||||||
|
<view :id="elId" ref="uni-grid" class="uni-grid" :class="{ 'uni-grid--border': showBorder }" :style="{ 'border-left-color':borderColor}">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
const dom = uni.requireNativePlugin('dom');
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grid 宫格
|
||||||
|
* @description 宫格组件
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=27
|
||||||
|
* @property {Number} column 每列显示个数
|
||||||
|
* @property {String} borderColor 边框颜色
|
||||||
|
* @property {Boolean} showBorder 是否显示边框
|
||||||
|
* @property {Boolean} square 是否方形显示
|
||||||
|
* @property {Boolean} Boolean 点击背景是否高亮
|
||||||
|
* @event {Function} change 点击 grid 触发,e={detail:{index:0}},index 为当前点击 gird 下标
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'UniGrid',
|
||||||
|
emits:['change'],
|
||||||
|
props: {
|
||||||
|
// 每列显示个数
|
||||||
|
column: {
|
||||||
|
type: Number,
|
||||||
|
default: 3
|
||||||
|
},
|
||||||
|
// 是否显示边框
|
||||||
|
showBorder: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
// 边框颜色
|
||||||
|
borderColor: {
|
||||||
|
type: String,
|
||||||
|
default: '#D2D2D2'
|
||||||
|
},
|
||||||
|
// 是否正方形显示,默认为 true
|
||||||
|
square: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
highlight: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
grid: this
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
const elId = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
|
||||||
|
return {
|
||||||
|
elId,
|
||||||
|
width: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.children = []
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.$nextTick(()=>{
|
||||||
|
this.init()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
init() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this._getSize((width) => {
|
||||||
|
this.children.forEach((item, index) => {
|
||||||
|
item.width = width
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}, 50)
|
||||||
|
},
|
||||||
|
change(e) {
|
||||||
|
this.$emit('change', e)
|
||||||
|
},
|
||||||
|
_getSize(fn) {
|
||||||
|
// #ifndef APP-NVUE
|
||||||
|
uni.createSelectorQuery()
|
||||||
|
.in(this)
|
||||||
|
.select(`#${this.elId}`)
|
||||||
|
.boundingClientRect()
|
||||||
|
.exec(ret => {
|
||||||
|
this.width = parseInt((ret[0].width - 1) / this.column) + 'px'
|
||||||
|
fn(this.width)
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
// #ifdef APP-NVUE
|
||||||
|
dom.getComponentRect(this.$refs['uni-grid'], (ret) => {
|
||||||
|
this.width = parseInt((ret.size.width - 1) / this.column) + 'px'
|
||||||
|
fn(this.width)
|
||||||
|
})
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.uni-grid-wrap {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex: 1;
|
||||||
|
flex-direction: column;
|
||||||
|
/* #ifdef H5 */
|
||||||
|
width: 100%;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-grid {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
// flex: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-grid--border {
|
||||||
|
position: relative;
|
||||||
|
/* #ifdef APP-NVUE */
|
||||||
|
border-left-color: #D2D2D2;
|
||||||
|
border-left-style: solid;
|
||||||
|
border-left-width: 0.5px;
|
||||||
|
/* #endif */
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
z-index: 1;
|
||||||
|
border-left: 1px #D2D2D2 solid;
|
||||||
|
/* #endif */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
134
node_modules/@dcloudio/uni-ui/lib/uni-group/uni-group.vue
generated
vendored
Normal file
134
node_modules/@dcloudio/uni-ui/lib/uni-group/uni-group.vue
generated
vendored
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
<template>
|
||||||
|
<view class="uni-group" :class="['uni-group--'+mode ,margin?'group-margin':'']" :style="{marginTop: `${top}px` }">
|
||||||
|
<slot name="title">
|
||||||
|
<view v-if="title" class="uni-group__title" :style="{'padding-left':border?'30px':'15px'}">
|
||||||
|
<text class="uni-group__title-text">{{ title }}</text>
|
||||||
|
</view>
|
||||||
|
</slot>
|
||||||
|
<view class="uni-group__content" :class="{'group-conent-padding':border}">
|
||||||
|
<slot />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/**
|
||||||
|
* Group 分组
|
||||||
|
* @description 表单字段分组
|
||||||
|
* @tutorial https://ext.dcloud.net.cn/plugin?id=3281
|
||||||
|
* @property {String} title 主标题
|
||||||
|
* @property {Number} top 分组间隔
|
||||||
|
* @property {Number} mode 模式
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
name: 'uniGroup',
|
||||||
|
emits:['click'],
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
top: {
|
||||||
|
type: [Number, String],
|
||||||
|
default: 10
|
||||||
|
},
|
||||||
|
mode: {
|
||||||
|
type: String,
|
||||||
|
default: 'default'
|
||||||
|
},
|
||||||
|
stat:{
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
margin: false,
|
||||||
|
border: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
title(newVal) {
|
||||||
|
if (uni.report && this.stat && newVal !== '') {
|
||||||
|
uni.report('title', newVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.form = this.getForm()
|
||||||
|
if (this.form) {
|
||||||
|
this.margin = true
|
||||||
|
this.border = this.form.border
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
/**
|
||||||
|
* 获取父元素实例
|
||||||
|
*/
|
||||||
|
getForm() {
|
||||||
|
let parent = this.$parent;
|
||||||
|
let parentName = parent.$options.name;
|
||||||
|
while (parentName !== 'uniForms') {
|
||||||
|
parent = parent.$parent;
|
||||||
|
if (!parent) return false
|
||||||
|
parentName = parent.$options.name;
|
||||||
|
}
|
||||||
|
return parent;
|
||||||
|
},
|
||||||
|
onClick() {
|
||||||
|
this.$emit('click')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<style lang="scss" >
|
||||||
|
.uni-group {
|
||||||
|
background: #fff;
|
||||||
|
margin-top: 10px;
|
||||||
|
// border: 1px red solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-margin {
|
||||||
|
// margin: 0 -15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-group__title {
|
||||||
|
/* #ifndef APP-NVUE */
|
||||||
|
display: flex;
|
||||||
|
/* #endif */
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 15px;
|
||||||
|
height: 40px;
|
||||||
|
background-color: #eee;
|
||||||
|
font-weight: normal;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-group__content {
|
||||||
|
padding: 15px;
|
||||||
|
// padding-bottom: 5px;
|
||||||
|
// background-color: #FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-conent-padding {
|
||||||
|
padding: 0 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-group__title-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.distraction {
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uni-group--card {
|
||||||
|
margin: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.08);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user