Commit aeb7dfb4 authored by wangxl's avatar wangxl

4444

parent 170ce7ae
import Vue from 'vue'
import Api from '@/api/index.js'
import api from '@/api'
const state = {
dict: {},
queue: []
......@@ -24,10 +25,10 @@ const mutations = {
}
}
const actions = {
getDict: (state) => {
getDict: ({ commit, state }, type) => {
return state.dict
},
getDictByType: (state) => (type) => {
getDictByType: ({ dispatch, state }, type) => {
/**
* 闭包特性。返回一个函数,该函数接收一个type参数。
* 同时由于闭包还持有state对象,故可以返回需要的值。
......@@ -43,25 +44,24 @@ const actions = {
// 没有缓存则请求数据
if (!isExistence) {
// 在异步请求之前将该任务标记为已缓存(存入队列)
commit('SET_QUEUE', 'dict/' + type)
return new Promise((resolve, reject) => {
return Api.getDict(type)
.then((res) => {
const { code, data } = res
if (code && code !== 200) {
// 获取失败移除缓存队列
commit('DEL_QUEUE', 'dict/' + type)
reject(res)
this.commit('cache/SET_QUEUE', 'dict/' + type)
return new Promise(async (resolve, reject) => {
await api.parameter.getArrayListByType({ typeId: type })
.then(({ data = {} }) => {
if (data) {
try {
this.commit('cache/SET_DICT', { type: type, list: data })
resolve(data)
} catch (error) {
reject(error)
}
} else {
// 获取到的值存入字典
commit('SET_DICT', { type: type, list: data })
resolve(res)
reject('error')
}
})
.catch((error) => {
}).catch(err => {
// 获取失败移除缓存队列
commit('DEL_QUEUE', 'dict/' + type)
reject(error)
this.commit('cache/DEL_QUEUE', 'dict/' + type)
reject(err.response)
})
})
} else {
......
<template>
<div style=" width:auto; display:inline-block !important; display:inline;">
<a-select :style="{width: width? width+ 'px':'80%'}" v-model="selected" @change="paraChange($event)" :key="0">
<a-select :style="{width: width? width+ 'px':'80%'}" v-model="selected" @change="onChange($event)" :key="0">
<a-select-option v-for="item in selectArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
</div>
</template>
<script>
// 用法 <para-select v-model="formData.projClass" :typeId="52" />
export default {
name: "paraSelect",
data () {
......@@ -49,17 +49,16 @@ export default {
},
},
created () {
this.loadSelected()
this.load()
},
methods: {
loadSelected () {
load () {
let pars = { typeId: this.typeId }
this.$api.parameter.getParameterList(pars).then(({ data = { data } }) => {
if (data) {
this.selectArray = data.data
this.selectArray.unshift(this.defaultValue)
if (!!this.value) {
this.loadState = true
this.selected = this.value
}
else
......@@ -67,7 +66,7 @@ export default {
}
}).catch(() => { })
},
paraChange (value) {
onChange (value) {
this.$emit("input", value);
var newArr = this.selectArray.filter(x => x.key == value);
if (!!newArr && newArr.length > 0) {
......
......@@ -50,7 +50,7 @@ import projectView from '@/views/report/project/components/projectView'
export default {
name: 'queryProject',
components: {
projectView
projectView,
},
data () {
return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment