From 51c7896fd8e45085dd5cdfff11e79a00ee0a7379 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期五, 05 九月 2025 15:16:54 +0800 Subject: [PATCH] 上料/下料、报工/打印机配置/产线选择 、排产工单 --- store/index.js | 411 +++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 249 insertions(+), 162 deletions(-) diff --git a/store/index.js b/store/index.js index 22ff7ca..662a799 100644 --- a/store/index.js +++ b/store/index.js @@ -3,172 +3,259 @@ import api from "@/api/api" import MinCache from '@/common/util/MinCache.js' import { - ACCESS_TOKEN, - USER_NAME, - USER_INFO, - X_TENANT_ID + ACCESS_TOKEN, + USER_NAME, + USER_INFO, + X_TENANT_ID } from "@/common/util/constants" Vue.use(Vuex) export default new Vuex.Store({ - state: { - auth: [], - token: '', - userid: '', - username: '', - realname: '', - welcome: '', - avatar: '' - }, - mutations: { - SET_AUTH(state, auth) { - state.auth = auth - }, - SET_TOKEN: (state, token) => { - state.token = token - }, - SET_NAME: (state, { - username, - realname, - welcome - }) => { - state.username = username - state.realname = realname - state.welcome = welcome - }, - SET_AVATAR: (state, avatar) => { - state.avatar = avatar - } - }, - actions: { - // 鐧诲綍 - mLogin({ - commit - }, userInfo) { - return new Promise((resolve, reject) => { - api.login(userInfo).then(response => { - if (response.data.code == 200) { - const result = response.data.result - const userInfo = result.userInfo - uni.setStorageSync(ACCESS_TOKEN, result.token); - uni.setStorageSync("isLogin", true); - uni.setStorageSync("userId", userInfo.id); - uni.setStorageSync(USER_INFO, userInfo); - commit('SET_TOKEN', result.token) - commit('SET_AVATAR', userInfo.avatar) - commit('SET_NAME', { - username: userInfo.username, - realname: userInfo.realname - }) - resolve(response) - } else { - resolve(response) - } - }).catch(error => { - console.log("catch===>response", response) - reject(error) - }) - }) - }, - //鎵嬫満鍙风櫥褰� - PhoneLogin({ - commit - }, userInfo) { - return new Promise((resolve, reject) => { - api.phoneNoLogin(userInfo).then(response => { - if (response.data.code == 200) { - const result = response.data.result - const userInfo = result.userInfo - uni.setStorageSync(ACCESS_TOKEN, result.token); - uni.setStorageSync(USER_INFO, userInfo); - commit('SET_TOKEN', result.token) - commit('SET_NAME', { - username: userInfo.username, - realname: userInfo.realname - }) - commit('SET_AVATAR', userInfo.avatar) - resolve(response) - } else { - reject(response) - } - }).catch(error => { - reject(error) - }) - }) - }, - // 绗笁鏂圭櫥褰� - ThirdLogin({ - commit - }, param) { - return new Promise((resolve, reject) => { - api.thirdLogin(param.token, param.thirdType).then(response => { - if (response.data.code == '200') { - const result = response.data.result - const userInfo = result.userInfo - uni.setStorageSync(ACCESS_TOKEN, result.token); - uni.setStorageSync(USER_INFO, userInfo); - uni.setStorageSync("userId", userInfo.id); - uni.setStorageSync(X_TENANT_ID, userInfo.loginTenantId); + state: { + auth: [], + token: '', + userid: '', + username: '', + realname: '', + welcome: '', + avatar: '', + user: {}, // 琛ュ厖鐢ㄦ埛淇℃伅瀵硅薄 + tenantId: '', // 琛ュ厖绉熸埛ID + // 浜х嚎绠$悊鐩稿叧鐘舵�� + lineList: [], // 浜х嚎鍒楄〃 + currentLineId: uni.getStorageSync('currentLineId') || null, // 褰撳墠閫変腑鐨勪骇绾縄D + currentLineName: uni.getStorageSync('currentLineName') || '', // 褰撳墠閫変腑鐨勪骇绾垮悕绉� + currentLineInfo: null, // 褰撳墠閫変腑鐨勪骇绾胯缁嗕俊鎭� + currentLineType: uni.getStorageSync('currentLineType') || '' // 鏂板锛氬綋鍓嶉�変腑鐨勪骇绾跨被鍨� + }, + mutations: { + SET_AUTH(state, auth) { + state.auth = auth + }, + SET_TOKEN: (state, token) => { + state.token = token + }, + SET_NAME: (state, { + username, + realname, + welcome + }) => { + state.username = username + state.realname = realname + state.welcome = welcome + }, + SET_AVATAR: (state, avatar) => { + state.avatar = avatar + }, + SET_ID: (state, id) => { + state.userid = id + }, + SET_INFO: (state, userInfo) => { + state.user = userInfo + }, + SET_TENANTID: (state, tenantId) => { + state.tenantId = tenantId + }, + // 浜х嚎鐩稿叧mutations + SET_LINE_LIST(state, list) { + state.lineList = list + console.log('Vuex SET_LINE_LIST: 浜х嚎鍒楄〃宸叉洿鏂�', list); + }, + SET_CURRENT_LINE_ID(state, lineId) { + state.currentLineId = lineId + uni.setStorageSync('currentLineId', lineId) - commit('SET_TOKEN', result.token) - commit('SET_AVATAR', userInfo.avatar) - commit('SET_NAME', { - username: userInfo.username, - realname: userInfo.realname - }) - commit('SET_ID', userInfo.id) - commit('SET_INFO', userInfo) - commit('SET_TENANTID', userInfo.loginTenantId) - resolve(response) - } else { - reject(response) - } - }).catch(error => { - reject(error) - }) - }) - }, - // 鐧诲嚭 - Logout({ - commit, - state - }) { - return new Promise((resolve) => { - let logoutToken = state.token; - commit('SET_TOKEN', '') - uni.removeStorageSync(ACCESS_TOKEN) - api.logout(logoutToken).then(() => { - resolve() - }).catch(() => { - resolve() - }) - }) - }, - saveAuth({ - commit - }, auth) { - commit('SET_AUTH', auth) - } - }, - getters: { - getAuth: state => state.auth, - token: state => state.token, - username: state => { - state.userid = uni.getStorageSync(USER_INFO).username; - return state.username - }, - nickname: state => { - state.userid = uni.getStorageSync(USER_INFO).realname; - return state.user.realname - }, - avatar: state => { - state.userid = uni.getStorageSync(USER_INFO).avatar; - return state.user.avatar - }, - userid: state => { - state.userid = uni.getStorageSync(USER_INFO).id; - return state.userid - }, - } + // 鍚屾鏇存柊褰撳墠浜х嚎淇℃伅銆佸悕绉板拰绫诲瀷 + if (lineId && state.lineList.length > 0) { + state.currentLineInfo = state.lineList.find(line => line.id === lineId) || null + // 浠庝骇绾夸俊鎭腑鎻愬彇鍚嶇О骞朵繚瀛� + state.currentLineName = state.currentLineInfo ? state.currentLineInfo.name : '' + // 鏂板锛氫粠浜х嚎淇℃伅涓彁鍙栫被鍨嬪苟淇濆瓨 + state.currentLineType = state.currentLineInfo ? state.currentLineInfo.type : '' + + uni.setStorageSync('currentLineName', state.currentLineName) + // 鏂板锛氬皢绫诲瀷鍚屾淇濆瓨鍒版湰鍦板瓨鍌� + uni.setStorageSync('currentLineType', state.currentLineType) + } else { + state.currentLineInfo = null + state.currentLineName = '' + state.currentLineType = '' // 鏂板锛氭竻绌虹被鍨� + + uni.removeStorageSync('currentLineName') + uni.removeStorageSync('currentLineType') // 鏂板锛氭竻闄ゆ湰鍦板瓨鍌ㄧ殑绫诲瀷 + } + console.log('Vuex SET_CURRENT_LINE_ID: 褰撳墠浜х嚎ID宸叉洿鏂�', lineId); + console.log('Vuex SET_CURRENT_LINE_NAME: 褰撳墠浜х嚎鍚嶇О宸叉洿鏂�', state.currentLineName); + console.log('Vuex SET_CURRENT_LINE_TYPE: 褰撳墠浜х嚎绫诲瀷宸叉洿鏂�', state.currentLineType); // 鏂板锛氭墦鍗扮被鍨嬩俊鎭� + } + }, + actions: { + // 璐﹀彿鐧诲綍 + mLogin({ + commit + }, userInfo) { + return new Promise((resolve, reject) => { + api.login(userInfo).then(response => { + if (response.data.code == 200) { + const result = response.data.result + const userInfo = result.userInfo + uni.setStorageSync(ACCESS_TOKEN, result.token); + uni.setStorageSync("isLogin", true); + uni.setStorageSync("userId", userInfo.id); + uni.setStorageSync(USER_INFO, userInfo); + commit('SET_TOKEN', result.token) + commit('SET_AVATAR', userInfo.avatar) + commit('SET_NAME', { + username: userInfo.username, + realname: userInfo.realname + }) + commit('SET_ID', userInfo.id) + commit('SET_INFO', userInfo) + resolve(response) + } else { + resolve(response) + } + }).catch(error => { + console.log("鐧诲綍澶辫触:", error) + reject(error) + }) + }) + }, + // 鎵嬫満鍙风櫥褰� + PhoneLogin({ + commit + }, userInfo) { + return new Promise((resolve, reject) => { + api.phoneNoLogin(userInfo).then(response => { + if (response.data.code == 200) { + const result = response.data.result + const userInfo = result.userInfo + uni.setStorageSync(ACCESS_TOKEN, result.token); + uni.setStorageSync(USER_INFO, userInfo); + commit('SET_TOKEN', result.token) + commit('SET_NAME', { + username: userInfo.username, + realname: userInfo.realname + }) + commit('SET_AVATAR', userInfo.avatar) + commit('SET_ID', userInfo.id) + commit('SET_INFO', userInfo) + resolve(response) + } else { + reject(response) + } + }).catch(error => { + reject(error) + }) + }) + }, + // 绗笁鏂圭櫥褰� + ThirdLogin({ + commit + }, param) { + return new Promise((resolve, reject) => { + api.thirdLogin(param.token, param.thirdType).then(response => { + if (response.data.code == '200') { + const result = response.data.result + const userInfo = result.userInfo + uni.setStorageSync(ACCESS_TOKEN, result.token); + uni.setStorageSync(USER_INFO, userInfo); + uni.setStorageSync("userId", userInfo.id); + uni.setStorageSync(X_TENANT_ID, userInfo.loginTenantId); + + commit('SET_TOKEN', result.token) + commit('SET_AVATAR', userInfo.avatar) + commit('SET_NAME', { + username: userInfo.username, + realname: userInfo.realname + }) + commit('SET_ID', userInfo.id) + commit('SET_INFO', userInfo) + commit('SET_TENANTID', userInfo.loginTenantId) + resolve(response) + } else { + reject(response) + } + }).catch(error => { + reject(error) + }) + }) + }, + // 鐧诲嚭 + Logout({ + commit, + state + }) { + return new Promise((resolve) => { + let logoutToken = state.token; + commit('SET_TOKEN', '') + uni.removeStorageSync(ACCESS_TOKEN) + uni.removeStorageSync("isLogin") + uni.removeStorageSync("userId") + // 娓呴櫎浜х嚎閫夋嫨鐘舵�� + commit('SET_CURRENT_LINE_ID', null) + api.logout(logoutToken).then(() => { + resolve() + }).catch(() => { + resolve() + }) + }) + }, + saveAuth({ + commit + }, auth) { + commit('SET_AUTH', auth) + }, + + // 鑾峰彇浜х嚎鍒楄〃锛堝凡鍖呭惈type瀛楁锛� + fetchLineList({ commit, state }) { + return new Promise((resolve, reject) => { + api.getLineList({ + headers: { + 'Authorization': `Bearer ${state.token}` + } + }).then(response => { + console.log('fetchLineList鎺ュ彛杩斿洖鍘熷鏁版嵁:', response); + if (response.data.code === 200) { + const lineList = (response.data.result || []).map(line => ({ + id: line.value, + name: line.text, + type: line.type // 纭繚鏄犲皠type瀛楁 + })); + commit('SET_LINE_LIST', lineList); + resolve(lineList); + } else { + reject(new Error(`鑾峰彇浜х嚎鍒楄〃澶辫触: ${response.data.message || '鏈煡閿欒'}`)); + } + }).catch(error => { + console.error('鑾峰彇浜х嚎鍒楄〃鍑洪敊:', error); + reject(error); + }); + }); + }, + + // 璁剧疆褰撳墠浜х嚎锛堜繚鎸佷笉鍙橈紝绫诲瀷閫氳繃mutation鑷姩鍚屾锛� + setCurrentLine({ commit }, lineId) { + return new Promise((resolve) => { + commit('SET_CURRENT_LINE_ID', lineId) + resolve() + }) + } + }, + getters: { + getAuth: state => state.auth, + token: state => state.token, + username: state => state.username || uni.getStorageSync(USER_INFO)?.username || '', + nickname: state => state.realname || uni.getStorageSync(USER_INFO)?.realname || '', + avatar: state => state.avatar || uni.getStorageSync(USER_INFO)?.avatar || '', + userid: state => state.userid || uni.getStorageSync(USER_INFO)?.id || '', + // 浜х嚎鐩稿叧getters + lineList: state => state.lineList, + currentLineId: state => state.currentLineId, + currentLineName: state => state.currentLineName, + currentLineInfo: state => state.currentLineInfo, + currentLineType: state => state.currentLineType, // 鏂板锛氳幏鍙栧綋鍓嶄骇绾跨被鍨嬬殑getter + hasSelectedLine: state => !!state.currentLineId + } }) -- Gitblit v1.9.3