Skip to content

Commit

Permalink
split modal && clear cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Elegenthus committed Apr 22, 2017
1 parent e198ce5 commit b4f8cd4
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 184 deletions.
14 changes: 12 additions & 2 deletions src/common/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
var expires = "expires=" + d.toUTCString() + ";path = /";
document.cookie = cname + "=" + cvalue + "; " + expires;
}
//获取cookie
Expand All @@ -21,6 +21,15 @@ function clearCookie(name) {
setCookie(name, "", -1);
}

//删除cookie
function delCookie(name)
{
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString() + ";path = /";
}

function checkCookie(val) {
var key = getCookie(val);
if (key) {
Expand Down Expand Up @@ -53,6 +62,7 @@ var cookie = {
clearCookie: clearCookie,
checkCookie: checkCookie,
getToken: getToken,
getQueryString: getQueryString
getQueryString: getQueryString,
delCookie:delCookie
}
module.exports = cookie;
5 changes: 4 additions & 1 deletion src/components/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div v-show="showTips" :class="$style.suggestMask">
<div :class="$style.returnCard">
<div :class="$style.returnContent">登录以后才能评论和收藏哦~</div>
<div :class="$style.returnButton">我要登录</div>
<div :class="$style.returnButton" v-on:click = "admin">我要登录</div>
<div :class="$style.returnButton" v-on:click="quit">取消</div>
</div>
</div>
Expand Down Expand Up @@ -75,6 +75,9 @@ export default {
quit() {
this.showTips = false
},
admin(){
window.location = "/landing"
},
showSearch(e) {
if (window.location.pathname !== '/search') {
window.location = '/search'
Expand Down
12 changes: 5 additions & 7 deletions src/components/landing.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="$style.go">跳转中......</div>
<div :class="$style.go">登录中......</div>
</template>
<script>
import 'whatwg-fetch'
Expand All @@ -8,18 +8,16 @@ import FETCH from '../common/fetch.js'
export default {
mounted() {
// Cookie.setCookie("token", "value.token", 3000)
Cookie.setCookie("email", "[email protected]", 3000)
// Cookie.setCookie("uid", "4", 3000)
FETCH.FetchData("/api/v1.0/login","POST",{
FETCH.FetchData("/api/v1.0/login/","POST",{
email: Cookie.getCookie("email"),
password:"1234"
}).then(value => {
console.log(value)
Cookie.setCookie("token", value.token, 3000)
Cookie.setCookie("uid", value.uid, 3000)
Cookie.setCookie("token", value.token)
Cookie.setCookie("uid", value.uid)
setTimeout(() => {
window.location = "/"
window.history.back(-1);
}, 2000)
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/main/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import url from '../../common/url'
import 'whatwg-fetch'
import Item from './item'
import scrollDirective from '../../directives/scroll'
import Cookie from '../../common/cookie.js'
import FETCH from '../../common/fetch.js'
export default {
Expand All @@ -31,7 +30,6 @@ export default {
},
methods: {
onScroll() {
console.log("this.isScroll", this.isScroll)
if (this.isScroll) {
return
}
Expand Down
24 changes: 13 additions & 11 deletions src/components/pictures/banner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div>
<div :class="$style.banner" v-bind:style="imgHeight">
<div :class="$style.container" v-finger:swipeMove="onSwipe" v-finger:swipe="afterSwipe" v-finger:tap="showMask" v-bind:style="styleObject" v-transitionEnd="changeState">
<img alt="picture" v-bind:src="img.pic_url" v-bind:style="imgWidth" v-for="img in pics" v-radio="initImgRadio">
<img alt="picture" v-bind:src="img" v-bind:style="imgWidth" v-for="img in pics" v-radio="initImgRadio">
</div>
<div :class="$style.lastOneMask" v-show="lastOne" v-bind:style="imgHeight">
<div :class="$style.lastOneMask" v-show="lastOne" v-bind:style="imgHeight" v-finger:swipeMove="formerPic">
<svg viewBox="0 0 200 200" :class="$style.imgRecommend">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#recommend"></use>
</svg>
Expand Down Expand Up @@ -45,7 +45,8 @@ export default {
imgRadioArr: [],
tappedImgSrc: "",
tappedImgDescription: "",
lastOne: false
lastOne: false,
descriptionImg:[]
}
},
computed: {
Expand Down Expand Up @@ -80,18 +81,18 @@ export default {
}
}
},
mounted() {
console.log("this.picWidth", this.pics)
},
directives: {
transitionEnd: transitionEndDirective,
radio: radioDirective
},
methods: {
formerPic(d){
if(d.direction == 'Right' && this.i == this.pics.length-1)
this.lastOne = false
},
switchAble(direction) {
if (direction == 'Right') {
this.lastOne = false
console.log(this.lastOne)
}
if ((direction == 'Right' && this.i == 0) || (this.i == (this.pics.length - 1) && direction == 'Left')) {
if (this.i == (this.pics.length - 1) && direction == 'Left') {
Expand All @@ -111,7 +112,6 @@ export default {
if (this.picWidth / 2 + Math.abs(this.ix + e.deltaX) < (this.picWidth * this.customscale) / 2) {
this.ix += e.deltaX
}
console.log(document.body.clientHeight, window.screen.height, window.screen.availHeight)
var picHeight = this.picWidth / this.imgRadioArr[this.i]
if ((this.screenHeight < this.customscale * picHeight) && (this.screenHeight / 2 + Math.abs(this.iy + e.deltaY) - 40 * this.customscale < picHeight * this.customscale / 2)) {
this.iy += e.deltaY
Expand All @@ -132,23 +132,25 @@ export default {
if (e.direction == 'Left') {
this.i++
this.$parent.i++
this.x = -this.picWidth * this.i
} else {
this.i--
this.$parent.i--
this.x = -this.picWidth * this.i
}
} else {
this.x = -this.picWidth * this.i
}
this.isSwitching = true
this.tappedImgDescription = this.descriptionImg[this.i].description
this.tappedImgDescription = this.descriptionImg[this.i]
},
changeState() {
this.isSwitching = false
},
showMask(e, index) {
this.ifTab = true
this.tappedImgSrc = this.pics[index].pic_url
this.tappedImgSrc = this.pics[index]
this.picHight = this.picWidth / this.imgRadioArr[index]
},
hideMask() {
Expand All @@ -161,7 +163,7 @@ export default {
initImgRadio(radio, index) {
this.imgRadioArr[index] = radio
this.picHeight = this.picWidth * 0.75
this.tappedImgDescription = this.descriptionImg[this.i].description
this.tappedImgDescription = this.descriptionImg[this.i]
},
imgScale() {
if (this.customscale > 1.0) {
Expand Down
9 changes: 7 additions & 2 deletions src/components/pictures/pictures.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import widthDirective from '../../directives/width'
import Item from '../main/item'
import FETCH from '../../common/fetch.js'
import Banner from './banner'
import Cookie from '../../common/cookie.js'
export default {
Expand All @@ -56,19 +57,23 @@ export default {
mounted() {
var api = window.location.pathname
var ids = api.split('/')
let promise1 = FETCH.FetchData("/api/v1.0" + api + "/", "GET")
let promise1 = FETCH.FetchData("/api/v1.0" + api + "/", "POST",{
my_id: Cookie.getCookie("uid") ? Cookie.getCookie("uid"): -1
})
let promise2 = FETCH.FetchData("/api/v1.0/comments/?article_id=" + ids[2] + "&kind=2", "GET")
Promise.all([promise1, promise2]).then(values => {
this.pics = values[0].pics
this.$refs.bannerPic.pics = values[0].pics
console.log("this.$refs.bannerPic.pics",values[0])
this.$refs.bannerPic.descriptionImg = values[0].introduction
this.picInfo = values[0]
this.$refs.picComments.obj = values[1]
this.$refs.picComments.articleInfo = {
id: values[0].id,
kind: values[0].kind,
commentCount: values[0].commentCount,
likes: values[0].likes
likes: values[0].likes,
collected:values[0].collected
}
FETCH.FetchData("/api/v1.0/" + ids[1] + "/recommend/", "POST", {
article_id: this.picInfo.id
Expand Down
56 changes: 56 additions & 0 deletions src/components/profile/exitPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div v-show="returnIt" :class="$style.suggestMask">
<div :class="$style.returnCard">
<div :class="$style.returnContent">退出登录后,将不能发表评论和收藏内容。确认退出?</div>
<div :class="$style.returnButton" v-on:click="exit">退出</div>
<div :class="$style.returnButton" v-on:click="quit">取消</div>
</div>
</div>
</template>
<script>
import Cookie from '../../common/cookie.js'
export default {
methods: {
quit() {
this.$parent.returnIt = false
},
exit() {
Cookie.delCookie("token")
Cookie.delCookie("uid")
window.location = "/"
}
}
}
</script>
<style lang="sass" module>
@import '../../scss/color.scss';
.suggestMask {
position: fixed;
top: 0;
bottom: 0;
width: 100%;
background-color: rgba(51, 51, 51, 0.85);
}
.returnCard {
position: absolute;
top: 50%;
left: 50%;
width: 250px;
height: 90px;
background-color: $white;
color: $black;
padding: 15px;
border-radius: 2px;
transform: translate(-50%, -50%);
}
.returnButton {
float: right;
margin-left: 25px;
color: $orange;
cursor: pointer;
margin-top: 16px;
}
</style>
Loading

0 comments on commit b4f8cd4

Please sign in to comment.