From add1eeea7815d6601f63add140df09396c639a4d Mon Sep 17 00:00:00 2001 From: zmc <zmc_li@foxmail.com> Date: 星期四, 14 十二月 2023 15:25:21 +0800 Subject: [PATCH] 修改为正确的网络请求Ip --- src/sfc/InputSearch.vue | 160 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 100 insertions(+), 60 deletions(-) diff --git a/src/sfc/InputSearch.vue b/src/sfc/InputSearch.vue index 28757d2..0b79333 100644 --- a/src/sfc/InputSearch.vue +++ b/src/sfc/InputSearch.vue @@ -1,7 +1,10 @@ <!-- 杩滅▼鎼滅储 绔欑偣鍚嶇О 杈撳叆妗嗙粍浠� 鏍规嵁杈撳叆绔欑偣鐨勫唴瀹规彁渚涘搴旂殑杈撳叆寤鸿 - + 1.鍚戠埗缁勪欢浼犲叆绔欑偣鍚嶅瓧 鍜� 璁惧缂栫爜 + 2.鍙互閫夋嫨寤鸿鎴栬�呬换鎰忚緭鍏� + 3.鐖剁粍浠跺彲浠ヨ缃緭鍏ユ鏈夋棤榛樿鐨勭珯鐐瑰悕绉� + 4.鐖剁粍浠跺彲浠ヨ缃槸鍚﹂渶瑕佹牴鎹�変腑鐨勫紓甯哥被鍨嬫潵缁欏嚭绔欑偣寤鸿 ** 鍦ㄧ埗缁勪欢涓缃� <InputSearch :isNeedDefaultSite="1" @submit-value="(n)=>form.name=n"> </InputSearch> @@ -9,8 +12,9 @@ 鐖剁粍浠堕�氳繃娉ㄥ叆 :isNeedDefaultSite="1"鎴� :isNeedDefaultSite="0"鏉ヤ唬琛ㄨ杈撳叆妗嗘湁鏃犻粯璁ょ殑绔欑偣鍚嶇О 1浠h〃闇�瑕侀粯璁ゅ�� 锛�0浠h〃涓嶉渶瑕侀粯璁ゅ�� --> + <script> -import exceptionApi from '@/api/exceptionApi.js'; +import exceptionApi from '@/api/exceptionApi.js' export default { props: { // 0浠h〃涓嶉渶瑕侀粯璁ゅ�硷紝1浠h〃闇�瑕侀粯璁ゅ�� @@ -19,66 +23,77 @@ default: '0' }, // 0浠h〃涓嶉渶瑕侊紝1浠h〃鏍规嵁鏃舵鍜屽紓甯告潵缁欏嚭杈撳叆寤鸿 - isNeedRealTimeAdvice:{ - type:String, - default:'0' + isNeedRealTimeAdvice: { + type: String, + default: '0' }, - exceptionType:{ - type:Array, - default:()=>{ + exceptionType: { + type: Array, + default: () => { return [] } }, - beginTime:{ - type:String, - default:'' + beginTime: { + type: String, + default: '' }, - endTime:{ - type:String, - default:'' + endTime: { + type: String, + default: '' }, - siteName:{ - type:String, - default:'-1' + siteName: { + type: String, + default: '-1' } }, - emits: ['submitValue', 'submitSiteNums'], + emits: ['submitValue', 'submitSiteNums', 'submitMncode'], data() { return { // 鐢ㄦ埛閫変腑鐨勫�� state: '', // 淇濆瓨杈撳叆寤鸿鐨勭珯鐐瑰悕绉� - siteNames: [] + siteNames: [], + // 淇濆瓨杈撳叆寤鸿鐨勭珯鐐硅澶囩紪鍙� + siteNamesAndMnCode: [] } }, - watch:{ - beginTime(val,oldVal){ - - if(this.isNeedRealTimeAdvice =='1' && oldVal != ''){ - exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{ - this.siteNames = [] - const sites = res.data.data - sites.filter((item) => { - this.siteNames.push(item['name']) + watch: { + beginTime(val, oldVal) { + if (this.isNeedRealTimeAdvice == '1' && oldVal != '') { + exceptionApi + .getExceptionName(this.exceptionType, this.beginTime, this.endTime) + .then((res) => { + this.siteNames = [] + const sites = res.data.data + sites.filter((item) => { + this.siteNames.push(item['name']) + }) }) - }) } }, - exceptionType(){ - if(this.isNeedRealTimeAdvice =='1' ){ - exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{ - this.siteNames = [] - const sites = res.data.data - sites.filter((item) => { - this.siteNames.push(item['name']) + exceptionType() { + if (this.isNeedRealTimeAdvice == '1') { + exceptionApi + .getExceptionName(this.exceptionType, this.beginTime, this.endTime) + .then((res) => { + this.siteNames = [] + const sites = res.data.data + sites.filter((item) => { + this.siteNames.push(item['name']) + }) }) - }) } }, - siteName(){ - if(this.siteName != '-1' && this.siteName != ''){ + siteName() { + if (this.siteName != '-1' && this.siteName != '') { this.state = this.siteName this.$emit('submitValue', this.state) + } + }, + state() { + if (this.state != '' && this.state != null) { + // 鏌ユ壘瀵瑰簲鐨勮澶囩紪鍙� + this.onSiteNameSelected(this.state) } } }, @@ -94,42 +109,66 @@ } }, methods: { + obscureMatch(a, b) { + const pattern = new RegExp(a, 'i') + // 'i' 琛ㄧず涓嶅尯鍒嗗ぇ灏忓啓 + return pattern.test(b) + }, + querySearch(queryString, cb) { const results = queryString ? this.siteNames.filter(this.createFilter(queryString)) : this.siteNames cb(results) }, + createFilter(queryString) { return (restaurant) => { return ( - // toLowerCase() 鏂规硶鐢ㄤ簬鎶婂瓧绗︿覆杞崲涓哄皬鍐欍�� - restaurant.toLowerCase().indexOf(queryString.toLowerCase()) === 0 + this.obscureMatch(queryString,restaurant) ) } }, // 鍒濆鍖栧姞杞芥墍鏈夌殑绔欑偣鍚嶅瓧 loadAll() { - if(this.isNeedRealTimeAdvice == '1'){ - exceptionApi.getExceptionName(this.exceptionType,this.beginTime,this.endTime).then( res=>{ - this.siteNames = [] - const sites = res.data.data - sites.filter((item) => { - this.siteNames.push(item['name']) + if (this.isNeedRealTimeAdvice == '1') { + exceptionApi + .getExceptionName(this.exceptionType, this.beginTime, this.endTime) + .then((res) => { + this.siteNames = [] + const sites = res.data.data + sites.filter((item) => { + this.siteNames.push(item['name']) + let temp = {} + temp.name = item.name + temp.mnCode = item.mnCode + this.siteNamesAndMnCode.push(temp) + }) }) + } else if (this.isNeedRealTimeAdvice == '0') { + exceptionApi.getSitesNum().then((response) => { + const sites = response.data.data + sites.filter((item) => { + this.siteNames.push(item['name']) + let temp = {} + temp.name = item.name + temp.mnCode = item.mnCode + this.siteNamesAndMnCode.push(temp) + }) + this.$emit('submitSiteNums', this.siteNames.length) }) - - }else if(this.isNeedRealTimeAdvice == '0'){ - this.$http.get('/dust/sitename').then((response) => { - const sites = response.data.data - sites.filter((item) => { - this.siteNames.push(item['name']) - }) - this.$emit('submitSiteNums', this.siteNames.length) - }) - } + } }, - + // 鏍规嵁閫変腑鐨勭珯鐐规煡璇㈣澶囩紪鍙� + onSiteNameSelected(siteName) { + const selectedSite = this.siteNamesAndMnCode.find((site) => site.name == siteName) + if (selectedSite) { + this.$emit('submitMncode', selectedSite.mnCode) + } else { + this.$emit('submitMncode', '') + } + }, + // 鐐瑰嚮閫変腑寤鸿椤规椂瑙﹀彂 handleSelect(item) { this.state = item @@ -139,7 +178,8 @@ clearSiteName() { this.state = '' this.$emit('submitValue', this.state) - } + }, + } } </script> @@ -153,6 +193,7 @@ popper-class="my-autocomplete" placeholder="璇疯緭鍏�" @select="handleSelect" + @change="handleSelect" clearable @clear="clearSiteName" > @@ -176,5 +217,4 @@ .el-autocomplete { width: 200px; } - </style> -- Gitblit v1.9.3