Browse Source

重构store

master
陈裕财 3 years ago
parent
commit
97c7919945
  1. 7
      src/store/getters.js
  2. 10
      src/store/index.js
  3. 29
      src/store/modules/projectInfo.js
  4. 95
      src/store/modules/xm.js
  5. 29
      src/store/modules/xmIteration.js
  6. 29
      src/store/modules/xmProduct.js
  7. 69
      src/views/xm/core/xmTestCasedb/index.vue
  8. 194
      src/views/xm/core/xmTestCasedb/top-nav.vue

7
src/store/getters.js

@ -21,8 +21,9 @@ const getters = {
added: state => state.permission.added,
isLoadOk:state=>state.user.isLoadOk,
noticeMsg:state=>state.noticeMsg.noticeMsg,
projectInfo:state=>state.projectInfo.projectInfo,
xmProduct:state=>state.xmProduct.xmProduct,
xmIteration:state=>state.xmIteration.xmIteration,
projectInfo:state=>state.xm.projectInfo,
xmProduct:state=>state.xm.xmProduct,
xmIteration:state=>state.xm.xmIteration,
testCasedb:state=>state.xm.testCasedb,
}
export default getters

10
src/store/index.js

@ -5,10 +5,8 @@ import errorLog from './modules/errorLog'
import permission from './modules/permission'
import tagsView from './modules/tagsView'
import user from './modules/user'
import noticeMsg from './modules/noticeMsg'
import projectInfo from './modules/projectInfo'
import xmProduct from './modules/xmProduct'
import xmIteration from './modules/xmIteration'
import noticeMsg from './modules/noticeMsg'
import xm from './modules/xm'
import getters from './getters'
@ -22,9 +20,7 @@ const store = new Vuex.Store({
tagsView,
user,
noticeMsg,
projectInfo,
xmProduct,
xmIteration,
xm,
},
getters
})

29
src/store/modules/projectInfo.js

@ -1,29 +0,0 @@
var key='xm-project-info';
const projectInfo = {
state: {
projectInfo: null,
},
mutations: {
SET_PROJECT_INFO: (state, projectInfo) => {
state.projectInfo=projectInfo
if(projectInfo && projectInfo!='null' && projectInfo!='undefined' ){
sessionStorage.setItem(key,JSON.stringify(projectInfo))
}else{
sessionStorage.removeItem(key)
}
}
},
actions: {
setProjectInfo({ commit }, projectInfo) {
commit('SET_PROJECT_INFO', projectInfo)
}
}
}
var projectStr=sessionStorage.getItem(key)
if(projectStr && projectStr!='null' && projectStr!='undefined' ){
projectInfo.state.projectInfo=JSON.parse(projectStr)
}
export default projectInfo

95
src/store/modules/xm.js

@ -0,0 +1,95 @@
var iterationKey='xm-iteration-store';
var productKey='xm-product-store';
var projectKey='xm-project-info-store';
var testCasedbKey='xm-test-casedb-store';
const xm = {
state: {
xmIteration: null,
xmProduct:null,
projectInfo:null,
testCasedb:null,
},
mutations: {
SET_XM_ITERATION: (state, xmIteration) => {
state.xmIteration=xmIteration
if(xmIteration && xmIteration!='null' && xmIteration!='undefined' ){
sessionStorage.setItem(iterationKey,JSON.stringify(xmIteration))
}else{
sessionStorage.removeItem(iterationKey)
}
},
SET_XM_PRODUCT: (state, xmProduct) => {
state.xmProduct=xmProduct
if(xmProduct && xmProduct!='null' && xmProduct!='undefined' ){
sessionStorage.setItem(productKey,JSON.stringify(xmProduct))
}else{
sessionStorage.removeItem(productKey)
}
},
SET_PROJECT_INFO: (state, projectInfo) => {
state.projectInfo=projectInfo
if(projectInfo && projectInfo!='null' && projectInfo!='undefined' ){
sessionStorage.setItem(projectKey,JSON.stringify(projectInfo))
}else{
sessionStorage.removeItem(projectKey)
}
},
SET_TEST_CASEDB: (state, testCasedb) => {
state.testCasedb=testCasedb
if(testCasedb && testCasedb!='null' && testCasedb!='undefined' ){
sessionStorage.setItem(testCasedbKey,JSON.stringify(testCasedb))
}else{
sessionStorage.removeItem(testCasedbKey)
}
},
},
actions: {
setXmIteration({ commit }, xmIteration) {
commit('SET_XM_ITERATION', xmIteration)
},
setXmProduct({ commit }, xmProduct) {
commit('SET_XM_PRODUCT', xmProduct)
},
setProjectInfo({ commit }, projectInfo) {
commit('SET_PROJECT_INFO', projectInfo)
},
setTestCasedb({ commit }, testCasedb) {
commit('SET_TEST_CASEDB', testCasedb)
}
}
}
var iterationStr=sessionStorage.getItem(iterationKey)
if(iterationStr && iterationStr!='null' && iterationStr!='undefined' ){
xm.state.xmIteration=JSON.parse(iterationStr)
}
var xmProductStr=sessionStorage.getItem(productKey)
if(xmProductStr && xmProductStr!='null' && xmProductStr!='undefined' ){
xm.state.xmProduct=JSON.parse(xmProductStr)
}
var projectStr=sessionStorage.getItem(projectKey)
if(projectStr && projectStr!='null' && projectStr!='undefined' ){
xm.state.projectInfo=JSON.parse(projectStr)
}
var testCasedbStr=sessionStorage.getItem(testCasedbKey)
if(testCasedbStr && testCasedbStr!='null' && testCasedbStr!='undefined' ){
xm.state.testCasedb=JSON.parse(testCasedbStr)
}
export default xm

