去掉设置页tab,并将社区源选择的select修改为只有主源和备源的单选

This commit is contained in:
sunxiyuan 2020-04-10 15:07:28 +08:00
parent d25c4d3129
commit 24e6a23fd1
2 changed files with 73 additions and 98 deletions

View file

@ -77,9 +77,18 @@ class WP_CHINA_YES {
return false; return false;
} }
$options = get_option('wp_china_yes_options'); $options = get_option('wp_china_yes_options');
$api_server = $options["custom_api_server"] ?: $options["api_server"];
$download_server = $options["custom_download_server"] ?: $options["download_server"]; if ($options["community"] == 1) {
$api_server = 'api.w.org.ixmu.net';
$download_server = 'd.w.org.ixmu.net';
} else {
$api_server = 'api.w.org.ibadboy.net';
$download_server = 'd.w.org.ibadboy.net';
}
$api_server = $options["custom_api_server"] ?: $api_server;
$download_server = $options["custom_download_server"] ?: $download_server;
$url = str_replace('api.wordpress.org', $api_server, $url); $url = str_replace('api.wordpress.org', $api_server, $url);
$url = str_replace('downloads.wordpress.org', $download_server, $url); $url = str_replace('downloads.wordpress.org', $download_server, $url);
@ -146,15 +155,13 @@ EOT;
} }
public static function set_config() { public static function set_config() {
if (( ! array_key_exists('api_server', $_POST) && ! array_key_exists('download_server', $_POST)) || if ( ! array_key_exists('community', $_POST) ||
( ! array_key_exists('community', $_POST) && ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) { ( ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) {
self::error('参数错误', - 1); self::error('参数错误', - 1);
} }
self::set_wp_option( self::set_wp_option(
sanitize_text_field(trim($_POST['community'])), sanitize_text_field(trim($_POST['community'])),
sanitize_text_field(trim($_POST['api_server'])),
sanitize_text_field(trim($_POST['download_server'])),
sanitize_text_field(trim($_POST['custom_api_server'])), sanitize_text_field(trim($_POST['custom_api_server'])),
sanitize_text_field(trim($_POST['custom_download_server'])) sanitize_text_field(trim($_POST['custom_download_server']))
); );
@ -192,15 +199,11 @@ EOT;
private static function set_wp_option( private static function set_wp_option(
$community = 0, $community = 0,
$api_server = 'api.w.org.ibadboy.net',
$download_server = 'd.w.org.ibadboy.net',
$custom_api_server = '', $custom_api_server = '',
$custom_download_server = '' $custom_download_server = ''
) { ) {
$options = array(); $options = array();
$options['community'] = (int) $community; $options['community'] = (int) $community;
$options['api_server'] = $api_server;
$options['download_server'] = $download_server;
$options['custom_api_server'] = $custom_api_server; $options['custom_api_server'] = $custom_api_server;
$options['custom_download_server'] = $custom_download_server; $options['custom_download_server'] = $custom_download_server;
update_option("wp_china_yes_options", $options); update_option("wp_china_yes_options", $options);

View file

@ -16,80 +16,65 @@
</el-header> </el-header>
<el-main> <el-main>
<el-divider></el-divider> <el-divider></el-divider>
<el-tabs tab-position="right" style="height: 520px;"> <el-container>
<el-tab-pane label="插件设置"> <el-main class="no_top_main_box">
<el-container> <el-form ref="mirrors_form" :model="mirrors_form"
<el-main class="no_top_main_box"> label-width="100px" size="small"
<el-form ref="mirrors_form" :model="mirrors_form" style="width: 342px;">
label-width="100px" size="small" <el-card class="box-card" shadow="hover">
style="width: 342px;"> <div slot="header">
<el-card class="box-card" shadow="hover"> <span>使用社区仓库源</span>
<div slot="header"> </div>
<span>使用社区源</span> <el-form-item label="选择仓库源">
</div> <el-radio-group v-model="mirrors_form.community">
<el-form-item label="选择社区源"> <el-tooltip class="item" effect="dark"
<el-select v-model="mirrors_form.community" content="更新的技术、更快的速度、更佳的负载能力"
@change="changeServer" placement="top-start">
placeholder="请选择社区源"> <el-radio :label="0">主源</el-radio>
<el-option v-for="(item,index) in external_api.server" </el-tooltip>
:label="item.name" <el-tooltip class="item" effect="dark"
:value="item.id"></el-option> content="不求新颖但求稳定,力求高可用"
</el-select> placement="top-start">
</el-form-item> <el-radio :label="1">备源</el-radio>
<el-alert </el-tooltip>
:title="server_desc" </el-radio-group>
type="info" </el-form-item>
:closable="false" </el-card>
style="width: 422px; margin-left: 20px;" <el-card class="box-card" shadow="hover">
show-icon> <div slot="header">
</el-alert> <span>自定义源</span>
</el-card> <span style="font-size: 12px; margin-left: 10px;">若配置自定义源则会覆盖社区仓库源</span>
<el-card class="box-card" shadow="hover"> <el-link href="https://www.ibadboy.net/archives/3349.html"
<div slot="header"> style="float: right;"
<span>自定义源</span> type="primary"
<span style="font-size: 12px; margin-left: 10px;">若配置自定义源则会覆盖社区源</span> target="_blank"
<el-link href="https://www.ibadboy.net/archives/3349.html" :underline="false">搭建方法
style="float: right;" </el-link>
type="primary" </div>
target="_blank" <el-form-item label="API服务器" style="width: 442px;">
:underline="false">搭建方法 <el-input clearable
</el-link> v-model="mirrors_form.custom_api_server">
</div> <template slot="prepend">https://</template>
<el-form-item label="API服务器" style="width: 442px;"> </el-input>
<el-input clearable </el-form-item>
v-model="mirrors_form.custom_api_server"> <el-form-item label="下载服务器" style="width: 442px;">
<template slot="prepend">https://</template> <el-input clearable
</el-input> v-model="mirrors_form.custom_download_server">
</el-form-item> <template slot="prepend">https://</template>
<el-form-item label="下载服务器" style="width: 442px;"> </el-input>
<el-input clearable </el-form-item>
v-model="mirrors_form.custom_download_server"> </el-card>
<template slot="prepend">https://</template> <el-card class="box-card"
</el-input> style="height: 60px; text-align:center;"
</el-form-item> shadow="never">
</el-card> <el-button style="margin-top: -7px;"
<el-card class="box-card" type="primary"
style="height: 60px; text-align:center;" @click="submitMirrorsForm" size="medium">保存配置
shadow="never"> </el-button>
<el-button style="margin-top: -7px;" </el-card>
type="primary" </el-form>
@click="submitMirrorsForm" size="medium">保存配置 </el-main>
</el-button> </el-container>
</el-card>
</el-form>
</el-main>
</el-container>
</el-tab-pane>
<!--
<el-tab-pane label="贡献者名单">
</el-tab-pane>
<el-tab-pane label="捐助者名单">
</el-tab-pane>
-->
<el-tab-pane label="广告列表">
</el-tab-pane>
</el-tabs>
</el-main> </el-main>
<el-divider></el-divider> <el-divider></el-divider>
<el-footer> <el-footer>
@ -120,7 +105,6 @@
data() { data() {
return { return {
external_api: {}, external_api: {},
server_desc: '',
token: { token: {
get_config: '', get_config: '',
set_config: '' set_config: ''
@ -129,19 +113,10 @@
community: '0', community: '0',
custom_api_server: '', custom_api_server: '',
custom_download_server: '', custom_download_server: '',
api_server: '',
download_server: '',
} }
} }
}, },
methods: { methods: {
changeServer() {
let server = this.external_api.server[this.mirrors_form.community];
this.server_desc = server.desc;
this.mirrors_form.api_server = server.api_server;
this.mirrors_form.download_server = server.download_server;
},
getConfig() { getConfig() {
let vm = this; let vm = this;
let data = new FormData(); let data = new FormData();
@ -154,7 +129,6 @@
axios.get('https://wp-china-yes.ibadboy.net') axios.get('https://wp-china-yes.ibadboy.net')
.then(function (response) { .then(function (response) {
vm.external_api = response.data; vm.external_api = response.data;
vm.changeServer();
}) })
.catch(function (error) { .catch(function (error) {
vm.$message({ vm.$message({
@ -191,8 +165,6 @@
data.append('community', vm.mirrors_form.community); data.append('community', vm.mirrors_form.community);
data.append('custom_api_server', vm.mirrors_form.custom_api_server); data.append('custom_api_server', vm.mirrors_form.custom_api_server);
data.append('custom_download_server', vm.mirrors_form.custom_download_server); data.append('custom_download_server', vm.mirrors_form.custom_download_server);
data.append('api_server', vm.mirrors_form.api_server);
data.append('download_server', vm.mirrors_form.download_server);
axios.post(root_url + 'wp-admin/admin-ajax.php', data) axios.post(root_url + 'wp-admin/admin-ajax.php', data)
.then(function (response) { .then(function (response) {