管理后台前端搭建
This commit is contained in:
		| @@ -8,9 +8,11 @@ const getters = { | ||||
|   avatar: state => state.user.avatar, | ||||
|   name: state => state.user.name, | ||||
|   introduction: state => state.user.introduction, | ||||
|   roles: state => state.user.roles, | ||||
|   // roles: state => state.user.roles, | ||||
|   roles: state => ["dietician"], | ||||
|   permissions: state => state.user.permissions, | ||||
|   userId: state => state.user.userId, | ||||
|   // userId: state => state.user.userId, | ||||
|   userId: state => 131, | ||||
|   userRemark: state => state.user.remark, | ||||
|   permission_routes: state => state.permission.routes, | ||||
|   // | ||||
|   | ||||
| @@ -6,11 +6,15 @@ import { | ||||
| } from "@/api/custom/message"; | ||||
|  | ||||
| const oriState = { | ||||
|   topicList: undefined, | ||||
|   detailData: undefined | ||||
|   topicList: [], | ||||
|   detailData: {}, | ||||
|   selTopicId: "" | ||||
| }; | ||||
|  | ||||
| const mutations = { | ||||
|   updateSelTopicId(state, payload) { | ||||
|     state.selTopicId = payload.selTopicId; | ||||
|   }, | ||||
|   save(state, payload) { | ||||
|     Object.keys(payload).forEach(key => { | ||||
|       state[key] = payload[key]; | ||||
| @@ -24,13 +28,59 @@ const mutations = { | ||||
| }; | ||||
|  | ||||
| const actions = { | ||||
|   async init({ rootGetters, commit }, payload) { | ||||
|   async init({ rootGetters, commit, dispatch }, payload) { | ||||
|     const { | ||||
|       roles: [role], | ||||
|       userId | ||||
|     } = rootGetters; | ||||
|     const result = await fetchTopicList({ role: "dietician", uid: 131 }); | ||||
|     console.log({ result }); | ||||
|     const result = await fetchTopicList({ role, uid: userId }); | ||||
|     if (result.code === 200) { | ||||
|       const [defTopic] = result.rows; | ||||
|  | ||||
|       dispatch("fetchTopicDetailActions", { | ||||
|         topicId: defTopic.topicId, | ||||
|         id: defTopic.id | ||||
|       }); | ||||
|  | ||||
|       commit("save", { | ||||
|         topicList: result.rows | ||||
|       }); | ||||
|     } | ||||
|   }, | ||||
|   async fetchTopicDetailActions({ commit }, payload) { | ||||
|     const { topicId, id } = payload; | ||||
|     commit("save", { selTopicId: topicId }); | ||||
|     const result = await fetchTopicDetail({ topicId, id }); | ||||
|     if (result.code === 200) { | ||||
|       commit("save", { detailData: result.data[0] }); | ||||
|     } | ||||
|   }, | ||||
|   async postTopicReplyActions( | ||||
|     { commit, rootGetters, dispatch, state }, | ||||
|     payload | ||||
|   ) { | ||||
|     const { | ||||
|       roles: [role], | ||||
|       userId | ||||
|     } = rootGetters; | ||||
|     const { detailData, topicList } = state; | ||||
|     const params = { ...payload, fromRole: role, fromUid: userId }; | ||||
|  | ||||
|     const result = payload.commentId | ||||
|       ? await postTopicReply(params) | ||||
|       : await postTopicComment(params); | ||||
|     if (result.code === 200) { | ||||
|       const tarTopic = topicList.find( | ||||
|         obj => obj.topicId === detailData.topicId | ||||
|       ); | ||||
|       if (tarTopic) { | ||||
|         dispatch("fetchTopicDetailActions", { | ||||
|           topicId: tarTopic.topicId, | ||||
|           id: tarTopic.id | ||||
|         }); | ||||
|       } | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user