<commit_before><template> 
    <div class="page_wrap slim_scrollbar">
        <div class="page_hd">
            <div class="search_box">
                <div class="search">
                    <span class="back" @click="goback"><mu-icon value="arrow_back" color="#fff" /></span>
                    <input type="search" v-model="keyword" placeholder="输入影片名" @keyup.enter="doSearch" ref="input_dom">
                    <span class="cancer" @click="doSearch" @keyup.enter="doSearch">搜索</span>
                </div>
            </div>
        </div>
        <div class="page_bd">
            <div class="content">
                <div class="list" v-if="movies && movies.length">
                    <MediaCard :media="movies"></MediaCard>
                </div>
                <div style="text-align: center;padding-top: 20px;" v-if="showEmpt">抱歉，没有找到要找的东西噢！</div>
                <mu-infinite-scroll :scroller="scroller" :loading="getLoading" @load="loadMore"/>
            </div>
        </div>
        <div class="page_ft">
        </div>
    </div>
</template>
<script>
let _self;
import Layout from '@/components/Layout';
import MediaCard from '@/components/MediaCard';
import { Toast } from 'mint-ui';

export default {
    data: function() {
        return {
            loading: 'init',
            movies: [],
            tvs: [],
            pageIndex: 1,
            keyword: '',
            scroller: null,
        };
    },
    created() {
        _self = this;
    },
    activated() {
        this.scroller = this.$el // 滚动的元素
    },
    deactivated() {
        this.scroller = null;
    },
    beforeRouteEnter (to, from, next) {
        if (from.name !== 'MovieDetail') {
            next(vm => {
                // vm.inputFocus();
                vm.resetData();
            });
        } else {
            next();
        }
    },
    methods: {
        doSearch() {
            if (this.keyword.replace(/\s+/g, "").length == 0 ) {
                Toast('请输入关键字');
                return;
            }
            this.$refs.input_dom.blur();
            this.resetData();
            this.getSearchVoice();
        },
        resetData() {
            this.loading = 'init';
            this.movies = [];
            this.tvs = [];
        },
        inputFocus() {
            this.$nextTick(() => {
                this.$refs.input_dom.focus();
            })
        },
        getSearchVoice() {
            let params = {};
            params.pageIndex = this.pageIndex || 1;
            params.keyword = this.keyword;
            this.loading = 'loading';
            this.$store.dispatch('getSearchVoice', params).then(function(response) {
                let res = response.data;
                if (response.ok && response.status === 200) {
                    res = JSON.parse(res);
                    _self.loading = 'loaded';
                    for(let item of res.movies) {
                        item.title = item.name;
                        item.image = item.img;
                    }
                    if (params.pageIndex > 1) {
                        _self.movies.push(...res.movies);<commit_msg>搜索bug<commit_after><template> 
    <div class="page_wrap slim_scrollbar">
        <div class="page_hd">
            <div class="search_box">
                <div class="search">
                    <span class="back" @click="goback"><mu-icon value="arrow_back" color="#fff" /></span>
                    <input type="search" v-model="keyword" placeholder="输入影片名" @keyup.enter="doSearch" ref="input_dom">
                    <span class="cancer" @click="doSearch" @keyup.enter="doSearch">搜索</span>
                </div>
            </div>
        </div>
        <div class="page_bd">
            <div class="content">
                <div class="list" v-if="movies && movies.length">
                    <MediaCard :media="movies"></MediaCard>
                </div>
                <div style="text-align: center;padding-top: 20px;" v-if="showEmpt">抱歉，没有找到要找的东西噢！</div>
                <mu-infinite-scroll :scroller="scroller" :loading="getLoading" @load="loadMore"/>
            </div>
        </div>
        <div class="page_ft">
        </div>
    </div>
</template>
<script>
let _self;
import Layout from '@/components/Layout';
import MediaCard from '@/components/MediaCard';
import { Toast } from 'mint-ui';

export default {
    data: function() {
        return {
            loading: 'init',
            movies: [],
            tvs: [],
            pageIndex: 1,
            keyword: '',
            scroller: null,
        };
    },
    created() {
        _self = this;
    },
    activated() {
        this.scroller = this.$el // 滚动的元素
    },
    deactivated() {
        this.scroller = null;
    },
    beforeRouteEnter (to, from, next) {
        if (from.name !== 'MovieDetail') {
            next(vm => {
                // vm.inputFocus();
                vm.resetData();
            });
        } else {
            next();
        }
    },
    methods: {
        doSearch() {
            if (this.keyword.replace(/\s+/g, "").length == 0 ) {
                Toast('请输入关键字');
                return;
            }
            this.$refs.input_dom.blur();
            this.resetData();
            this.getSearchVoice();
        },
        resetData() {
            this.loading = 'init';
            this.movies = [];
            this.tvs = [];
        },
        inputFocus() {
            this.$nextTick(() => {
                this.$refs.input_dom.focus();
            })
        },
        getSearchVoice() {
            let params = {};
            params.pageIndex = this.pageIndex || 1;
            params.keyword = this.keyword;
            this.loading = 'loading';
            this.$store.dispatch('getSearchVoice', params).then(function(response) {
                let res = response.data;
                if (response.ok && response.status === 200) {
                    res && res.movies && res.movies.length ? res = res : res = JSON.parse(res);
                    _self.loading = 'loaded';
                    for(let item of res.movies) {
                        item.title = item.name;
                        item.image = item.img;
                    }
                    if (params.pageIndex > 1) {
                        _self.movies.push(...res.movies);
{'fraction_non_alphanumeric': 0.1510802712505914, 'fraction_numerical': 0.0028386689796562055, 'mean_word_length': 1.3664179104477612, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6115795', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1811, 'n_words': 326}