29
src/store/modules/xmIteration.js

@ -1,29 +0,0 @@
var key='xm-iteration';
const xmIteration = {
state: {
xmIteration: null,
},
mutations: {
SET_XM_ITERATION: (state, xmIteration) => {
state.xmIteration=xmIteration
if(xmIteration && xmIteration!='null' && xmIteration!='undefined' ){
sessionStorage.setItem(key,JSON.stringify(xmIteration))
}else{
sessionStorage.removeItem(key)
}
}
},
actions: {
setXmIteration({ commit }, xmIteration) {
commit('SET_XM_ITERATION', xmIteration)
}
}
}
var iterationStr=sessionStorage.getItem(key)
if(iterationStr && iterationStr!='null' && iterationStr!='undefined' ){
xmIteration.state.xmIteration=JSON.parse(iterationStr)
}
export default xmIteration

29
src/store/modules/xmProduct.js

@ -1,29 +0,0 @@
var key='xm-product';
const xmProduct = {
state: {
xmProduct: null,
},
mutations: {
SET_XM_PRODUCT: (state, xmProduct) => {
state.xmProduct=xmProduct
if(xmProduct && xmProduct!='null' && xmProduct!='undefined' ){
sessionStorage.setItem(key,JSON.stringify(xmProduct))
}else{
sessionStorage.removeItem(key)
}
}
},
actions: {
setXmProduct({ commit }, xmProduct) {
commit('SET_XM_PRODUCT', xmProduct)
}
}
}
var xmProductStr=sessionStorage.getItem(key)
if(xmProductStr && xmProductStr!='null' && xmProductStr!='undefined' ){
xmProduct.state.xmProduct=JSON.parse(xmProductStr)
}
export default xmProduct

69
src/views/xm/core/xmTestCasedb/index.vue

@ -0,0 +1,69 @@
<template>
<section>
<top-nav v-if="testCasedb&&testCasedb.id"/>
<keep-alive><router-view v-if="testCasedb && testCasedb.id"></router-view></keep-alive>
</section>
</template>
<script>
import util from "@/common/js/util"; //
//import Sticky from '@/components/Sticky' // header
//import { initSimpleDicts } from '@/api/mdp/meta/item';//
import { mapGetters } from "vuex";
import topNav from './top-nav.vue'
import store from '@/store'
import { listXmTestCasedb } from '@/api/xm/core/xmTestCasedb';
export default {
computed: {
...mapGetters(["userInfo", "roles","testCasedb"]),
},
watch: {},
data() {
return {
};
}, //end data
methods: {
}, //end methods
components: {
topNav
//
},
mounted() {
if(!this.$route.query.casedbId){
this.$message.error("地址不合规")
this.$route.back(-1)
}
if(!this.testCasedb||this.testCasedb.id!=this.$route.query.casedbId){
listXmTestCasedb({id:this.$route.query.casedbId}).then(res=>{
var tips = res.data.tips;
if(tips.isOk ){
if( res.data.data.length==1){
store.dispatch('setTestCasedb',res.data.data[0])
}else{
this.$message.error("测试用例库不存在,请确保测试用例库编号正确")
this.$router.push({
path:'/xm/core/xmTestCasedb/XmTestCasedbMng'
})
}
}else{
this.$message.error(tips.msg)
this.$router.push({
path:'/xm/core/xmTestCasedb/XmTestCasedbMng'
})
}
})
}
},
beforeDestroy(){
store.dispatch('setTestCasedb',null)
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>

194
src/views/xm/core/xmTestCasedb/top-nav.vue

@ -0,0 +1,194 @@
<template>
<section>
<el-row>
<el-menu
:default-active="infotype"
mode="horizontal"
@select="setInfotype"
class="menus"
background-color="rgb(48, 65, 86)"
text-color="rgb(191, 203, 217)"
active-text-color="#409eff"
:router="true"
>
<el-menu-item :index="'/xm/core/test/overview?casedbId='+testCasedb.id">
<span
slot="title"
style="font-size: 18px; color: #409eff"
class="hidden-md-and-down"
:title="testCasedb.name"
>
<font v-if="testCasedb.name.length >= 15">
<strong>
&nbsp;<el-avatar class="top-icon" icon="el-icon-s-opportunity" style="background-color:#409EFF"></el-avatar>&nbsp;{{ testCasedb.name.substring(0, 15) }}</strong
></font
>
<div v-else>
<font type="danger">
<strong>&nbsp; <el-avatar class="top-icon" icon="el-icon-s-opportunity" style="background-color:#409EFF"></el-avatar>&nbsp;:&nbsp;{{ testCasedb.name }}</strong></font
>
</div>
</span>
<span
slot="title"
style="color: #409eff"
class="hidden-lg-and-up"
:title="testCasedb.name"
>
<font v-if="testCasedb.name.length >= 15">
&nbsp;<el-avatar class="top-icon" icon="el-icon-s-opportunity" style="background-color:#409EFF"></el-avatar>&nbsp;:&nbsp;{{ testCasedb.name.substring(0, 15) }}</font
>
<font type="danger" v-else>
&nbsp;<el-avatar class="top-icon" icon="el-icon-s-opportunity" style="background-color:#409EFF"></el-avatar>&nbsp;:&nbsp;{{ testCasedb.name }}</font
>
</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/project?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-odometer"></i>项目</span>
</el-menu-item>
<el-menu-item label="需求" :index="'/xm/core/product/menu?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-document"></i>需求</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/iteration?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-connection"></i>迭代</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/plan?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-time"></i>计划</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/task?productId='+testCasedb.id" class="hidden-md-and-down">
<span slot="title"><i class="el-icon-s-operation"></i>任务</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/question?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-question"></i>缺陷</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/group?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-user-solid"></i>团队</span>
</el-menu-item>
<el-submenu index="caiwu" class="hidden-sm-and-down">
<template slot="title"><i class="el-icon-coin"></i>财务</template>
<el-menu-item :index="'/xm/core/product/contract?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-s-data"></i>合同管理</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/budget?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-coin"></i>预算</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/cost?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-coin"></i>费用</span>
</el-menu-item>
</el-submenu>
<el-menu-item :index="'/xm/core/product/report?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-s-data"></i>效能</span>
</el-menu-item>
<el-submenu index="zhishi" class="hidden-md-and-down">
<template slot="title">知识</template>
<el-menu-item :index="'/xm/core/product/file?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-document"></i>文档</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/env?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-setting"></i>环境清单</span>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/record?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-edit-outline"></i>日志</span>
</el-menu-item>
</el-submenu>
<el-submenu index="更多">
<template slot="title">更多 </template>
<el-menu-item :index="'/xm/core/product/workloadDay?productId='+testCasedb.id">
<span slot="title"
><i class="el-icon-video-camera"></i>每日工时</span
>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/workloadMonth?productId='+testCasedb.id">
<span slot="title"
><i class="el-icon-video-camera"></i>每月工时</span
>
</el-menu-item>
<el-menu-item :index="'/xm/core/product/env?productId='+testCasedb.id">
<span slot="title"><i class="el-icon-setting"></i>环境清单</span>
</el-menu-item>
<el-menu-item index="/forum">
<span slot="title"><i class="el-icon-date"></i>论坛</span>
</el-menu-item>
<el-menu-item index="/im">
<span slot="title"><i class="el-icon-date"></i>即聊</span>
</el-menu-item>
<el-menu-item index="/helpCenter">
<span slot="title"><i class="el-icon-date"></i>客服</span>
</el-menu-item>
<el-menu-item index="/xm/core/testCasedb/XmProductMng" >
<span slot="title"
><i class="el-icon-back"></i>回到产品列表页</span
>
</el-menu-item>
<el-menu-item index="/">
<span slot="title"
><i class="el-icon-s-home"></i>首页</span
>
</el-menu-item>
</el-submenu>
</el-menu>
</el-row>
</section>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
props: ["visible"],
computed: {
...mapGetters(["userInfo", "roles","testCasedb"]),
},
watch: {
$route:{
handler(newVal,oldValu){
this.infotype=newVal.fullPath
},
deep:true,
immediate:true,
}
},
data() {
return {
infotype:'',
};
}, //end data
methods: {
setInfotype(infotype) {
this.infotype = infotype;
},
}, //end methods
components: {
//
},
mounted() {
this.infotype=this.$route.fullPath
},
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.menus {
.el-menu-item {
padding-left: 0px !important;
}
}
/* 超过宽度则用...代替 */
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.step-btn{
margin-left:0px;margin-bottom: 5px;
}
</style>
Loading…
Cancel
Save