import { createStore } from "vuex"; import api from "apis/fetch.js"; const store = createStore({ state: { isLogin: false, currentTabText: "运输安全管理中心", cargoOwnerInfo: { cargoOwnerName: "货主王", cargo: "石油焦", tons: "30000", shipRoute: "秦皇岛-上海", contractId: 1, data: [ { title: "货种", text: "煤炭", icon: "cargo", }, { title: "吨位", text: "30", unit: "吨", icon: "ship", }, { title: "航线", text: "秦皇岛-上海", icon: "hangxian", }, ], }, shipInfo: { shipOwnerName: "船东王", shipOwnerId: "898980000000000909", shipName: "航海家998", icon: "china", mmsi: "410999888", length: 100, width: 30, data: [ { title: "MMSI", text: "410998998", icon: "ship-fill", }, { title: "船长", text: "30", unit: "米", icon: "ship-length", }, { title: "船宽", text: "18", unit: "米", icon: "ship-width", }, ], }, damInfo: { data: [ { title: "上游前往三峡数量", text: "0", unit: "艘", icon: "ship-fill", }, { title: "三峡等闸船舶数量", text: "0", unit: "艘", icon: "dam", }, { title: "预计等待时间", text: "0", unit: "分", icon: "clock", }, ], }, capacity: { status: 0, shipOwner: "王船东", company: "船王公司", cargoOwner: "货主王", cargoStatus: 0, }, numbers: [], }, mutations: { changeLogin(state, b) { state.isLogin = b; }, changeTab(state, text) { state.currentTabText = text; }, setCargoOwner(state, info) { state.cargoOwnerInfo = info; }, setShipInfo(state, info) { state.shipInfo = info; }, setNumbers(state, numbers) { state.numbers = numbers; }, setDamInfo(state, nums) { state.damInfo.data[0].text = nums.upstreamShipNum; state.damInfo.data[1].text = nums.waitingShipNum; state.damInfo.data[2].text = nums.estimatedWaitingTime; }, }, actions: { Login({ commit }, userInfo) { return new Promise((resolve, reject) => { localStorage.setItem("id", 1); commit("changeLogin", true); resolve(1); }); }, LogOut({ commit }) { return new Promise((resolve, reject) => { commit("changeLogin", false); localStorage.removeItem("id"); resolve(0); }); }, GetSanxiaInfo({ commit }) { api.getSanxiaInfo().then((e) => { commit("setDamInfo", e.data.result); }); }, GetNumbers({ commit, state }, type) { return new Promise((resolve, reject) => { let arr1 = [ { icon: "loading", title: "装货中船舶数量", num: 22033 }, { icon: "transit", title: "运输中船舶数量", num: 12312 }, { icon: "unloading", title: "卸货中船舶数量", num: 87655 }, ]; let arr2 = [ { icon: "ship-fill-2", title: "装货中船舶数量", num: 16090 }, { icon: "ship-line", title: "运输中船舶数量", num: 20090 }, ]; resolve(type ? arr1 : arr2); }); }, }, }); export default store;