eleme ui el-select 远程模糊搜索例子

作者: 时间: 2025-04-09 评论: 暂无评论
Vue.component('MySuperGame', {
props: {
    // 双向绑定值
    value: {
        type: [String, Number, Array],
        default: ''
    },
    platform: {
        type: [String, Number],
        default: 0
    },
    // 初始默认值(用于回显)
    initialValue: {
        type: [String, Number, Array],
        default: ''
    },
    // 是否多选
    multiple: {
        type: Boolean,
        default: false
    },
    // 防抖时间(毫秒)
    debounceTime: {
        type: Number,
        default: 300
    },
    // 是否启用缓存
    enableCache: {
        type: Boolean,
        default: true
    },
    // 自定义结果格式化函数
    formatter: {
        type: Function,
        default: items => items.map(item => ({
            value: item.id+'',
            label: item.id+'-'+item.title+'-' + item.subtitle,
            gameInfo: item
        }))
    }
},
data() {
    return {
        localValue: this.value || this.initialValue,
        options: [],
        loading: false,
        searchKeyword: '',
        searchCache: new Map(),
        cancelToken: null
    }
},

watch: {
    'platform': {
        handler(newVal, oldVal) {
            if (newVal > 0 && newVal != oldVal) {
                this.localValue = '';                   // 清空绑定值
                this.options = [];                   // 清空绑定值
            }
        },
    },
    value(newVal) {
        this.localValue = newVal
    },
    localValue(newVal) {
        this.$emit('input', newVal)
        this.$emit('change', newVal)
        let gameNode=this.options.filter(item => {
            if(item.value==newVal){
                return true
            }
        })
        if(gameNode[0]){
            this.$emit('gamechange', gameNode[0].gameInfo)
        }
    }
},

created() {
    console.log('platform',this.platform)
    // 初始化加载默认值对应的选项
    if (this.localValue) {
        this.loadInitialValues()
    }
},

methods: {
    // 防抖搜索方法
    handleSearch: _.debounce( async function  (keyword) {
        this.searchKeyword = keyword.trim()
        if (!this.searchKeyword) {
            this.options = []
            return
        }
        this.loading = true
        this.cancelPreviousRequest()
        let response = await axios.post('/topic/card/getGameNodeSearch', {key: keyword, platform: this.platform,format:0})
            .catch(error => {
                if (!axios.isCancel(error)) {
                    console.error('Remote search failed:', error)
                    this.$message.error('搜索失败,请稍后重试')
                }
            })
            .finally(() => (this.loading = false))
        const items = this.formatter(response.data.data.gameList || [])
        if (this.enableCache) {
            this.searchCache.set(this.searchKeyword, items)
        }
        this.options = items

    }, 300),

    // 取消之前的请求
    cancelPreviousRequest() {
        if (this.cancelToken) {
            this.cancelToken('取消重复请求')
        }
    },

    // 加载初始值对应的选项
    async loadInitialValues() {
        try {
            this.loading = true
            const id =  this.localValue
            const response = await axios.post(`/topic/card/getGameNodeSearch`, {key: id, format: 0, platform: this.platform})
            this.options = this.formatter(response.data.data.gameList || [])
        } catch (error) {
            console.error('初始化加载失败:', error)
        } finally {
            this.loading = false
        }
    },

    // 高亮匹配文本
    highlight(label) {
        if (!this.searchKeyword) return label
        const regex = new RegExp(`(${this.searchKeyword})`, 'gi')
        return label.replace(regex, '<span class="highlight">$1</span>')
    }
},

template: `
  <el-select
      v-model="localValue"
      filterable
      clearable
      remote
      reserve-keyword
      placeholder="请输入游戏名或游戏ID"  
      :multiple="multiple"
      :remote-method="handleSearch"
      :loading="loading"
      :loading-text="'加载中...'"
      :no-match-text="'无匹配结果'"
      :no-data-text="'暂无数据'"
  >
    <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
    >
      <span v-html="highlight(item.label)"></span>
    </el-option>
  </el-select>
`

})

移动开发问题总结

作者: 时间: 2018-12-27 评论: 暂无评论

1.情景:两个滚动层叠在一起,底层随着顶层滚动(滚动穿透)
方案:在底层可以滚动的层上加fixed

$("body").css({"position": "fixed",width:'100%'});

2.情景:fixed层input光标定位不准 或 input没有在可视区域。
方案:禁止底层的滚动,遮罩层禁止

