Feat: chrome插件,首页搜索初步完成

This commit is contained in:
fanxb 2019-12-01 22:50:10 +08:00
parent 90ddef3eca
commit 360bad76d7
10 changed files with 93 additions and 26 deletions

View File

@ -7,6 +7,7 @@ chrome.extension.onConnect.addListener(port => {
switch (msg.type) { switch (msg.type) {
case 'sendToken': case 'sendToken':
localStorage.setItem('token', msg.data); localStorage.setItem('token', msg.data);
window.token = msg.data;
break; break;
default: default:
console.error('未知的数据', msg); console.error('未知的数据', msg);

View File

@ -22,7 +22,7 @@
}, },
"content_scripts": [{ "content_scripts": [{
"matches": ["http://west.tapme.top/*", "http://bookmark.tapme.top/*","http://localhost:3000/*"], "matches": ["http://west.tapme.top/*", "http://bookmark.tapme.top/*","http://localhost:3000/*"],
"js": ["popup/static/sso.js"] "js": ["static/sso.js"]
} }
] ]

View File

@ -4,31 +4,24 @@ import store from '../store';
import router from './router'; import router from './router';
import ElementUI from 'element-ui'; import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'; import 'element-ui/lib/theme-chalk/index.css';
import config from '../util/config';
import axios from 'axios'; import axios from 'axios';
global.browser = require('webextension-polyfill'); global.browser = require('webextension-polyfill');
Vue.prototype.$browser = global.browser; Vue.prototype.$browser = global.browser;
Vue.use(ElementUI); Vue.use(ElementUI);
/* eslint-disable no-new */
window.vueInstance = new Vue({
el: '#app',
store,
router,
render: h => h(App),
});
/** /**
* 配置axios * 配置axios
*/ */
axios.defaults.timeout = 15000; axios.defaults.timeout = 15000;
axios.defaults.baseURL = config.baseUrl;
/** /**
* 请求拦截器 * 请求拦截器
*/ */
axios.interceptors.request.use( axios.interceptors.request.use(
function(config) { function(config) {
console.log(config); config.headers['jwt-token'] = window.token;
return config; return config;
}, },
function(error) { function(error) {
@ -39,10 +32,23 @@ axios.interceptors.request.use(
axios.interceptors.response.use( axios.interceptors.response.use(
res => { res => {
console.log(res); if (res.data.code === -1) {
return res.data; window.vueInstance.$router.replace('/public/login');
} else if (res.data.code === 1) {
return res.data.data;
} else {
Promise.reject(res);
}
}, },
error => { error => {
return Promise.reject(error); return Promise.reject(error);
} }
); );
/* eslint-disable no-new */
window.vueInstance = new Vue({
el: '#app',
store,
router,
render: h => h(App),
});

View File

@ -1,20 +1,71 @@
<template> <template>
<div class="main"> <div>
<p>Hello world!</p> <div class="head">
<img width="30%" src="/static/img/bookmarkLogo.png" alt="icon" />
<span>{{personInfo.username}}</span>
</div>
<!-- 书签检索 -->
<div class="search">
<el-input placeholder="关键词检索" v-model="searchContent">
<el-button slot="append" icon="el-icon-search"></el-button>
</el-input>
<div class="searchResult">
<div class="item" v-for="item in searchList" :key="item.bookmarkId"><a target="_blank" :href="item.url">{{item.name}}</a></div>
</div>
</div>
</div> </div>
</template> </template>
<script> <script>
import axios from 'axios';
export default { export default {
data() { data() {
return {}; return {
personInfo: {},
searchContent: "",
searchList: [],
timeOut: null
};
}, },
watch: {
searchContent(newVal, oldVal) {
if (newVal.trim() != oldVal) {
if (this.timeOut != null) {
clearTimeout(this.timeOut);
}
this.searchList = [];
this.timeOut = setTimeout(async () => {
this.searchList = await axios.get(`bookmark/searchUserBookmark?content=${newVal}`);
this.timeOut = null;
}, 200);
}
}
},
created() {
window.token = localStorage.getItem('token');
this.init();
},
methods: {
async init() {
let personInfo = await axios.get("/user/currentUserInfo");
window.personInfo = personInfo;
this.personInfo = personInfo;
}
}
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.main { .head {
width: 50%; display: flex;
height: 50%; justify-content: space-between;
align-items: center;
padding: 0 5% 0 5%;
}
.searchResult {
}
.item {
padding: 5px;
border-bottom: 1px solid black;
} }
</style> </style>

View File

@ -1,14 +1,15 @@
<template> <template>
<div class="main">您还未登陆授权<el-button type="primary" @click="go">前往授权页面</el-button></div> <div class="main">您还未登陆授权<br />
<el-button type="primary" @click="go">前往授权页面</el-button>
</div>
</template> </template>
<script> <script>
import config from '../../../../util/config';
export default { export default {
name: 'login', name: 'login',
data() { data() {
return { return {
// href: 'http://west.tapme.top:8083',
href: 'http://localhost:3000/userSpace/ssoAuth',
}; };
}, },
mounted() { mounted() {
@ -16,7 +17,7 @@ export default {
}, },
methods: { methods: {
go() { go() {
window.open(this.href); window.open(config.ssoUrl);
}, },
// token // token
checkToken() { checkToken() {
@ -33,6 +34,4 @@ export default {
</script> </script>
<style scoped> <style scoped>
.main {
}
</style> </style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -0,0 +1,9 @@
// const baseUri = 'https://bm.tapme.top';
const baseUri = 'http://localhost:3000';
const config = {
baseUrl: baseUri + '/bookmark/api',
ssoUrl: baseUri + '/userSpace/ssoAuth',
};
export default config;

View File

@ -74,7 +74,8 @@ const config = {
}), }),
new CopyWebpackPlugin([ new CopyWebpackPlugin([
{ from: 'icons', to: 'icons', ignore: ['icon.xcf'] }, { from: 'icons', to: 'icons', ignore: ['icon.xcf'] },
{ from: 'static', to: 'popup/static' }, { from: 'static', to: 'static' },
{ from: 'static/fonts', to: 'fonts' },
{ from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml }, { from: 'popup/popup.html', to: 'popup/popup.html', transform: transformHtml },
{ from: 'options/options.html', to: 'options/options.html', transform: transformHtml }, { from: 'options/options.html', to: 'options/options.html', transform: transformHtml },
{ {