diff --git a/App.vue b/App.vue index 76348d7..dfe8bfe 100644 --- a/App.vue +++ b/App.vue @@ -13,7 +13,6 @@ export default { store.commit('setSupplierId', supplierId) } } else { - console.log('非分享进入', store.state.supplierId) if (!store.state.supplierId) { // go2('error') } diff --git a/apis/commonApi.js b/apis/commonApi.js index 7a5aa00..4615a63 100644 --- a/apis/commonApi.js +++ b/apis/commonApi.js @@ -1,4 +1,5 @@ import http from '../utils/http/index.js' +import store from '@/store/index' let areaCache = null /** * 获取省市区街道 @@ -21,6 +22,24 @@ export function getArea(data = {}) { }) } +// 处理store同步问题 +function syncStore(res) { + if (res.enterpriseList && res.enterpriseList.length > 0) { + let companyInfo = res.enterpriseList[0] + store.commit('setCompanyInfo', { + id: companyInfo.id, + name: companyInfo.name, + fddEnterpriseStatus: companyInfo.fddEnterpriseStatus + }) + store.commit('setUserInfo', { + name: companyInfo.employeeName, + userId: res.userId, + mobile: res.mobile, + avatar: null + }) + } +} + let baseInfo = null /** * 获取当前账号的基础信息 @@ -36,6 +55,7 @@ export function getBaseInfo(data = {}, refresh = false) { http.get({ url: '/yyt-uec/get/base-info', data }, { hideLoading: true }).then((res) => { if (res) { baseInfo = res + syncStore(res) resolve(res) } else { resolve(null) @@ -60,3 +80,11 @@ export function getVerifyUrl(data = {}) { export function getGuaranteeContract(data = {}) { return http.post({ url: '/yyt-uec/create/supplier/guarantee-contract?mallSupplierId=' + data.mallSupplierId, data }) } + +/** + * 获取当前账号企业的飞算额度 + * @param {object} data 参数 enterpriseId + */ +export function getFsCredit(data = {}) { + return http.get({ url: '/yyt-uec/credit/get/enterprise-feisuan-credit', data }) +} diff --git a/apis/orderApi.js b/apis/orderApi.js new file mode 100644 index 0000000..0b19b8d --- /dev/null +++ b/apis/orderApi.js @@ -0,0 +1,14 @@ +import http from '../utils/http/index.js' + +/** + * 获取客户订单列表 + * @param {object} data 获取验证码参数 + * @returns {Promise} + * swagger: http://api-ops-yyt-test.qniao.cn//base-paper-trading/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E5%8E%9F%E7%BA%B8%E8%AE%A2%E5%8D%95/getCustomerOrderListPageUsingGET + */ +export const getOrderList = (data) => { + return http.get({ + url: '/base-paper-trading/get/customer/order/list/page', + data + }) +} diff --git a/apis/testApi.js b/apis/testApi.js new file mode 100644 index 0000000..c23cd4f --- /dev/null +++ b/apis/testApi.js @@ -0,0 +1,40 @@ +import http from '../utils/http/index.js' + +/** + * 获取店铺纸品列表 + * @param {object} data 参数 + * @returns {Promise} + * swagger: http://api-ops-yyt-test.qniao.cn//base-paper-trading/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86/getStoreProductListForCustomerUsingGET + */ +export const getPaperList = (data = {}) => { + return http.get({ + url: '/base-paper-trading/get/store/product-list/for/customer', + data + }) +} + +/** + * 获取店铺纸品详情 + * @param {object} data 参数 + * @returns {Promise} + * swagger: http://api-ops-yyt-test.qniao.cn//base-paper-trading/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86/getProductDetailForCustomerUsingGET + */ +export const getPaperDetail = (data = {}) => { + return http.get({ + url: '/base-paper-trading/get/product-detail/for/customer', + data + }) +} + +/** + * 立即订购 + * @param {object} data 参数 + * @returns {Promise} + * swagger: http://api-ops-yyt-test.qniao.cn//base-paper-trading/swagger-ui/index.html?urls.primaryName=CustomerApi#/%E5%8E%9F%E7%BA%B8%E8%AE%A2%E5%8D%95/buyerPaperGoodsReserveUsingPOST + */ +export const purchasePaper = (data = {}) => { + return http.post({ + url: '/base-paper-trading/buyer/paper/goods/reserve', + data + }) +} diff --git a/components/scroll-list/scroll-list.vue b/components/scroll-list/scroll-list.vue index 40d82a4..261facc 100644 --- a/components/scroll-list/scroll-list.vue +++ b/components/scroll-list/scroll-list.vue @@ -580,7 +580,7 @@ export default { .scroll-content { height: 100%; display: flex; - will-change: transform; + // will-change: transform; flex-direction: column; .pull-down-wrap { left: 0; @@ -627,10 +627,11 @@ export default { margin: auto; display: flex; align-items: center; + margin-bottom: 400rpx; flex-direction: column; .empty-image { - width: 200rpx; - height: 200rpx; + width: 600rpx; + height: 600rpx; } .empty-text { color: #606266; diff --git a/enums/index.js b/enums/index.js index 790632f..1c06a7f 100644 --- a/enums/index.js +++ b/enums/index.js @@ -107,3 +107,87 @@ export const fsAuditStatus = { PASS: 2, REJECT: 3 } + +/** + * 客户订单状态 0: 全部 ; 30100: 待确认 ; 30204: 待供应商确认 ; 30101: 已下单 ; 30104: 已完成 ; 30105: 已取消 + */ +export const orderStatusEnum = { + ALL: 0, + WAIT_CONFIRM: 30100, + WAIT_SUPPLIER_CONFIRM: 30204, + ORDERED: 30101, + FINISHED: 30104, + CANCELED: 30105 +} + +/** + * 客户订单状态 0: 全部 ; 30100: 待确认 ; 30204: 待供应商确认 ; 30101: 已下单 ; 30104: 已完成 ; + */ +export const orderStatusArray = [ + { + value: orderStatusEnum.ALL, + label: '全部' + }, + { + value: orderStatusEnum.WAIT_CONFIRM, + label: '待确认' + }, + { + value: orderStatusEnum.WAIT_SUPPLIER_CONFIRM, + label: '待供应商确认' + }, + { + value: orderStatusEnum.ORDERED, + label: '已下单' + }, + { + value: orderStatusEnum.FINISHED, + label: '已完成' + }, + { + value: orderStatusEnum.CANCELED, + label: '已取消' + } +] + +export const orderStatusMap = { + [orderStatusEnum.ALL]: '全部', + [orderStatusEnum.WAIT_CONFIRM]: '待确认', + [orderStatusEnum.WAIT_SUPPLIER_CONFIRM]: '待供应商确认', + [orderStatusEnum.ORDERED]: '已下单', + [orderStatusEnum.FINISHED]: '已完成', + [orderStatusEnum.CANCELED]: '已取消' +} + +/** + * 供应商订单状态 待客户确认订单/30202,待供应商确认订单/30205,待发货/30106,已发货/30107 已发货在H5客户端显示 待收货/30107 ,待客户借款/30207,支付中/30208,待客户支付/30214,付款失败/30211,已完成/30213,待客户还款/30217,已取消/30212,还款中/30216 + */ +export const supplierOrderStatusEnum = { + WAIT_CLIENT_CONFIRM: 30202, + WAIT_SUPPLIER_CONFIRM: 30205, + WAIT_DELIVERY: 30106, + WAIT_RECEIVE: 30107, + WAIT_CLIENT_LOAN: 30207, + PAYING: 30208, + WAIT_CLIENT_PAY: 30214, + PAY_FAIL: 30211, + FINISHED: 30213, + WAIT_CLIENT_REPAY: 30217, + REPAYING: 30216, + CANCELED: 30212 +} + +export const supplierOrderStatusMap = { + [supplierOrderStatusEnum.WAIT_CLIENT_CONFIRM]: '待客户确认', + [supplierOrderStatusEnum.WAIT_SUPPLIER_CONFIRM]: '待供应商确认', + [supplierOrderStatusEnum.WAIT_DELIVERY]: '待发货', + [supplierOrderStatusEnum.WAIT_RECEIVE]: '待收货', + [supplierOrderStatusEnum.WAIT_CLIENT_LOAN]: '待客户借款', + [supplierOrderStatusEnum.PAYING]: '支付中', + [supplierOrderStatusEnum.WAIT_CLIENT_PAY]: '待客户支付', + [supplierOrderStatusEnum.PAY_FAIL]: '付款失败', + [supplierOrderStatusEnum.FINISHED]: '已完成', + [supplierOrderStatusEnum.WAIT_CLIENT_REPAY]: '待客户还款', + [supplierOrderStatusEnum.REPAYING]: '还款中', + [supplierOrderStatusEnum.CANCELED]: '已取消' +} diff --git a/manifest.json b/manifest.json index 9f55dcf..aabc002 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "name" : "uniapp-demo", - "appid" : "", + "name" : "纸掌柜", + "appid" : "__UNI__34A22DC", "description" : "", "versionName" : "1.0.0", "versionCode" : "100", @@ -85,7 +85,7 @@ "vueVersion" : "2", "h5" : { "router" : { - "mode" : "history" + "mode" : "hash" } } } diff --git a/pages.json b/pages.json index f5be82b..02fea01 100644 --- a/pages.json +++ b/pages.json @@ -51,6 +51,14 @@ "navigationStyle": "custom" } }, + { + "path": "pages/address-manage/index", + "style": { + "navigationBarTitleText": "收货地址", + "enablePullDownRefresh": false, + "navigationStyle": "custom" + } + }, { "path": "pages/error/index", "style": { @@ -66,6 +74,22 @@ "enablePullDownRefresh": false } } + { + "path": "pages/order-list/index", + "style": { + "navigationBarTitleText": "订单列表", + "enablePullDownRefresh": false, + "navigationStyle": "custom" + } + }, + { + "path": "pages/test/index", + "style": { + "navigationBarTitleText": "测试页面", + "enablePullDownRefresh": false, + "navigationStyle": "custom" + } + } ], "globalStyle": { "navigationBarTextStyle": "black", diff --git a/pages/address-manage/index.vue b/pages/address-manage/index.vue new file mode 100644 index 0000000..ffece6d --- /dev/null +++ b/pages/address-manage/index.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/pages/enterprise-info/index.vue b/pages/enterprise-info/index.vue index b6881ee..c47b603 100644 --- a/pages/enterprise-info/index.vue +++ b/pages/enterprise-info/index.vue @@ -1,6 +1,8 @@ @@ -310,7 +239,7 @@ export default { padding: 0 32rpx; display: flex; flex-direction: row; - align-items: flex-start; + align-items: center; justify-content: space-between; .user { z-index: 5; @@ -335,7 +264,7 @@ export default { align-items: center; justify-content: flex-start; .name { - font-size: 40rpx; + font-size: 38rpx; color: #fff; font-weight: 600; margin-right: 16rpx; @@ -349,106 +278,24 @@ export default { } } } - .operation { + .logout { z-index: 5; - margin-top: 18rpx; - margin-left: 20rpx; - flex-grow: 0; - flex-shrink: 0; - .box { - display: flex; - flex-direction: row; - align-items: center; - justify-content: flex-end; - margin-bottom: 36rpx; - .container { - width: 40rpx; - height: 40rpx; - flex-grow: 0; - flex-shrink: 0; - margin-right: 26rpx; - position: relative; - .number { - position: absolute; - top: -12rpx; - right: -12rpx; - // width:32rpx; - // height: 32rpx; - padding: 6rpx 10rpx; - background-color: #f5222d; - border-radius: 16rpx; - display: flex; - align-items: center; - justify-content: center; - .text { - font-size: 20rpx; - color: #fff; - font-weight: 500; - } - } - } - .icon { - width: 40rpx; - height: 40rpx; - flex-grow: 0; - flex-shrink: 0; - } - } - } - } - .vip-area { - z-index: 5; - position: absolute; - bottom: 0; - left: 0; - width: 686rpx; - height: 90rpx; - margin: 0 32rpx; - background-image: linear-gradient(90deg, #333333 0%, #696c6b 99%); - border-radius: 10rpx; - .vip-content { - width: 686rpx; - padding: 18rpx 24rpx 0; display: flex; flex-direction: row; align-items: center; - justify-content: space-between; - .left { - display: flex; - flex-direction: row; - align-items: center; - justify-content: flex-start; - .icon { - width: 28rpx; - height: 28rpx; - flex-grow: 0; - flex-shrink: 0; - } - .text { - font-size: 26rpx; - color: #dbc189; - font-weight: 500; - } - } - .center { + justify-content: flex-end; + flex-grow: 0; + flex-shrink: 0; + .text { font-size: 24rpx; - color: #e7e1be; - font-weight: 600; + color: #ffffff; } - .right { - position: relative; - display: flex; - flex-direction: row; - align-items: center; - justify-content: center; - width: 128rpx; - height: 44rpx; - border-radius: 14rpx; - background-image: linear-gradient(90deg, #f4edce 1%, #f3d99e 98%); - .text { - font-size: 24rpx; - color: #443015; - } + .icon { + margin-left: 8rpx; + width: 24rpx; + height: 24rpx; + flex-grow: 0; + flex-shrink: 0; } } } @@ -458,7 +305,7 @@ export default { margin: 20rpx 32rpx 0; background-color: #fff; box-shadow: 0 2rpx 14rpx 0 rgba(220, 220, 220, 0.5); - border-radius: 10px; + border-radius: 10rpx; .header { padding: 20rpx 24rpx 14rpx; border-bottom: 2rpx solid #f8f8f8; @@ -479,65 +326,82 @@ export default { font-size: 30rpx; color: rgba(0, 0, 0, 0.85); letter-spacing: 1.5rpx; - font-weight: 500; + font-weight: 600; } } } } + .order-area { - padding: 20rpx 20rpx 30rpx; + padding: 40rpx 32rpx; display: flex; flex-direction: row; align-items: center; justify-content: space-between; - .order-item { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - .value { - font-size: 36rpx; - color: rgba(0, 0, 0, 0.85); - font-weight: 500; - } - .label { - font-size: 26rpx; - color: #666666; - margin-top: 10rpx; - } - } + flex-wrap: nowrap; } .icon-area { padding: 40rpx 32rpx; display: flex; flex-direction: row; align-items: center; - justify-content: space-between; + justify-content: flex-start; flex-wrap: wrap; - .icon-item { - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - min-width: 140rpx; - margin-bottom: 36rpx; - .icon { - width: 68rpx; - height: 68rpx; - flex-grow: 0; - flex-shrink: 0; - } - .label { - font-size: 26rpx; - color: #666666; - margin-top: 10rpx; - } +} +.icon-item { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + margin-bottom: 36rpx; + .icon { + width: 68rpx; + height: 68rpx; + flex-grow: 0; + flex-shrink: 0; + } + .label { + font-size: 26rpx; + color: #666666; + margin-top: 10rpx; } } -.time-range { +.poster { + width: 686rpx; + height: 140rpx; +} +.fs-card { + width: 686rpx; + padding: 24rpx 32rpx 32rpx; display: flex; flex-direction: row; align-items: center; - justify-content: flex-end; + justify-content: space-between; + flex-wrap: nowrap; + .left { + display: flex; + flex-direction: column; + align-items: flex-start; + justify-content: flex-start; + .pre { + font-size: 36rpx; + color: rgba(0, 0, 0, 0.85); + font-weight: 500; + } + .next { + font-size: 56rpx; + color: rgba(0, 0, 0, 0.85); + font-weight: 700; + } + } + .right { + display: flex; + flex-direction: row; + align-items: center; + justify-content: flex-end; + font-size: 32rpx; + color: #333333; + font-weight: 500; + } } diff --git a/pages/order-list/index.vue b/pages/order-list/index.vue new file mode 100644 index 0000000..88b020c --- /dev/null +++ b/pages/order-list/index.vue @@ -0,0 +1,263 @@ + + + + + diff --git a/pages/test/index.vue b/pages/test/index.vue new file mode 100644 index 0000000..59556a1 --- /dev/null +++ b/pages/test/index.vue @@ -0,0 +1,55 @@ + + + + + diff --git a/static/imgs/mine/account-icon.png b/static/imgs/mine/account-icon.png new file mode 100644 index 0000000..07ebedc Binary files /dev/null and b/static/imgs/mine/account-icon.png differ diff --git a/static/imgs/mine/address-icon.png b/static/imgs/mine/address-icon.png new file mode 100644 index 0000000..0518249 Binary files /dev/null and b/static/imgs/mine/address-icon.png differ diff --git a/static/imgs/mine/contract-icon.png b/static/imgs/mine/contract-icon.png deleted file mode 100644 index 13dc629..0000000 Binary files a/static/imgs/mine/contract-icon.png and /dev/null differ diff --git a/static/imgs/mine/credit-icon.png b/static/imgs/mine/credit-icon.png deleted file mode 100644 index fa4b43c..0000000 Binary files a/static/imgs/mine/credit-icon.png and /dev/null differ diff --git a/static/imgs/mine/enquiry-icon.png b/static/imgs/mine/enquiry-icon.png new file mode 100644 index 0000000..3122815 Binary files /dev/null and b/static/imgs/mine/enquiry-icon.png differ diff --git a/static/imgs/mine/finance-icon.png b/static/imgs/mine/finance-icon.png deleted file mode 100644 index b26f8f1..0000000 Binary files a/static/imgs/mine/finance-icon.png and /dev/null differ diff --git a/static/imgs/mine/logout-icon.png b/static/imgs/mine/logout-icon.png new file mode 100644 index 0000000..e0914a9 Binary files /dev/null and b/static/imgs/mine/logout-icon.png differ diff --git a/static/imgs/mine/money-icon.png b/static/imgs/mine/money-icon.png deleted file mode 100644 index 8cc76fc..0000000 Binary files a/static/imgs/mine/money-icon.png and /dev/null differ diff --git a/static/imgs/mine/msg-icon.png b/static/imgs/mine/msg-icon.png deleted file mode 100644 index f06043c..0000000 Binary files a/static/imgs/mine/msg-icon.png and /dev/null differ diff --git a/static/imgs/mine/order-all-icon.png b/static/imgs/mine/order-all-icon.png new file mode 100644 index 0000000..16af855 Binary files /dev/null and b/static/imgs/mine/order-all-icon.png differ diff --git a/static/imgs/mine/order-done-icon.png b/static/imgs/mine/order-done-icon.png new file mode 100644 index 0000000..1964b7e Binary files /dev/null and b/static/imgs/mine/order-done-icon.png differ diff --git a/static/imgs/mine/order-icon.png b/static/imgs/mine/order-icon.png deleted file mode 100644 index 27b06a6..0000000 Binary files a/static/imgs/mine/order-icon.png and /dev/null differ diff --git a/static/imgs/mine/order-ing-icon.png b/static/imgs/mine/order-ing-icon.png new file mode 100644 index 0000000..da800cc Binary files /dev/null and b/static/imgs/mine/order-ing-icon.png differ diff --git a/static/imgs/mine/order-ready-icon.png b/static/imgs/mine/order-ready-icon.png new file mode 100644 index 0000000..7d56a86 Binary files /dev/null and b/static/imgs/mine/order-ready-icon.png differ diff --git a/static/imgs/mine/order-supplier-ready-icon.png b/static/imgs/mine/order-supplier-ready-icon.png new file mode 100644 index 0000000..8612ee1 Binary files /dev/null and b/static/imgs/mine/order-supplier-ready-icon.png differ diff --git a/static/imgs/mine/setting-icon.png b/static/imgs/mine/setting-icon.png deleted file mode 100644 index 20d3b34..0000000 Binary files a/static/imgs/mine/setting-icon.png and /dev/null differ diff --git a/static/imgs/mine/toggle-icon.png b/static/imgs/mine/toggle-icon.png deleted file mode 100644 index 7b943e4..0000000 Binary files a/static/imgs/mine/toggle-icon.png and /dev/null differ diff --git a/static/imgs/mine/vip-icon.png b/static/imgs/mine/vip-icon.png deleted file mode 100644 index 2917916..0000000 Binary files a/static/imgs/mine/vip-icon.png and /dev/null differ diff --git a/static/imgs/order/order-empty.png b/static/imgs/order/order-empty.png new file mode 100644 index 0000000..b47dbf9 Binary files /dev/null and b/static/imgs/order/order-empty.png differ diff --git a/static/imgs/order/paper-default-icon.png b/static/imgs/order/paper-default-icon.png new file mode 100644 index 0000000..4aece50 Binary files /dev/null and b/static/imgs/order/paper-default-icon.png differ diff --git a/store/index.js b/store/index.js index e93f135..bd0a7c2 100644 --- a/store/index.js +++ b/store/index.js @@ -19,7 +19,7 @@ let qnToken = null, uecToken = null, searchHistory = null, /** - * @value supplierId 当前被分析的供应商id + * @value supplierId 当前被分享的供应商id */ supplierId = null const companyInfoParams = ['id', 'name', 'fddEnterpriseStatus'] @@ -51,14 +51,29 @@ const store = new Vuex.Store({ qnToken: qnToken || '', // token supplierId: supplierId || '', // 供应商id userInfo: userInfo || {}, // 用户信息 - companyInfo: companyInfo || {}, // 纸盘商信息 + companyInfo: companyInfo || {}, // 印包厂信息 nextPage: { name: '', data: {} }, - searchHistory: searchHistory || [] + searchHistory: searchHistory || [], + /** + * 监听cache的type即可,每次取值后都必须调用commit('resetCache') + */ + cache: { + type: 'none', + data: null + } }, mutations: { + setCache(state, { type, data }) { + state.cache.type = type + state.cache.data = data + }, + resetCache(state) { + state.cache.type = 'none' + state.cache.data = null + }, setUecToken(state, token) { try { uni.setStorageSync('uecToken', token) diff --git a/utils/hook.js b/utils/hook.js index 88cc5ef..e30e19a 100644 --- a/utils/hook.js +++ b/utils/hook.js @@ -94,9 +94,10 @@ export function exit() { /** * 文件上传 * @param {array} sourceType 上传的方式 album:相册 camera:相机 - * @return {Promise} 以数组的形式返回对应的文件地址 + * @param {number} count 上传的数量 + * @return {Promise} 以数组的形式返回对应的文件地址 */ -export function uploadImage(sourceType = ['album', 'camera']) { +export function uploadImage(sourceType = ['album', 'camera'], count = 1) { return new Promise((resolve, reject) => { uni.chooseImage({ count: 1, @@ -104,24 +105,16 @@ export function uploadImage(sourceType = ['album', 'camera']) { sourceType: sourceType, success: (res) => { const tempFilePaths = res.tempFilePaths - uni.uploadFile({ - url: uploadUrl.image, - filePath: tempFilePaths[0], - name: 'image', - fileType: 'image', - success: (res) => { - let result = JSON.parse(res.data) - if (result.data) { - resolve(result.data) - } else { - reject(result.message) - } - }, - fail: (err) => { - console.error('uploadFile error:', err) - reject(err) - } + let cache = tempFilePaths.map((path) => { + return uploadFile(path, 'image') }) + Promise.all(cache) + .then((res) => { + resolve(res) + }) + .catch((err) => { + reject(err) + }) }, fail: (err) => { console.error('chooseImage error:', err) @@ -130,3 +123,59 @@ export function uploadImage(sourceType = ['album', 'camera']) { }) }) } + +/** + * 单文件上传 + * @param {string} path 文件路径 + * @param {string} type 文件类型 image | file,默认为image + * @returns {Promise} 返回单文件上传地址 + */ +export function uploadFile(path, type = 'image') { + return new Promise((resolve, reject) => { + uni.uploadFile({ + url: uploadUrl[type], + filePath: path, + name: type, + // fileType: type, + success: (res) => { + let result = JSON.parse(res.data) + if (result.data) { + resolve(result.data) + } else { + reject(result.message) + } + }, + fail: (err) => { + console.error('uploadFile error:', err) + reject(err) + } + }) + }) +} + +/** + * 根据类型获取缓存 + * @param {string} type 缓存类型 + * @returns 缓存数据 + */ +export function getCache(type) { + let data = null + if (store.state.cache.type === type) { + data = store.state.cache.data + // 防止同一事件循环的数据竞争 + setTimeout(() => { + store.commit('resetCache') + }) + } + return data +} + +/** + * 设置缓存 + * @param {string} type 缓存类型 + * @param {object} data 缓存数据 + * @returns null + */ +export function setCache(type, data) { + store.commit('setCache', { type, data }) +} diff --git a/utils/index.js b/utils/index.js index ad47f00..9b0d029 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1,12 +1,16 @@ import env from '@/env/index.js' import store from '@/store/index.js' +import { isDate } from './is.js' /** * 日期格式化,样例 yyyy-mm-dd hh:MM:ss * @param date Date 需要转换的日期 * @param fmt string 转化的格式 yyyy-mm-dd hh:MM:ss */ export const dateTimeFormat = (date, fmt) => { - if (!date) { + if (!isDate(date)) { + date = new Date(date) + } + if (!date || isNaN(date.getTime())) { throw new Error('日期不正确') } let ret diff --git a/utils/is.js b/utils/is.js index fa7bb45..ac04e98 100644 --- a/utils/is.js +++ b/utils/is.js @@ -15,3 +15,7 @@ export function isObject(val) { export function isArray(val) { return is(val, 'Array') } + +export function isDate(val) { + return is(val, 'Date') +}