forked from ganlvtech/down_52pojie_cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Vue components. 'Not support IE 8 or eariler'. now pluggable.
- Loading branch information
Showing
8 changed files
with
248 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import axios from 'axios'; | ||
import jQuery from 'jquery'; | ||
import toastr from 'toastr'; | ||
import Vue from 'vue'; | ||
import Router from 'vue-router'; | ||
import Home from './views/Home.vue'; | ||
import App from './App.vue'; | ||
import {cacheTimestamp} from './helpers'; | ||
|
||
const $ = jQuery; | ||
|
||
Vue.config.productionTip = false; | ||
Vue.use(Router); | ||
|
||
export default function Down52PojieCn(config = {}) { | ||
/** | ||
* Vue 实例的挂载目标 | ||
* | ||
* @default '#app' | ||
* @type string | ||
* @see https://cn.vuejs.org/v2/api/#el | ||
*/ | ||
this.vueElement = config.vueElement || '#app'; | ||
|
||
/** | ||
* Vue Router 历史记录模式 | ||
* | ||
* 'hash' or 'history' | ||
* | ||
* @default 'hash' | ||
* @type string | ||
* @see https://router.vuejs.org/api/#router-mode | ||
*/ | ||
this.routerMode = config.routerMode || 'hash'; | ||
|
||
/** | ||
* 基础网址(末尾不加斜线) | ||
* | ||
* @type string | ||
* @default 'https://down.52pojie.cn' | ||
*/ | ||
this.baseUrl = config.baseUrl || 'https://down.52pojie.cn'; | ||
|
||
/** | ||
* 请求数据文件的方法 | ||
* | ||
* 'json' or 'jsonp' | ||
* | ||
* @default 'json' | ||
* @type string | ||
*/ | ||
this.requestType = config.requestType || 'json'; | ||
|
||
/** | ||
* json 文件的 URL | ||
* | ||
* @type string | ||
* @default '/list.json' | ||
*/ | ||
this.jsonUrl = config.jsonUrl || '/list.json'; | ||
|
||
/** | ||
* jsonp 请求的 URL | ||
* | ||
* @type string | ||
* @default '/list.js' | ||
*/ | ||
this.jsonpUrl = config.jsonpUrl || '/list.js'; | ||
|
||
/** | ||
* jsonp 请求的回调函数名, | ||
* | ||
* @type string | ||
* @default '__jsonpCallbackDown52PojieCn' | ||
*/ | ||
this.jsonpCallback = config.jsonpCallback || '__jsonpCallbackDown52PojieCn'; | ||
|
||
/** | ||
* 数据文件缓存时间 | ||
* | ||
* 数字表示缓存时间(秒),请求后面会加上类似 ?t=153xxxxxxx 的时间戳,这个时间戳是通过整除得到的,通常是可以通过 CDN 缓存的。 | ||
* falsy value 表示不加 ?t= 的时间戳,是否读取缓存靠服务器的缓存控制 | ||
* | ||
* @type {int} | ||
* @default 0 | ||
*/ | ||
this.cacheTime = config.cacheTime || 0; | ||
|
||
this.router = null; | ||
toastr.info('爱盘搜索扩展插件加载完成,正在加载文件列表'); | ||
this[this.requestType](); | ||
} | ||
|
||
Down52PojieCn.prototype.json = function () { | ||
let url = this.jsonUrl; | ||
if (this.cacheTime) { | ||
url += '?t=' + cacheTimestamp(this.cacheTime); | ||
} | ||
axios.get(url) | ||
.then(response => { | ||
let data = response.data; | ||
this.callback(data); | ||
}) | ||
.catch(error => { | ||
toastr.error(`通过 ajax 加载文件出错,请刷新页面或联系管理员。错误信息:${error.message}`); | ||
throw error; | ||
}); | ||
}; | ||
|
||
Down52PojieCn.prototype.jsonp = function () { | ||
window[this.jsonpCallback] = data => { | ||
clearTimeout(timeout); | ||
this.callback(data); | ||
window[this.jsonpCallback] = undefined; | ||
}; | ||
let script = document.createElement('script'); | ||
script.src = this.jsonpUrl; | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
let timeout = setTimeout(function () { | ||
toastr.error('通过 jsonp 加载文件列表超时,请刷新页面或联系管理员。'); | ||
}, 20000); | ||
}; | ||
|
||
Down52PojieCn.prototype.callback = function (data) { | ||
let router = new Router({ | ||
mode: this.routerMode, | ||
base: '/', | ||
routes: [ | ||
{ | ||
path: '(.*)', | ||
name: 'home', | ||
component: Home, | ||
props: { | ||
baseUrl: this.baseUrl, | ||
list: data | ||
} | ||
} | ||
] | ||
}); | ||
this.router = router; | ||
|
||
this.vm = new Vue({ | ||
el: this.vueElement, | ||
router, | ||
render: h => h(App) | ||
}); | ||
|
||
$('#main').hide(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<div> | ||
<form class="form-inline" action="/" method="post" @submit.prevent="submitForm"> | ||
<div class="form-group mb-2"> | ||
<label for="search-input">查找文件:</label> | ||
</div> | ||
<div class="form-group mr-2 mb-2"> | ||
<input id="search-input" ref="searchInput" :value="query" type="search" name="query" class="form-control" @input="submitDebounce"> | ||
</div> | ||
<button type="submit" class="btn btn-primary mr-2 mb-2">搜索</button> | ||
<a class="btn btn-outline-primary mb-2" @click="submitAll">全部文件</a> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
query: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
methods: { | ||
submit(query) { | ||
this.$emit('submit', query); | ||
}, | ||
submitDebounce: _.debounce(function () { | ||
this.submit(this.$refs.searchInput.value); | ||
}, 500), | ||
submitForm() { | ||
this.submit(this.$refs.searchInput.value); | ||
}, | ||
submitAll() { | ||
this.submit(''); | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
import './styles/index.scss'; | ||
import Down52PojieCn from './Down52PojieCn'; | ||
|
||
import Vue from 'vue'; | ||
import Router from 'vue-router'; | ||
import Home from './views/Home.vue'; | ||
import App from './App.vue'; | ||
|
||
window.$ = window.jQuery = require('jquery'); | ||
window.Popper = require('popper.js'); | ||
require('bootstrap'); | ||
|
||
Vue.config.productionTip = false; | ||
Vue.use(Router); | ||
|
||
const router = new Router({ | ||
mode: process.env.VUE_APP_ROUTER_MODE || 'hash', | ||
base: '/', | ||
routes: [ | ||
{path: '(.*)', name:'home', component: Home} | ||
] | ||
}); | ||
|
||
window.vm = new Vue({ | ||
el: '#app', | ||
router, | ||
render: h => h(App) | ||
}); | ||
window.Down52PojieCn = Down52PojieCn; |
Oops, something went wrong.