| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // commonUtils.js
- const http = uni.$u.http
- import service from '../service'
- // 判断数据是否为空
- function isDataEmpty(data) {
- if (data === null || data === undefined) {
- return true;
- }
- if (typeof data === 'string' && data.trim() === '') {
- return true;
- }
- if (Array.isArray(data) && data.length === 0) {
- return true;
- }
- if (typeof data === 'object' && Object.keys(data).length === 0) {
- return true;
- }
- return false;
- }
- // 日期转换
- function formatDate(timestamp) {
- const date = new Date(timestamp);
- const year = date.getFullYear();
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
- const day = date.getDate().toString().padStart(2, '0');
- const hour = date.getHours().toString().padStart(2, '0');
- const minutes = date.getMinutes().toString().padStart(2, '0');
- const secoonds = date.getSeconds().toString().padStart(2, '0');
- return `${year}-${month}-${day} ${hour}:${minutes}:${secoonds}`;
- }
- // 日期转换
- function dateFormatYmd(dateStr) {
- const timestamp = new Date(dateStr).getTime();
- const date = new Date(timestamp);
- const year = date.getFullYear();
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
- const day = date.getDate().toString().padStart(2, '0');
- return `${year}-${month}-${day}`;
- }
- function getImgUrlByOssId(id) {
- return service.getImage(id).then(res => {
- res.data.data[0].url = res.data.data[0].url.replace(/^http:/, "https:")
- return res.data.data
- });
- }
- // 导出工具类方法
- export default {
- isDataEmpty,
- formatDate,
- dateFormatYmd,
- getImgUrlByOssId
- };
|