Skip to content

Commit

Permalink
代码优化:ghost:
Browse files Browse the repository at this point in the history
  • Loading branch information
D-xuanmo committed Apr 20, 2018
1 parent 8069940 commit 039a545
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 43 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>Your name</title>
<script src="//at.alicdn.com/t/font_556506_02zrofvxcsug14i.js"></script>
<script src="//at.alicdn.com/t/font_556506_fosg14c49ehtzkt9.js"></script>
</head>
<body>
<div id="app"></div>
Expand Down
56 changes: 41 additions & 15 deletions src/components/comment/Comments.vue
Expand Up @@ -95,11 +95,16 @@
<!-- 评论者等级 -->
<p class="inline-block">
<span class="icon-vip icon-level" :class="[item.userAgentInfo.vipStyle.style, item.userAgentInfo.vipStyle.level]" :style="`background-image: url(${templeteUrl}/static/images/vip.png);`" :title="item.userAgentInfo.vipStyle.title"></span>
<svg v-if="item.userAgentInfo.vipStyle.title === '博主'" class="iconfont-colour admin" aria-hidden="true">
<use xlink:href="#icon-vip"></use>
</svg>
</p>
<p class="inline-block system-wrap">
<!-- 浏览器logo -->
<span class="browser-info" :class="item.userAgentInfo.userAgent.browserName.toLowerCase()">{{ item.userAgentInfo.userAgent.browserName.replace('-', ' ') }}|{{ item.userAgentInfo.userAgent.browserVersion }}</span>
<!-- 系统logo -->
<span class="system-info">{{ item.userAgentInfo.userAgent.system.replace(/_/g, '.') }}</span>
</p>
<!-- 浏览器logo -->
<span class="browser-info" :class="item.userAgentInfo.userAgent.browserName.toLowerCase()">{{ item.userAgentInfo.userAgent.browserName.replace('-', ' ') }}|{{ item.userAgentInfo.userAgent.browserVersion }}</span>
<!-- 系统logo -->
<span class="system-info">{{ item.userAgentInfo.userAgent.system.replace(/_/g, '.') }}</span>
<time>{{ item.date.replace('T', ' ') }}</time>
<span v-if="item.status === 'hold'">您的评论正在审核中...</span>
</div>
Expand All @@ -109,9 +114,9 @@
</div> -->
</li>
</ul>
<div class="more-btn" v-show="commentList.length">
<img v-if="bMoreList" src="./images/bars.svg" alt="" width="40">
<span v-else @click="bClick && getMoreList()">{{ sMoreBtnText }}</span>
<div class="more-btn" @click="bClick && getMoreList()">
<!-- <img v-if="bMoreList" src="./images/bars.svg" alt="" width="40"> -->
<span><i v-show="bMoreList" class="iconfont icon-loading"></i>{{ sMoreBtnText }}</span>
</div>
</div>
</template>
Expand Down Expand Up @@ -159,10 +164,10 @@ export default {
},
currentNum: 1,
bClick: true,
bMoreList: false,
bMoreList: true,
bSubmit: true,
showChart: false,
sMoreBtnText: '下一页',
sMoreBtnText: '加载中',
submitText: '提交评论'
}
},
Expand Down Expand Up @@ -191,11 +196,13 @@ export default {
page: this.currentNum
}
}).then(res => {
this.bMoreList = false
this.sMoreBtnText = '下一页'
this.commentList = res.data
if (this.currentNum === +res.header['x-wp-totalpages']) {
this.sMoreBtnText = '最后一页!'
this.bClick = false
}
this.commentList = res.data
}).catch(err => console.log(err))
},
computed: {
Expand All @@ -207,19 +214,23 @@ export default {
// 评论列表下一页
getMoreList () {
this.bMoreList = true
this.bClick = false
this.sMoreBtnText = '加载中'
this.currentNum++
window.axios.get('/wp-json/wp/v2/comments/', {
params: {
post: this.$route.params.id,
page: this.currentNum
}
}).then(res => {
this.bMoreList = false
this.bClick = true
this.sMoreBtnText = '下一页'
this.commentList = [...this.commentList, ...res.data]
if (this.currentNum === +res.header['x-wp-totalpages']) {
this.sMoreBtnText = '最后一页!'
this.bClick = false
}
this.bMoreList = false
this.commentList = [...this.commentList, ...res.data]
}).catch(err => console.log(err))
},
// 提交评论
Expand Down Expand Up @@ -604,7 +615,7 @@ export default {
background: linear-gradient(to right, #dd3a45, #fcea67);
}
&.qqbrowser{
&[class*="qq"]{
background: linear-gradient(to right, #3072d1, #4ea8f3);
}
Expand All @@ -619,6 +630,14 @@ export default {
&.wechat{
background: #94d258;
}
&.ucbrowser{
background: linear-gradient(to right, #ed5e31, #f8cd46);
}
&.opera{
background: #eb3b3a;
}
}
// 系统信息
Expand Down Expand Up @@ -675,6 +694,13 @@ export default {
}
}
// 博主
.admin{
vertical-align: bottom;
width: 20px;
height: 20px;
}
time,
span{
font-size: 12px;
Expand Down Expand Up @@ -717,9 +743,9 @@ export default {
left: -15px;
}
time{
.system-wrap{
display: block;
margin-top: 5px;
margin: 5px 0;
}
}
}
Expand Down
Binary file removed xm-vue-theme.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions xm-vue-theme/functions.php
Expand Up @@ -13,13 +13,13 @@ function remove_redirects()
// Load scripts
function load_vue_scripts()
{
wp_enqueue_style('app.css', get_template_directory_uri() . '/static/css/app.46d29daaab34e0238ce6ade7e2592657.css', false, null);
wp_enqueue_style('app.css', get_template_directory_uri() . '/static/css/app.1b313ab3dffd4d31bd5cca25aa90ccad.css', false, null);

wp_enqueue_script('manifest.js', get_template_directory_uri() . '/static/js/manifest.37a2ecbb1d1b7e6c9ada.js', null, null, true);

wp_enqueue_script('vendor.js', get_template_directory_uri() . '/static/js/vendor.16b0e68c4ef67f74555d.js', null, null, true);

wp_enqueue_script('app.js', get_template_directory_uri() . '/static/js/app.5a0e34759de4a1d1a993.js', null, null, true);
wp_enqueue_script('app.js', get_template_directory_uri() . '/static/js/app.dc5a349d6ebbf4c294b3.js', null, null, true);
}

add_action('wp_enqueue_scripts', 'load_vue_scripts', 100);
Expand Down
47 changes: 30 additions & 17 deletions xm-vue-theme/include/xm-api.php
Expand Up @@ -203,25 +203,28 @@ function get_browser_name ($str)
$matches['ua'] = $str;
// 判断系统
if (preg_match('/Maci/', $str)) {
// Mac OS X 10.13
// mac
preg_match_all('/(?P<system>Mac(\s\w+)+\s(?P<version>(\d+\.\d+)|\d+(_\d+){2}))/i', $str, $match, PREG_SET_ORDER);
$matches['system'] = 'Mac ' . $match[0]['version'];
} else if (preg_match('/iPhone/', $str)) {
preg_match_all('/(?P<system>(iPhone\s\w+\s.)\w+)/i', $str, $match[0], PREG_SET_ORDER);
$matches['system'] = str_replace(' OS', '', str_replace('_', '.', $match[0][0]['system']));
} else if (preg_match('/iPad|iPhone/', $str)) {
// iPad or iphone
preg_match_all('/(?P<system>\w+);(\s[a-zA-Z]+)+\s(?P<version>\d+_\d+)/i', $str, $match, PREG_SET_ORDER);
$matches['system'] = $match[0]['system'] . ' ' . $match[0]['version'];
} else if (preg_match('/Android/', $str)) {
preg_match_all('/(?P<system>Android\s\d+\.\d+)/i', $str, $match[0], PREG_SET_ORDER);
$matches['system'] = $match[0][0]['system'];
// Android
preg_match_all('/(?P<system>Android\s\d+\.\d+)/i', $str, $match, PREG_SET_ORDER);
$matches['system'] = $match[0]['system'];
} else if (preg_match('/Wind/', $str)) {
preg_match_all('/(?P<system>Windows\sNT\s\d+\.\d+)/i', $str, $match[0], PREG_SET_ORDER);
if (strpos($match[0][0]['system'], '6.1')) {
$matches['system'] = str_replace(' NT 6.1', ' 7', $match[0][0]['system']);
} else if (strpos($match[0][0]['system'], '6.2')) {
$matches['system'] = str_replace(' NT 6.2', ' 8', $match[0][0]['system']);
} else if (strpos($match[0][0]['system'], '6.3')) {
$matches['system'] = str_replace(' NT 6.3', ' 8.1', $match[0][0]['system']);
} else if (strpos($match[0][0]['system'], '10.0')) {
$matches['system'] = str_replace(' NT 10.0', ' 10', $match[0][0]['system']);
// windows
preg_match_all('/(?P<system>Windows\sNT\s\d+\.\d+)/i', $str, $match, PREG_SET_ORDER);
if (strpos($match[0]['system'], '6.1')) {
$matches['system'] = str_replace(' NT 6.1', ' 7', $match[0]['system']);
} else if (strpos($match[0]['system'], '6.2')) {
$matches['system'] = str_replace(' NT 6.2', ' 8', $match[0]['system']);
} else if (strpos($match[0]['system'], '6.3')) {
$matches['system'] = str_replace(' NT 6.3', ' 8.1', $match[0]['system']);
} else if (strpos($match[0]['system'], '10.0')) {
$matches['system'] = str_replace(' NT 10.0', ' 10', $match[0]['system']);
}
} else {
$matches['system'] = 'Unknown';
Expand All @@ -237,6 +240,16 @@ function get_browser_name ($str)
// 微信内置浏览器
preg_match_all('/(?P<name>MicroMessenger)\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
$matches['browserVersion'] = $match[0]['version'];
$matches['browserName'] = 'wechat';
} else if (preg_match('/QQ\/\d/', $str)) {
// QQ
preg_match_all('/(?P<name>QQ)\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
$matches['browserVersion'] = $match[0]['version'];
$matches['browserName'] = $match[0]['name'];
} else if (preg_match('/UCBrowser/', $str)) {
// UC
preg_match_all('/(?P<name>UCBrowser)\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
$matches['browserVersion'] = $match[0]['version'];
$matches['browserName'] = $match[0]['name'];
} else if (preg_match('/Edge/', $str)) {
// edge
Expand All @@ -247,7 +260,7 @@ function get_browser_name ($str)
// opera
preg_match_all('/(?P<name>OPR)\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
$matches['browserVersion'] = $match[0]['version'];
$matches['browserName'] = $match[0]['name'];
$matches['browserName'] = 'Opera';
} else if (preg_match('/Chrome|MetaSr/', $str)) {
// chrome
preg_match_all('/(?P<name>(Chrome))\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
Expand All @@ -265,7 +278,7 @@ function get_browser_name ($str)
$matches['browserName'] = $match[0]['name'];
} else if (preg_match('/Trident/', $str)) {
// IE
preg_match_all('/(?P<name>Trident)\/(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
preg_match_all('/MSIE\s(?P<version>(\d+\.\d+))/i', $str, $match, PREG_SET_ORDER);
$matches['browserVersion'] = $match[0]['version'];
$matches['browserName'] = 'Internet-Explorer';
} else {
Expand Down
2 changes: 1 addition & 1 deletion xm-vue-theme/index.php
Expand Up @@ -13,7 +13,7 @@
?>
<link rel="icon" href="<?php echo get_option('xm_vue_options')['favicon']; ?>">
<?php wp_head(); ?>
<script src=//at.alicdn.com/t/font_556506_02zrofvxcsug14i.js></script>
<script src=//at.alicdn.com/t/font_556506_fosg14c49ehtzkt9.js></script>
</head>
<body>
<div id="app"></div>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

2 changes: 0 additions & 2 deletions xm-vue-theme/static/js/app.5a0e34759de4a1d1a993.js

This file was deleted.

1 change: 0 additions & 1 deletion xm-vue-theme/static/js/app.5a0e34759de4a1d1a993.js.map

This file was deleted.

2 changes: 2 additions & 0 deletions xm-vue-theme/static/js/app.dc5a349d6ebbf4c294b3.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions xm-vue-theme/static/js/app.dc5a349d6ebbf4c294b3.js.map

Large diffs are not rendered by default.

0 comments on commit 039a545

Please sign in to comment.