去掉设置页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;
}
$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"];
$options = get_option('wp_china_yes_options');
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('downloads.wordpress.org', $download_server, $url);
@ -146,15 +155,13 @@ EOT;
}
public static function set_config() {
if (( ! array_key_exists('api_server', $_POST) && ! array_key_exists('download_server', $_POST)) ||
( ! array_key_exists('community', $_POST) && ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) {
if ( ! array_key_exists('community', $_POST) ||
( ! array_key_exists('custom_api_server', $_POST) && ! array_key_exists('custom_download_server', $_POST))) {
self::error('参数错误', - 1);
}
self::set_wp_option(
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_download_server']))
);
@ -192,15 +199,11 @@ EOT;
private static function set_wp_option(
$community = 0,
$api_server = 'api.w.org.ibadboy.net',
$download_server = 'd.w.org.ibadboy.net',
$custom_api_server = '',
$custom_download_server = ''
) {
$options = array();
$options['community'] = (int) $community;
$options['api_server'] = $api_server;
$options['download_server'] = $download_server;
$options['custom_api_server'] = $custom_api_server;
$options['custom_download_server'] = $custom_download_server;
update_option("wp_china_yes_options", $options);

View file

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