优化vuex mutations

This commit is contained in:
kuaifan 2021-06-06 14:00:59 +08:00
parent 1f08c596a4
commit c8f88dc3ee
7 changed files with 28 additions and 37 deletions

View File

@ -113,8 +113,6 @@
</style> </style>
<script> <script>
import {mapMutations} from "vuex";
export default { export default {
data() { data() {
return { return {
@ -129,9 +127,6 @@ export default {
code: '', code: '',
} }
}, },
computed: {
...mapMutations(['setUserInfo']),
},
methods: { methods: {
reCode() { reCode() {
this.codeUrl = $A.apiUrl('users/login/codeimg?_=' + Math.random()) this.codeUrl = $A.apiUrl('users/login/codeimg?_=' + Math.random())
@ -167,8 +162,9 @@ export default {
} }
this.loadIng++; this.loadIng++;
$A.ajaxc({ $A.ajaxc({
url: $A.apiUrl('users/login?type=' + this.loginType), url: $A.apiUrl('users/login'),
data: { data: {
type: this.loginType,
email: this.email, email: this.email,
password: this.password, password: this.password,
code: this.code, code: this.code,
@ -178,7 +174,7 @@ export default {
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
this.setUserInfo(data); this.$store.commit('setUserInfo', data);
// //
this.goNext(); this.goNext();
} else { } else {

View File

@ -231,7 +231,7 @@
</style> </style>
<script> <script>
import {mapMutations, mapState} from 'vuex' import { mapState } from 'vuex'
export default { export default {
data() { data() {
@ -252,14 +252,13 @@ export default {
} }
}, },
mounted() { mounted() {
this.$store.commit("getUserInfo"); this.$store.commit('getUserInfo');
}, },
deactivated() { deactivated() {
this.addShow = false; this.addShow = false;
}, },
computed: { computed: {
...mapState(['projectList']), ...mapState(['projectList']),
...mapMutations(['getProjectList']),
}, },
watch: { watch: {
'$route' (route) { '$route' (route) {
@ -353,7 +352,7 @@ export default {
this.$set(this.addData, 'template', 0); this.$set(this.addData, 'template', 0);
// //
this.loadIng++; this.loadIng++;
this.getProjectList(() => { this.$store.commit('getProjectList', () => {
this.loadIng--; this.loadIng--;
}); });
} else { } else {

View File

@ -43,7 +43,7 @@
<script> <script>
import DragInput from "../../../components/DragInput"; import DragInput from "../../../components/DragInput";
import ScrollerY from "../../../components/ScrollerY"; import ScrollerY from "../../../components/ScrollerY";
import {mapMutations, mapState} from "vuex"; import {mapState} from "vuex";
import DialogView from "./DialogView"; import DialogView from "./DialogView";
import DialogUpload from "./DialogUpload"; import DialogUpload from "./DialogUpload";
@ -67,7 +67,6 @@ export default {
computed: { computed: {
...mapState(['userId', 'dialogId', 'dialogDetail', 'dialogMsgLoad', 'dialogMsgList']), ...mapState(['userId', 'dialogId', 'dialogDetail', 'dialogMsgLoad', 'dialogMsgList']),
...mapMutations(["spliceDialogMsg"]),
peopleNum() { peopleNum() {
return this.dialogDetail.type === 'group' ? $A.runNum(this.dialogDetail.people) : 0; return this.dialogDetail.type === 'group' ? $A.runNum(this.dialogDetail.people) : 0;
@ -108,7 +107,7 @@ export default {
text: this.msgText, text: this.msgText,
}, },
error:() => { error:() => {
this.spliceDialogMsg({id: tempId}); this.$store.commit('spliceDialogMsg', {id: tempId});
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret !== 1) { if (ret !== 1) {
@ -117,7 +116,7 @@ export default {
content: msg content: msg
}); });
} }
this.spliceDialogMsg({ this.$store.commit('spliceDialogMsg', {
id: tempId, id: tempId,
data: ret === 1 ? data : null data: ret === 1 ? data : null
}); });
@ -185,11 +184,11 @@ export default {
break; break;
case 'error': case 'error':
this.spliceDialogMsg({id: file.tempId}); this.$store.commit('spliceDialogMsg', {id: file.tempId});
break; break;
case 'success': case 'success':
this.spliceDialogMsg({id: file.tempId, data: file.data}); this.$store.commit('spliceDialogMsg', {id: file.tempId, data: file.data});
break; break;
} }
}, },

View File

@ -828,7 +828,7 @@
<script> <script>
import TaskPriority from "./TaskPriority"; import TaskPriority from "./TaskPriority";
import TaskAdd from "./TaskAdd"; import TaskAdd from "./TaskAdd";
import {mapState, mapMutations} from "vuex"; import {mapState} from "vuex";
import UserInput from "../../../components/UserInput"; import UserInput from "../../../components/UserInput";
export default { export default {
name: "ProjectList", name: "ProjectList",
@ -880,7 +880,6 @@ export default {
'taskUndoneShow', 'taskUndoneShow',
'taskCompletedShow' 'taskCompletedShow'
]), ]),
...mapMutations(['toggleBoolean', 'getProjectList', 'getProjectDetail']),
panelTask() { panelTask() {
const {searchText} = this; const {searchText} = this;
@ -984,7 +983,7 @@ export default {
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.getProjectDetail(this.addData.project_id); this.$store.commit('getProjectDetail', this.addData.project_id);
this.addShow = false; this.addShow = false;
this.addData = { this.addData = {
owner: 0, owner: 0,
@ -1037,7 +1036,7 @@ export default {
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.getProjectDetail(this.userData.project_id); this.$store.commit('getProjectDetail', this.userData.project_id);
this.userShow = false; this.userShow = false;
} else { } else {
$A.modalError(msg); $A.modalError(msg);
@ -1060,7 +1059,7 @@ export default {
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.getProjectDetail(this.transferData.project_id); this.$store.commit('getProjectDetail', this.transferData.project_id);
this.transferShow = false; this.transferShow = false;
} else { } else {
$A.modalError(msg); $A.modalError(msg);
@ -1088,7 +1087,7 @@ export default {
this.$Modal.remove(); this.$Modal.remove();
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.getProjectList(); this.$store.commit('getProjectList');
this.goForward({path: '/manage/dashboard'}, true); this.goForward({path: '/manage/dashboard'}, true);
}else{ }else{
$A.modalError(msg, 301); $A.modalError(msg, 301);
@ -1118,7 +1117,7 @@ export default {
this.$Modal.remove(); this.$Modal.remove();
if (ret === 1) { if (ret === 1) {
$A.messageSuccess(msg); $A.messageSuccess(msg);
this.getProjectList(); this.$store.commit('getProjectList');
this.goForward({path: '/manage/dashboard'}, true); this.goForward({path: '/manage/dashboard'}, true);
}else{ }else{
$A.modalError(msg, 301); $A.modalError(msg, 301);
@ -1161,6 +1160,10 @@ export default {
} }
}, },
toggleBoolean(type) {
this.$store.commit('toggleBoolean', type);
},
formatTime(date) { formatTime(date) {
let time = Math.round(new Date(date).getTime() / 1000), let time = Math.round(new Date(date).getTime() / 1000),
string = ''; string = '';

View File

@ -19,8 +19,6 @@
</template> </template>
<script> <script>
import {mapMutations} from "vuex";
export default { export default {
data() { data() {
return { return {
@ -35,9 +33,6 @@ export default {
ruleDatum: { }, ruleDatum: { },
} }
}, },
computed: {
...mapMutations(['setUserInfo']),
},
methods: { methods: {
initLanguage() { initLanguage() {
this.ruleDatum = { this.ruleDatum = {
@ -93,7 +88,7 @@ export default {
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess('修改成功!'); $A.messageSuccess('修改成功!');
this.setUserInfo(data); this.$store.commit('setUserInfo', data);
this.$refs.formDatum.resetFields(); this.$refs.formDatum.resetFields();
} else { } else {
$A.modalError(msg); $A.modalError(msg);

View File

@ -24,7 +24,7 @@
<script> <script>
import ImgUpload from "../../../components/ImgUpload"; import ImgUpload from "../../../components/ImgUpload";
import {mapMutations, mapState} from "vuex"; import {mapState} from "vuex";
export default { export default {
components: {ImgUpload}, components: {ImgUpload},
data() { data() {
@ -45,7 +45,6 @@ export default {
}, },
computed: { computed: {
...mapState(['userInfo']), ...mapState(['userInfo']),
...mapMutations(['getUserInfo']),
}, },
watch: { watch: {
userInfo() { userInfo() {
@ -82,7 +81,7 @@ export default {
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
$A.messageSuccess('修改成功'); $A.messageSuccess('修改成功');
this.getUserInfo(); this.$store.commit('getUserInfo');
} else { } else {
$A.modalError(msg); $A.modalError(msg);
} }

View File

@ -152,7 +152,7 @@ export default {
/** /**
* 获取用户基本信息 * 获取用户基本信息
* @param state * @param state
* @param params // {userid, success, complete} * @param params {userid, success, complete}
*/ */
getUserBasic(state, params) { getUserBasic(state, params) {
if (!state.method.isJson(params)) { if (!state.method.isJson(params)) {
@ -274,7 +274,7 @@ export default {
/** /**
* 根据消息ID 删除 替换 对话数据 * 根据消息ID 删除 替换 对话数据
* @param state * @param state
* @param params // {id, data} * @param params {id, data}
*/ */
spliceDialogMsg(state, params) { spliceDialogMsg(state, params) {
let {id, data} = params; let {id, data} = params;
@ -388,7 +388,7 @@ export default {
/** /**
* 发送 websocket 消息 * 发送 websocket 消息
* @param state * @param state
* @param params // {type, data, callback, msgId} * @param params {type, data, callback, msgId}
*/ */
wsSend(state, params) { wsSend(state, params) {
if (!state.method.isJson(params)) { if (!state.method.isJson(params)) {
@ -418,7 +418,7 @@ export default {
/** /**
* 监听消息 * 监听消息
* @param state * @param state
* @param params // {name, callback} * @param params {name, callback}
*/ */
wsMsgListener(state, params) { wsMsgListener(state, params) {
const {name, callback} = params; const {name, callback} = params;