From f9687b9e0fea07180d8ac9506be9537386b5f0da Mon Sep 17 00:00:00 2001 From: xiaozhiyong Date: Wed, 1 Mar 2023 14:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/autocomplete/index.vue | 84 ++++++++++++++++++++------- src/utils/index.js | 4 +- src/views/login/index.vue | 2 +- src/views/product/index.vue | 3 +- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/components/autocomplete/index.vue b/src/components/autocomplete/index.vue index 126bba9..9055981 100644 --- a/src/components/autocomplete/index.vue +++ b/src/components/autocomplete/index.vue @@ -11,13 +11,31 @@ :disabled="isDisabled" @change="change" > - - + + @@ -37,6 +55,8 @@ export default { data() { return { text: "", + labelIsMore: false, + // labelKeyArr:[], list: [], isDisabled: false, }; @@ -44,48 +64,68 @@ export default { watch: { "config.echoId": { handler(nval, oval) { + this.list = []; + // this.isDisabled = !!this.config.isDisabled; if (nval) { - this.remoteMethod(this.config.echoName); + let resultName = this.config.echoName.replace(/\s*/g, ""); + if (!resultName) return; + this.remoteMethod(resultName); + } + }, + deep: true, + immediate: true, + }, + "config.isDisabled": { + handler(nval, oval) { + let type = this.$utils.typeJudgment(nval); + if (["Boolean", "String"].includes(type)) { + this.isDisabled = !!this.config.isDisabled; } - this.isDisabled = !!this.config.isDisabled; }, deep: true, immediate: true, }, }, + created() { + let { labelKey } = this.config; + let type = this.$utils.typeJudgment(labelKey); + // console.log(type); + if (type === "Array") { + // let + this.labelIsMore = true; + // console.log(this.labelIsMore); + } + }, methods: { // 远程搜索 remoteMethod(query) { if (query !== "") { this.loading = true; - let params = {}; let type = this.$utils.typeJudgment(this.config.autocompleteKey); - if (!type.includes("Object") && !type.includes("String")) return; - if (type.includes("Object")) { + let params = {}; + if (["Object"].includes(type)) { params[this.config.autocompleteKey.key] = query; params["enableMark"] = this.config.autocompleteKey.enableMark; } - if (type.includes("String")) { + if (["String", "Undefined", "Null"].includes(type)) { + // 接口为get类型时需将autocompleteKey值设为空 this.config.autocompleteKey ? (params[this.config.autocompleteKey] = query) - : (params["queryTypeGet"] = query); + : (params = query); } this.config.serveTarget(params).then((res) => { - let timeInstance = setTimeout(() => { - this.loading = false; - clearTimeout(timeInstance); - if (res.data.length) { - this.list = res.data; - } else this.list = []; - }, 1000 * Math.random()); + this.loading = false; + if (res.data.length) { + this.list = res.data; + } else this.list = []; }); } else { this.list = []; } }, change(val) { - this.$emit("change", val); + this.$emit("change", val, this.list); }, }, }; diff --git a/src/utils/index.js b/src/utils/index.js index d33d6ac..2e719e4 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -52,7 +52,9 @@ export function isLicensePlate(no) { return instance.test(no); } +// 类型判断 export function typeJudgment(object) { let res = {}.__proto__.toString.call(object); - return res ? res : ""; + let type = /(?<= ).+(?=\])/.exec(res); + return type.length ? type[0] : ""; } diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 9ea2be5..bb65af6 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -145,6 +145,7 @@ export default { networkId, }) .then((res) => { + this.loading = false; if (res && res.code === 42014) { serve .getRefineryByCustomerId(this.loginForm.username) @@ -154,7 +155,6 @@ export default { }); return; } - console.log() localStorage.setItem("customerToken", res.data.accessToken); this.$router.replace("/"); }) diff --git a/src/views/product/index.vue b/src/views/product/index.vue index 71f65a1..9495e20 100644 --- a/src/views/product/index.vue +++ b/src/views/product/index.vue @@ -33,6 +33,7 @@ > +