数据库列表
用户列表
关于
var CloudAdmin = CloudAdmin || {}; CloudAdmin.router = function () { this.currentUrl = ''; this.printer = { pageNotFound: function () { let body = document.querySelector('body'); mdui.JQ(body).empty(); mdui.JQ(body).append(`
数据库名 | 用户ID | 用户名称 | 创建时间 | 操作 |
---|
暂无数据
`); } else { results.forEach(function (item, index, array) { let resultsAry = [], detailBut = document.createElement('button'), removeBut = document.createElement('button'); detailBut.className = 'mdui-btn'; removeBut.className = 'mdui-btn mdui-color-theme-accent'; detailBut.innerText = '查看详情'; removeBut.innerText = '删除'; detailBut.addEventListener('click', function () { let getDatabaseTablesUrl = 'http://admin.cloudsql.1473.cn/v1/index/databaseList/getDatabaseAllTables?dbName=' + item.dbName; this.ajax.get(getDatabaseTablesUrl, function (response) { let tablesAry = []; response.data.results.forEach(function (_item) { tablesAry.push(_item.TABLE_NAME); }); if (tablesAry.length === 0) { tablesAry.push('该数据库无数据表信息'); } let content = `请确保您清楚您当前正在执行一个危险操作操作
您确定要删除DB: ` + item.dbName + ` 吗?
`, history: false, buttons: [{ text: '确定', onClick: function (inst) { let dropDatabaseUrl = 'http://admin.cloudsql.1473.cn/v1/index/databaseList/dropDatabase', data = 'dbName=' + item.dbName; this.ajax.post(dropDatabaseUrl, data, function (response) { if (response.status == 'success') { mdui.dialog({ content: '执行成功', history: false, buttons: [{ text: '确定', onClick: function (inst) { window.location.reload(); } }] }); } else { mdui.dialog({ content: '执行失败', history: false, buttons: [{ text: '确定', onClick: function (inst) { window.location.reload(); } }] }); } }); } }, { text: '取消' } ] }); }, false); let actionColContent = [detailBut, removeBut]; resultsAry.push(item.dbName, item.dbOwnUuid, item.account, item.createDate, actionColContent); let tr = this.printer.tableGenerator(resultsAry); tableBody.appendChild(tr); }, this); table.appendChild(tableBody); mdui.updateTables(table); let pageShowCol = document.querySelector('.mdui-col-xs-12.page-button-row b'), pageNumOfNow = document.querySelector('.mdui-col-xs-12.page-button-row input'), jumpButton = document.querySelector('.mdui-col-xs-12.page-button-row button'), pageNum = Math.ceil(resultsCount / 20); pageShowCol.innerHTML = pageNum; pageNumOfNow.value = this.arguments.arg.argObj.pageIndex; jumpButton.addEventListener('click', (function () { this.arguments.arg.argObj.pageIndex = pageNumOfNow.value; let argStr = this.arguments.computed(); window.location.hash = '/index/databaseList?' + argStr; }).bind(this), false); } } else { mdui.snackbar({ message: response.info }); } }.bind(this)); }, userList: function () { let contentAera = document.querySelector('.mdui-container.main-container'), getUserListUrl = 'http://admin.cloudsql.1473.cn/v1/index/userList'; if (!this.arguments.arg.argStr) { this.arguments.arg = { argStr: 'pageIndex=1&orderBy=userName', argObj: { 'pageIndex': 1, 'orderBy': 'userName', 'search': '' } } } getUserListUrl += '?' + this.arguments.arg.argStr; mdui.JQ(contentAera).empty(); mdui.JQ(contentAera).append(`用户昵称 | 用户ID | 数据库密码 | 用户注册时间 | 操作 |
---|
暂无数据
`); } else { } results.forEach(function (item, index) { let resultsAry = [], detailBut = document.createElement('button'), removeBut = document.createElement('button'); detailBut.className = 'mdui-btn'; removeBut.className = 'mdui-btn mdui-color-theme-accent'; detailBut.innerText = '查看详情'; removeBut.innerText = '删除'; detailBut.addEventListener('click', function () { let getUserOwnDbUrl = 'http://admin.cloudsql.1473.cn/v1/index/userList/getUserOwnDb?userId=' + item.uuid; this.ajax.get(getUserOwnDbUrl, function (response) { let dbAry = []; response.data.results.forEach(function (_item) { dbAry.push(_item.dbName); }); if (dbAry.length === 0) { dbAry.push('无'); } let content = `请确保您清楚您当前正在执行一个危险操作操作
您确定要删除用户: ` + item.account + ` 吗?
`, history: false, buttons: [{ text: '确定', onClick: function (inst) { let removeUserUrl = 'http://admin.cloudsql.1473.cn/v1/index/userList/removeUser', data = 'userId=' + item.uuid + '&userNickName=' + item.account; this.ajax.post(removeUserUrl, data, function (response) { if (response.status == 'success') { mdui.dialog({ content: '执行成功', history: false, buttons: [{ text: '确定', onClick: function (inst) { window.location.reload(); } }] }); } else { mdui.dialog({ content: '执行失败', history: false, buttons: [{ text: '确定', onClick: function (inst) { window.location.reload(); } }] }); } }); } }, { text: '取消' } ] }); }.bind(this), false); let actionColContent = [detailBut, removeBut]; resultsAry.push(item.account, item.uuid, item.dbpassword, item.createDate, actionColContent); let tr = this.printer.tableGenerator(resultsAry); tableBody.appendChild(tr); }, this); table.appendChild(tableBody); mdui.updateTables(table); let pageShowCol = document.querySelector('.mdui-col-xs-12.page-button-row b'), pageNumOfNow = document.querySelector('.mdui-col-xs-12.page-button-row input'), jumpButton = document.querySelector('.mdui-col-xs-12.page-button-row button'), pageNum = Math.ceil(resultsCount / 20); pageShowCol.innerHTML = pageNum; pageNumOfNow.value = this.arguments.arg.argObj.pageIndex; jumpButton.addEventListener('click', (function () { this.arguments.arg.argObj.pageIndex = pageNumOfNow.value; let argStr = this.arguments.computed(); window.location.hash = '/index/userList?' + argStr; }).bind(this), false); } else { mdui.snackbar({ message: response.info }); } }.bind(this)); } } this.permissionCheck = { /** * 检测账户登录状态 * * @param {any} next 回调函数 */ signStatus: function (next) { this.ajax.get('http://admin.cloudsql.1473.cn/v1/index/signStatus', function (response) { if (response.status == 'signedin') { next.call(this); } else { window.location.hash = '/signin'; } }.bind(this)); } } this.routes = { '/': function () { window.location.hash = '#/signin'; }, '/404': this.printer.pageNotFound, '/signin': this.printer.signin.bind(this), '/signup': this.printer.signup.bind(this), '/index': this.printer.indexInit.bind(this, this.printer.index), '/index/databaseList': this.printer.indexInit.bind(this, this.printer.databaseList), '/index/userList': this.printer.indexInit.bind(this, this.printer.userList) }; this.arguments = { arg: {}, computed: function () { this.arg.argStr = ''; Object.keys(this.arg.argObj).forEach(function (item, index, array) { if (index + 1 === array.length) { this.arg.argStr += item + '=' + this.arg.argObj[item]; } else { this.arg.argStr += item + '=' + this.arg.argObj[item] + '&'; } }, this); return this.arg.argStr; } }; this.route = function (path, callback) { this.routes[path] = callback || function () {} } this.refresh = function () { this.currentUrl = location.hash.slice(1) || '/'; this.currentUrl = this.currentUrl.split("?"); //路由内无对应路径则跳转至404页面 if (this.currentUrl.length === 1 && this.routes[this.currentUrl[0]]) { this.routes[this.currentUrl[0]](); this.arguments.arg = {}; } else if (this.currentUrl.length === 2 && this.routes[this.currentUrl[0]]) { this.routes[this.currentUrl[0]](); let argStr = this.currentUrl[1]; this.arguments.arg = { argStr: argStr, argObj: {} } argStr.split("&").forEach(function (item, index) { let ary = item.split("="); this.arguments.arg.argObj[ary[0]] = ary[1]; }, this); } else { this.routes['/404'](); } } this.init = function () { const windowLoad = this.handleEvent('load', { onElement: window, withCallback: this.refresh.bind(this) }); const hashChange = this.handleEvent('hashchange', { onElement: window, withCallback: this.refresh.bind(this) }); } } CloudAdmin.router.prototype.ajax = { /** * 发送Get请求 * * @param {!string} url 请求地址 * @param {?function} next 回调函数 */ get: function (url, next) { let xhr = new XMLHttpRequest(); if (url.includes('?')) { // 在URL有其他参数时,添加一个date参数加入当前时间以避免缓存 xhr.open('GET', url + '&date=' + new Date().getTime(), true); } else { // 添加一个date参数加入当前时间以避免缓存 xhr.open('GET', url + '?' + new Date().getTime(), true); } xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // 更改XMLHttpRequest对象withCredentials属性以支持跨域Cookies xhr.withCredentials = true; xhr.responseType = 'json'; xhr.onload = function (res) { // 获取请求接口返回值 let response = res.target.response; next.call(this, response); }; xhr.send(); }, /** * 发送Post请求 * * @param {!string} url 请求地址 * @param {?string} data post请求参数 * @param {?function} next 回调函数 */ post: function (url, data, next) { let xhr = new XMLHttpRequest(); if (url.includes('?')) { // 在URL有其他参数时,添加一个date参数加入当前时间以避免缓存 xhr.open("POST", url + '&' + new Date().getTime(), true); } else { // 添加一个date参数加入当前时间以避免缓存 xhr.open("POST", url + '?' + new Date().getTime(), true); } xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // 更改XMLHttpRequest对象withCredentials属性以支持跨域Cookies xhr.withCredentials = true; xhr.responseType = 'json'; xhr.onload = function (res) { // 获取请求接口返回值 let response = res.target.response; next.call(this, response); }; xhr.send(data); } } /** * 监听事件处理函数 * * @param {string} eventName 表示监听事件类型的字符串 * @param {object} [{ onElement, withCallback, useCapture = false }={}] 监听对象 回调函数 useCapture * @param {function} thisArg * @returns function */ CloudAdmin.router.prototype.handleEvent = function (eventName, { onElement, withCallback, useCapture = false } = {}, thisArg) { const element = onElement || document.documentElement; function handler(event) { if (typeof withCallback === 'function') { withCallback.call(thisArg, event); } } handler.destroy = function () { return element.removeEventListener(eventName, handler, useCapture); } element.addEventListener(eventName, handler, useCapture); return handler } CloudAdmin.router.prototype.event = { dom: [], /** * 调用 CloudAdmin.router.prototype.handleEvent.handler.destroy 移除DOM的监听事件 * * @param {any} ary 存放DOM的数组 */ removeEventListener: function (ary) { } } //创建并初始化前端路由 let r = new CloudAdmin.router(); r.init();