Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户登陆相关功能 #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chrome-xiaote",
"version": "1.1.4",
"version": "1.2.0",
"description": "Xiaote community on chrome plugin.",
"author": "Yimaoge",
"license": "GPL V3",
Expand All @@ -26,6 +26,7 @@
"@vant/touch-emulator": "^1.2.0",
"axios": "^0.19.0",
"js-cookie": "^2.2.1",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"url-loader": "^3.0.0",
"vant": "^2.5.3",
Expand Down
78 changes: 74 additions & 4 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import request from '../utils/request';
import apiRequest from '../utils/apiReuqest';

export function communities(page_index, page_size) {
const params = { page_index: page_index, page_size: page_size };
return request({
url: '/v1/communities',
url: '/api/v1/communities',
method: 'get',
params,
});
Expand All @@ -12,15 +13,15 @@ export function communities(page_index, page_size) {
export function recommends(page_index, page_size) {
const params = { page_index: page_index, page_size: page_size };
return request({
url: '/v1/recommends',
url: '/api/v1/recommends',
method: 'get',
params,
});
}

export function read(objectId) {
return request({
url: '/v1/communities/' + objectId + '/read',
url: '/api/v1/communities/' + objectId + '/read',
method: 'post',
data: {
objectId: objectId,
Expand All @@ -30,7 +31,76 @@ export function read(objectId) {

export function comments(objectId) {
return request({
url: '/v1/communities/' + objectId + '/comments',
url: '/api/v1/communities/' + objectId + '/comments',
method: 'get',
});
}

export function statistics(userId) {
return request({
url: '/api/v1/users/' + userId + '/statistics',
method: 'get',
});
}

export function smsCode(mobliePhone) {
return apiRequest({
url: '/1.1/requestSmsCode',
method: 'post',
data: {
mobilePhoneNumber: mobliePhone,
},
});
}

export function usersByMobilePhone(smsCode, mobliePhone) {
return apiRequest({
url: '/1.1/usersByMobilePhone',
method: 'post',
data: {
smsCode: smsCode,
mobilePhoneNumber: mobliePhone,
},
});
}

export function getUserInfo(userId) {
return apiRequest({
url: '/1.1/users/' + userId,
method: 'get',
});
}

export function follow(userId, targetUserId) {
return request({
url: '/api/v1/users/' + userId + '/followees',
method: 'post',
data: {
uid: targetUserId,
},
});
}

export function unFollow(userId, targetUserId) {
return request({
url: '/api/v1/users/' + userId + '/followees',
method: 'delete',
data: {
uid: targetUserId,
},
});
}

export function like(postId) {
return request({
url: '/api/v1/communities/' + postId + '/like',
method: 'post',
});
}

export function commentLike(postId, commentId) {
return request({
url: '/api/v1/communities/' + postId + '/comments/' + commentId + '/like',
method: 'post',
});
}
11 changes: 11 additions & 0 deletions src/assets/css/animate.min.css

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* @description 系统全局配置
*/
export default {
BASE_API: 'https://lcen.xiaote.net/api',
AppName: '小特社区',

BASE_API: 'https://lcen.xiaote.net',

AUTH_API: 'https://lcapi.xiaote.net',

JSON_API: 'https://api.npoint.io',

Expand All @@ -11,8 +15,16 @@ export default {
*/
TokenKey: 'X-LC-Session',

UserIdKey: 'X-LC-Uid',

/**
* @description 请求超时时间,毫秒(默认2分钟)
*/
timeout: 1200000,

tokenCookieExpires: 3600 * 24 * 10,

TeslaInviteUrl: 'https://ts.la/lnanddj59482',

TeslaInviteCode: 'lnanddj59482',
};
75 changes: 12 additions & 63 deletions src/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,40 @@
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
</transition>
<transition name="van-slide-right">
<transition :name="transitionName">
<!--因为用的是v-if 所以下面还要创建一个未缓存的路由视图出口-->
<router-view v-if="!$route.meta.keepAlive"></router-view>
</transition>

<tab v-show="isShowTab()"></tab>
<tab v-show="isShowTabBar"></tab>
<login :show="isShowLoginPage" @loginPageClose="loginPageClose"></login>
</div>
</template>

<script>
import PageTab from './components/Tab';
// import { mapGetters } from 'vuex';

const ESC_KEY_CODE = 27;
const W_KEY_CODE = 87;

function noScroll() {
window.scrollTo(0, 0);
}
function keyDown(e) {
const keyCode = e.which;
const realKey = String.fromCharCode(e.which);
console.log('按键码: ' + keyCode + ' 字符: ' + realKey);
// 用户按下 Esc 键
if (keyCode === ESC_KEY_CODE) {
e.preventDefault();
if (window.imagePreviewInstance) {
window.imagePreviewInstance.close();
window.imagePreviewInstance = null;
return;
}
// 如果在评论页面,回退一步
const path = document.$router.history.current.path;
if (path === '/settings' || path === '/comments' || path === '/about') {
history.back();
}
}
// 按下 ctrl + w
if (keyCode === W_KEY_CODE && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
window.close();
}
}
import LoginPage from './components/Login';
import { mapGetters } from 'vuex';
import { keyDown } from '@/utils/tools';

export default {
data() {
return {
transitionName: '',
};
return {};
},
computed: {
// ...mapGetters(['currentTab']),
...mapGetters(['isShowLoginPage', 'isShowTabBar', 'transitionName']),
},
created() {
document.$router = this.$router;
document.onkeydown = keyDown;
},
watch: {
$route(to, from) {
console.log(from.path, to.path);
if ((from.path === '/' || from.path === '/recommends') && to.path === '/comments') {
this.transitionName = 'van-slide-right';
} else if (from.path === '/comments' && (to.path === '/' || to.path === '/recommends')) {
this.transitionName = 'van-slide-left';
} else {
this.transitionName = '';
}
// 单独的个人中心页面 & 设置页面禁止页面滚动
if (to.path === '/home' || to.path === '/settings' || to.path === '/about') {
window.addEventListener('scroll', noScroll);
} else {
window.removeEventListener('scroll', noScroll);
}
},
this.$store.dispatch('GetUserInfo');
},
components: {
tab: PageTab,
login: LoginPage,
},
methods: {
getPath() {
return this.$router.history.current.path;
},
isShowTab() {
const path = this.$router.history.current.path;
return path !== '/comments' && path !== '/settings' && path != '/about';
loginPageClose() {
this.$store.dispatch('ToggleLoginPage', false);
},
},
};
Expand Down
Loading