Skip to content

Commit

Permalink
✨ inject search function #1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicejade committed Jan 20, 2019
1 parent ef41109 commit c1a652a
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 72 deletions.
67 changes: 67 additions & 0 deletions src/assets/icons/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions src/assets/styles/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
}
.title {
color: @black;
font-size: 6 * @size-factor;
font-weight: bold;
text-align: center;
margin-top: 5 * @size-factor;
}
.desc {
color: @grey-black;
Expand Down Expand Up @@ -42,4 +40,19 @@
:active {
height: 7 * @size-factor;
}
}

.nice-list {
background-color: @white-grey;
padding: 0 3 * @size-factor;
.load-more {
.flex-box-mixins(row, center, center);
margin-bottom: 2 * @size-factor;
.progress {
text-align: right;
}
.loading-tip {
text-align: center;
}
}
}
46 changes: 46 additions & 0 deletions src/components/Loading.ux
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<div class="loading">
<image class="loading-img" src="./../../assets/icons/loading.svg" />
</div>
</template>

<script>
export default {
data: {},
onInit() {}
}
</script>

<style lang="less">
@import './../assets/styles/variables.less';
.loading {
width: 100%;
height: 100%;
position: fixed;
top: 0;
bottom: 0;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: @grey-black;
opacity: 0.3;
.loading-img {
width: 20 * @size-factor;
height: 20 * @size-factor;
transform: rotate(90deg);
animation-name: rotate;
animation-duration: 1314ms;
animation-iteration-count: infinite;
animation-timing-function: ease-out;
animation-fill-mode: forwards;
}
@keyframes rotate{
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
}
</style>
44 changes: 22 additions & 22 deletions src/components/NiceList.ux
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,33 @@ export default {
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 5 * @size-factor;
padding: 3 * @size-factor;
.meta {
width: 100%;
white-space: nowrap;
margin-bottom: 2 * @size-factor;
.item {
color: @silver-grey;
}
.classify {
color: @brand;
}
.username {
color: @silver-grey;
}
.datetime {
color: @silver-grey;
margin-right: 3 * @size-factor;
}
.tag {
color: @silver-grey;
}
}
.title {
font-size: 5 * @size-factor;
color: @ink-black;
font-weight: bold;
text-align: left;
margin-bottom: 3 * @size-factor;
margin-bottom: 2 * @size-factor;
&:hover {
color: @brand;
}
Expand All @@ -138,27 +159,6 @@ export default {
color: @black-grey;
margin: 0 @size-factor;
}
.meta {
width: 100%;
white-space: nowrap;
margin-bottom: 3 * @size-factor;
.item {
color: @silver-grey;
}
.classify {
color: @brand;
}
.username {
color: @silver-grey;
}
.datetime {
color: @silver-grey;
margin-right: 3 * @size-factor;
}
.tag {
color: @silver-grey;
}
}
.operate-area {
.action-area {
border-radius: @size-factor;
Expand Down
20 changes: 2 additions & 18 deletions src/components/TabItem.ux
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,9 @@ export default {
$utils.promptMessage(error)
this.niceLinksList = await $storage.get(linksStorageKey)
this.isLoadMore = false
}).finally(() => {
this.$emit('updateCallback', true)
})
}
}
</script>

<style lang="less">
@import './../assets/styles/style.less';
.nice-list {
background-color: @white-grey;
padding: 0 3 * @size-factor;
.load-more {
.flex-box-mixins(row, center, center);
margin-bottom: 2 * @size-factor;
.progress {
text-align: right;
}
.loading-tip {
text-align: center;
}
}
}
</style>
59 changes: 36 additions & 23 deletions src/helper/ajax.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
import $utils from './utils'
/** @format */

import $fetch from '@system.fetch'
import $utils from './utils'

Promise.prototype.finally = function(callback) {
const P = this.constructor
return this.then(
value => P.resolve(callback()).then(() => value),
reason =>
P.resolve(callback()).then(() => {
throw reason
})
)
}

function requestHandle(params) {
return new Promise((resolve, reject) => {
$fetch.fetch({
url: params.url,
method: params.method,
data: params.data,
success: data => {
const serverResponse = JSON.parse(data.data)
if (serverResponse.success) {
resolve(serverResponse.value)
} else {
resolve(serverResponse.message)
}
},
fail: (data, code) => {
$fetch
.fetch({
url: params.url,
method: params.method,
data: params.data
})
.then(response => {
const result = response.data
const content = JSON.parse(result.data)
/* @desc: 可跟具体不同业务接口数据,返回你所需要的部分,使得使用尽可能便捷 */
content.success ? resolve(content.value) : resolve(content.message)
})
.catch((error, code) => {
console.log(`🐛 request fail, code = ${code}`)
reject(data)
},
complete: data => {
reject(data)
}
})
reject(error)
})
.finally(() => {
console.log(`✔️ request @${params.url} has been completed.`)
resolve()
})
})
}

export default {
post: function(url, params, op) {
post: function(url, params) {
return requestHandle({
method: 'post',
url: url,
data: params
})
},
get: function(url, params, op) {
get: function(url, params) {
return requestHandle({
method: 'get',
url: $utils.queryString(url, params)
})
}
}
}
6 changes: 6 additions & 0 deletions src/helper/apis/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ export default {
},
getNiceLinks(data) {
return $ajax.get($utils.composeApiPath('getNiceLinks'), data)
},
searchNiceLinks (data) {
return $ajax.get($utils.composeApiPath('searchNiceLinks'), data)
},
getRandomLinks (data) {
return $ajax.get($utils.composeApiPath('getRandomLinks'), data)
}
}
6 changes: 6 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
},
"pages/WebPage": {
"component": "index"
},
"pages/Search": {
"component": "index"
}
}
},
Expand All @@ -65,6 +68,9 @@
},
"pages/About": {
"menu": false
},
"pages/Search": {
"titleBarText": "倾城之链 - 搜索"
}
}
}
Expand Down
Loading

0 comments on commit c1a652a

Please sign in to comment.