mirror of
https://github.com/Spythere/genera-tor.git
synced 2026-05-03 21:48:13 +00:00
refactor: updated order message component
This commit is contained in:
@@ -15,75 +15,6 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
methods: {
|
||||
saveOrderSetting(key: string, value: string | number | boolean) {
|
||||
window.localStorage.setItem(key, value.toString());
|
||||
},
|
||||
|
||||
getOrderSetting(key: string) {
|
||||
return window.localStorage.getItem(key);
|
||||
},
|
||||
|
||||
removeOrderSetting(key: string) {
|
||||
window.localStorage.removeItem(key);
|
||||
},
|
||||
|
||||
saveLocalOrder() {
|
||||
const orderObj: LocalStorageOrder = {
|
||||
id: '',
|
||||
orderType: this.store.chosenOrderType,
|
||||
orderBody: this.store[this.store.chosenOrderType],
|
||||
orderFooter: this.store.orderFooter,
|
||||
createdAt: Date.now(),
|
||||
orderVersion: import.meta.env['VITE_APP_ORDER_VERSION'] || '1'
|
||||
};
|
||||
|
||||
const headerInfo = orderObj['orderBody']['header'];
|
||||
|
||||
if (!headerInfo['orderNo']) return -1;
|
||||
if (!headerInfo['trainNo']) return -1;
|
||||
if (!headerInfo['date']) return -1;
|
||||
|
||||
const localStorage = window.localStorage;
|
||||
const localOrderCount = localStorage.getItem('orderCount') || '0';
|
||||
|
||||
if (localOrderCount == '0') localStorage.setItem('orderCount', '0');
|
||||
|
||||
const prevLocalOrder = localStorage.getItem(`order-${Number(localOrderCount)}`);
|
||||
if (prevLocalOrder && prevLocalOrder == JSON.stringify(orderObj)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const nextOrderCount = Number(localOrderCount) + 1;
|
||||
const orderId = `order-${nextOrderCount}`;
|
||||
orderObj['id'] = orderId;
|
||||
|
||||
localStorage.setItem('orderCount', `${nextOrderCount}`);
|
||||
localStorage.setItem(orderId, JSON.stringify(orderObj));
|
||||
|
||||
this.store.chosenLocalOrderId = orderId;
|
||||
return 1;
|
||||
},
|
||||
|
||||
updateLocalOrder() {
|
||||
if (!this.store.chosenLocalOrderId) return 0;
|
||||
const localOrder = window.localStorage.getItem(this.store.chosenLocalOrderId);
|
||||
|
||||
if (!localOrder) return -1;
|
||||
|
||||
const orderObj: LocalStorageOrder = {
|
||||
id: this.store.chosenLocalOrderId,
|
||||
orderType: this.store.chosenOrderType,
|
||||
orderBody: this.store[this.store.chosenOrderType],
|
||||
orderFooter: this.store.orderFooter,
|
||||
updatedAt: Date.now(),
|
||||
orderVersion: import.meta.env['VITE_APP_ORDER_VERSION'] || '1'
|
||||
};
|
||||
|
||||
window.localStorage.setItem(this.store.chosenLocalOrderId, JSON.stringify(orderObj));
|
||||
|
||||
return 1;
|
||||
},
|
||||
|
||||
removeLocalOrder(order: LocalStorageOrder) {
|
||||
localStorage.removeItem(order.id);
|
||||
|
||||
@@ -157,7 +88,7 @@ export default defineComponent({
|
||||
|
||||
this.store.chosenOrderType = localOrder.orderType;
|
||||
this.store.chosenLocalOrderId = localOrder.id;
|
||||
this.store.orderMode = 'OrderMessage';
|
||||
this.store.panelMode = 'OrderMessage';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user