完成前后端紫鸟部分开发
This commit is contained in:
@@ -112,6 +112,7 @@
|
||||
<div class="tab active" data-tab="users">用户管理</div>
|
||||
<div class="tab" data-tab="columns">栏目权限配置</div>
|
||||
<div class="tab" data-tab="dedupe-total-data">数据去重总数据</div>
|
||||
<div class="tab" data-tab="shop-keys">店铺密钥管理</div>
|
||||
<div class="tab" data-tab="history">查看生成记录</div>
|
||||
<div class="tab" data-tab="version">版本管理</div>
|
||||
</div>
|
||||
@@ -308,6 +309,42 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 店铺密钥管理 -->
|
||||
<div id="panel-shop-keys" class="tab-panel">
|
||||
<div class="form-box">
|
||||
<h3 style="margin-bottom:16px;font-size:15px;">新增店铺密钥</h3>
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width:220px;">
|
||||
<label>紫鸟账号名称</label>
|
||||
<input type="text" id="shopKeyZiniaoAccountName" placeholder="请输入紫鸟账号名称">
|
||||
</div>
|
||||
<div class="form-group" style="min-width:260px;">
|
||||
<label>紫鸟令牌</label>
|
||||
<input type="text" id="shopKeyZiniaoToken" placeholder="请输入紫鸟令牌">
|
||||
</div>
|
||||
<button class="btn" id="btnCreateShopKey">新增店铺密钥</button>
|
||||
</div>
|
||||
<p class="msg" id="msgShopKey"></p>
|
||||
</div>
|
||||
<div class="panel-box">
|
||||
<h3 style="margin-bottom:16px;font-size:15px;">店铺密钥列表</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>序号</th>
|
||||
<th>紫鸟账号名称</th>
|
||||
<th>紫鸟令牌</th>
|
||||
<th>创建时间</th>
|
||||
<th>修改时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="shopKeyListBody"></tbody>
|
||||
</table>
|
||||
<div class="pagination" id="shopKeyPagination"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 查看生成记录 -->
|
||||
<div id="panel-history" class="tab-panel">
|
||||
<div class="form-box">
|
||||
@@ -423,6 +460,27 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 编辑店铺密钥弹窗 -->
|
||||
<div class="modal-mask" id="editShopKeyModal">
|
||||
<div class="modal">
|
||||
<h3>编辑店铺密钥</h3>
|
||||
<input type="hidden" id="editShopKeyId">
|
||||
<div class="form-group">
|
||||
<label>紫鸟账号名称</label>
|
||||
<input type="text" id="editShopKeyZiniaoAccountName" placeholder="紫鸟账号名称">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>紫鸟令牌</label>
|
||||
<input type="text" id="editShopKeyZiniaoToken" placeholder="紫鸟令牌">
|
||||
</div>
|
||||
<p class="msg" id="msgEditShopKey"></p>
|
||||
<div style="margin-top:16px;display:flex;gap:8px;">
|
||||
<button class="btn" id="btnSaveShopKey">保存</button>
|
||||
<button class="btn btn-secondary" id="btnCloseEditShopKey">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
// Tab 切换
|
||||
@@ -436,6 +494,7 @@
|
||||
if (t.dataset.tab === 'users') { loadUsers(1); loadColumnsForPermission(); }
|
||||
else if (t.dataset.tab === 'columns') loadColumns();
|
||||
else if (t.dataset.tab === 'dedupe-total-data') loadDedupeTotalData(1);
|
||||
else if (t.dataset.tab === 'shop-keys') loadShopKeys(1);
|
||||
else if (t.dataset.tab === 'history') loadHistory(1);
|
||||
else if (t.dataset.tab === 'version') loadVersions();
|
||||
};
|
||||
@@ -1134,6 +1193,142 @@
|
||||
document.getElementById('editDedupeTotalDataModal').classList.remove('show');
|
||||
};
|
||||
|
||||
// ========== 店铺密钥管理 ==========
|
||||
var shopKeyPage = 1, shopKeyPageSize = 15;
|
||||
function buildShopKeyQuery(page) {
|
||||
return 'page=' + (page || 1) + '&page_size=' + shopKeyPageSize;
|
||||
}
|
||||
function loadShopKeys(page) {
|
||||
shopKeyPage = page || 1;
|
||||
fetch('/api/admin/shop-keys?' + buildShopKeyQuery(shopKeyPage))
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
var tbody = document.getElementById('shopKeyListBody');
|
||||
if (!res.success) {
|
||||
tbody.innerHTML = '<tr><td colspan="6" class="empty-tip">加载失败: ' + (res.error || '') + '</td></tr>';
|
||||
return;
|
||||
}
|
||||
var items = res.items || [];
|
||||
if (items.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="6" class="empty-tip">暂无店铺密钥</td></tr>';
|
||||
} else {
|
||||
tbody.innerHTML = items.map(function(item, index) {
|
||||
var rowNo = (shopKeyPage - 1) * shopKeyPageSize + index + 1;
|
||||
return '<tr><td>' + rowNo + '</td><td>' + (item.ziniao_account_name || '') + '</td><td>' + (item.ziniao_token || '') + '</td><td>' + (item.created_at || '') + '</td><td>' + (item.updated_at || '') + '</td><td>' +
|
||||
'<button class="btn btn-sm" data-shop-key-edit="' + item.id + '" data-shop-key="' + (JSON.stringify(item).replace(/"/g, '"')) + '">编辑</button> ' +
|
||||
'<button class="btn btn-sm btn-danger" data-shop-key-delete="' + item.id + '" data-ziniao-account-name="' + (item.ziniao_account_name || '').replace(/"/g, '"') + '">删除</button>' +
|
||||
'</td></tr>';
|
||||
}).join('');
|
||||
}
|
||||
renderPagination('shopKeyPagination', res.total, res.page, res.page_size, loadShopKeys);
|
||||
bindShopKeyActions();
|
||||
})
|
||||
.catch(function() {
|
||||
document.getElementById('shopKeyListBody').innerHTML = '<tr><td colspan="6" class="empty-tip">请求失败</td></tr>';
|
||||
});
|
||||
}
|
||||
function bindShopKeyActions() {
|
||||
document.querySelectorAll('[data-shop-key-edit]').forEach(function(btn) {
|
||||
btn.onclick = function() {
|
||||
var item = {};
|
||||
try { item = JSON.parse((btn.dataset.shopKey || '').replace(/"/g, '"')); } catch (e) { item = {}; }
|
||||
document.getElementById('editShopKeyId').value = item.id || '';
|
||||
document.getElementById('editShopKeyZiniaoAccountName').value = item.ziniao_account_name || '';
|
||||
document.getElementById('editShopKeyZiniaoToken').value = item.ziniao_token || '';
|
||||
document.getElementById('msgEditShopKey').textContent = '';
|
||||
document.getElementById('msgEditShopKey').className = 'msg';
|
||||
document.getElementById('editShopKeyModal').classList.add('show');
|
||||
};
|
||||
});
|
||||
document.querySelectorAll('[data-shop-key-delete]').forEach(function(btn) {
|
||||
btn.onclick = function() {
|
||||
var name = (btn.dataset.ziniaoAccountName || '').replace(/"/g, '"');
|
||||
if (!confirm('确定删除店铺密钥「' + name + '」吗?')) return;
|
||||
fetch('/api/admin/shop-key/' + btn.dataset.shopKeyDelete, { method: 'DELETE' })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
if (res.success) { loadShopKeys(shopKeyPage); }
|
||||
else { alert(res.error || '删除失败'); }
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
document.getElementById('btnCreateShopKey').onclick = function() {
|
||||
var ziniaoAccountName = (document.getElementById('shopKeyZiniaoAccountName').value || '').trim();
|
||||
var ziniaoToken = (document.getElementById('shopKeyZiniaoToken').value || '').trim();
|
||||
var msgEl = document.getElementById('msgShopKey');
|
||||
msgEl.textContent = '';
|
||||
msgEl.className = 'msg';
|
||||
if (!ziniaoAccountName || !ziniaoToken) {
|
||||
msgEl.textContent = '请完整填写紫鸟账号名称、紫鸟令牌';
|
||||
msgEl.classList.add('err');
|
||||
return;
|
||||
}
|
||||
fetch('/api/admin/shop-key', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
ziniao_account_name: ziniaoAccountName,
|
||||
ziniao_token: ziniaoToken
|
||||
})
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
if (res.success) {
|
||||
document.getElementById('shopKeyZiniaoAccountName').value = '';
|
||||
document.getElementById('shopKeyZiniaoToken').value = '';
|
||||
msgEl.textContent = res.msg || '创建成功';
|
||||
msgEl.className = 'msg ok';
|
||||
loadShopKeys(1);
|
||||
} else {
|
||||
msgEl.textContent = res.error || '创建失败';
|
||||
msgEl.className = 'msg err';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
msgEl.textContent = '请求失败';
|
||||
msgEl.className = 'msg err';
|
||||
});
|
||||
};
|
||||
document.getElementById('btnSaveShopKey').onclick = function() {
|
||||
var itemId = document.getElementById('editShopKeyId').value;
|
||||
var ziniaoAccountName = (document.getElementById('editShopKeyZiniaoAccountName').value || '').trim();
|
||||
var ziniaoToken = (document.getElementById('editShopKeyZiniaoToken').value || '').trim();
|
||||
var msgEl = document.getElementById('msgEditShopKey');
|
||||
msgEl.textContent = '';
|
||||
msgEl.className = 'msg';
|
||||
if (!ziniaoAccountName || !ziniaoToken) {
|
||||
msgEl.textContent = '请完整填写紫鸟账号名称、紫鸟令牌';
|
||||
msgEl.classList.add('err');
|
||||
return;
|
||||
}
|
||||
fetch('/api/admin/shop-key/' + itemId, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
ziniao_account_name: ziniaoAccountName,
|
||||
ziniao_token: ziniaoToken
|
||||
})
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
if (res.success) {
|
||||
document.getElementById('editShopKeyModal').classList.remove('show');
|
||||
loadShopKeys(shopKeyPage);
|
||||
} else {
|
||||
msgEl.textContent = res.error || '保存失败';
|
||||
msgEl.classList.add('err');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
msgEl.textContent = '请求失败';
|
||||
msgEl.classList.add('err');
|
||||
});
|
||||
};
|
||||
document.getElementById('btnCloseEditShopKey').onclick = function() {
|
||||
document.getElementById('editShopKeyModal').classList.remove('show');
|
||||
};
|
||||
|
||||
// ========== 版本管理 ==========
|
||||
function loadVersions() {
|
||||
fetch('/api/admin/versions')
|
||||
@@ -1334,6 +1529,7 @@
|
||||
loadUserOptions();
|
||||
loadColumnsForPermission();
|
||||
loadDedupeTotalData(1);
|
||||
loadShopKeys(1);
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user