$('.bg-opacity').on('touchmove',function(e){
        e.stopPropagation();
        e.preventDefault();
});

// 苹果uc浏览器 position: fixed;处理
var ua = navigator.userAgent.toLowerCase();
if (/iphone|ipad|ipod/.test(ua)) {
     $('#login-box input').bind('focus', function () {
        var h = $(window).height()-100;
        $("底部滚动层").css({"overflow": "hidden", "height": h + "px"});
     });
     $('#login-box input').bind('blur', function () {
        $("底部滚动层").css({"overflow": "auto", "height": "auto"});
     });
}

3.情景:fiexd里含有input,当输入法弹起,head定位不准,往下偏移。(UC浏览器下导航栏收起)
方案:修改浮动层,body层定位为absolute,键盘收起后还原

$('#login-box input').bind('focus', function () {
    $('header,#login-box').css({
        'position': 'absolute'
    });
    $('#section-footer').css({
        'position': 'absolute'
    });

    $('html').css({
        'position': 'relative'
    });
});
$('#login-box input').bind('blur', function () {
    $('header,#login-box').css({
        'position': 'fixed'
    });
    $('#section-footer').css({//由于有些设备直接fixed定位会从键盘的位置掉到底部的动作,所以先隐藏再显示;
        'position': 'fixed',
        'bottom':'0',
        'display':'none'
    });

    setTimeout(function(){
        $('#section-footer').fadeIn();
    },500);
    $('html').css({
        'position': 'static'
    });
});

附:https://segmentfault.com/a/1190000000515816?_ea=1271747

webpack配置文件详解

作者: 时间: 2016-04-22 评论: 暂无评论

http://www.cnblogs.com/Leo_wl/p/4862714.html

React Flux Redux思想

作者: 时间: 2016-04-21 评论: 暂无评论

╔═════════╗ ╔════════╗ ╔═════════════════╗
║ Actions ║──────>║ Stores ║──────>║ View Components ║
╚═════════╝ ╚════════╝ ╚═════════════════╝

   ^                                      │
   └──────────────────────────────────────┘

1.Flux:大致的过程是这样的,View层不能直接对state进行操作,而需要依赖Actions派发指令来告知Store修改状态,Store接收Actions指令后发生相应的改变,View层同时跟着Store的变化而变化。
举个例子:A组件要使B组件发生变化。首先,A组件需要执行一个Action,告知绑定B组件的Store发生变化,Store接收到派发的指令后改变,那相应的B组件的视图也就发生了改变。假如C,D,E,F组件绑定了和B组件相同的Store,那么C,D,E,F也会跟着变化。

2.Redux:
(1)reducer 实际上就是一个函数:(previousState, action) => newState。用来根据指定 action 来更新 state 。通过 combineReducers(reducers) 可以把多个 reducer 合并成一个 root reducer。

整理js遇到的一些关键词的用法

作者: 时间: 2016-04-05 评论: 暂无评论

1.typeof:检查一个变量是否存在,是否有值.不存在返回undefined
typeof array 返回 array
注意:

typeof null=object 

2.A instanceof B //A是否是类B的实力

3.continue 与break 的区别,break跳出整个循环,continue则是跳出当前的一个循环,执行下一个.

4.定义一个封闭的域, 它不仅避免了干扰,也使得内存在执行完后立即释放.代码加载立即执行.
use strict 指定使用javascript严格模式,禁止使用javascript一些糟糕的写法

(function(){}(
  'use strict';
));

5.prototype javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用。
A.prototype = new B();
理解prototype不应把它和继承混淆。A的prototype为B的一个实例,可以理解A将B中的方法和属性全部克隆了一遍。A能使用B的方法和属性。这里强调的是克隆而不是继承。可以出现这种情况:A的prototype是B的实例,同时B的prototype也是A的实例。

  1. import,requirt 引入对象,函数 ;export导出对象,函数

exprot.name='ManTou'; //user.js
var user=require('user.js') //index.js 或者 import user from('app.js')
console.log(user.name) // ManTou

import { Router, Route, Link } from 'react-router' 相当于

// 不使用 ES6 的转译器
var ReactRouter = require('react-router')
var Router = ReactRouter.Router
var Route = ReactRouter.Route
var Link = ReactRouter.Link

export default 用import App from 'app.js'接收
module.exporsts=app;用require('app.js')接收

JS中文文档地址:
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference