Commit aeb7dfb4 authored by wangxl's avatar wangxl

4444

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