diff --git a/src/backyard/dashboard/Index.vue b/src/backyard/dashboard/Index.vue index dceb1c3..ba6d043 100644 --- a/src/backyard/dashboard/Index.vue +++ b/src/backyard/dashboard/Index.vue @@ -94,7 +94,7 @@ diff --git a/src/backyard/install/Index.vue b/src/backyard/install/Index.vue index b43c7da..ab0f0d1 100644 --- a/src/backyard/install/Index.vue +++ b/src/backyard/install/Index.vue @@ -41,12 +41,25 @@
+
+
+
注意:
+
    +
  1. 如果数据库和蓝眼云盘安装在同一台服务器,Host可以直接填写 127.0.0.1。
  2. +
  3. 数据库账户的权限要求要能够创建表,否则第二步"创建表"操作会出错
  4. +
+ +
+
+
+ +
- - @@ -59,16 +72,133 @@
- +
-

这里安装数据库表

+
+
+ {{tableInfo.name}} + + + 已安装 + + + 已安装,字段缺失 + + + 待安装 + + +
+ +
+ 所有字段: {{field.DBName}} +
+
+ 缺失字段: {{field.DBName}} +
+ +
+ +
+
+
+
点击"一键建表"后会按照以下逻辑执行操作:
+
    +
  1. 如果某表不存在,则直接创建表。
  2. +
  3. 如果某表存在并且字段齐全,那么不会对该表做任何操作
  4. +
  5. 如果某表存在但是部分字段缺失,那么会在该表中增加缺失字段。
  6. +
  7. 如果表中有多余的字段(多余字段即不是蓝眼云盘需要的字段),不会做删除处理,而会维持原样。
  8. +
+ +
+
+
+ +
+
+ + + + + + + +
+
+
- +
-

这里配置管理员

+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+
+
注意:
+
    +
  1. 由于昵称将作为文件上传的目录,因此只允许字母数字以及"_"。
  2. +
  3. 管理员邮箱将作为登录的用户名。
  4. +
  5. 点击"提交"后,如果成功将自动进入首页,安装程序将失效。
  6. +
  7. 如果conf/tank.conf丢失、结构破坏会导致蓝眼云盘重启时激活安装程序。
  8. +
+ +
+
+
+ + +
+
+ + + +
+
+ +
@@ -83,9 +213,8 @@ export default { data() { return { + activeName: 'first', - verified: false, - tableCreated: false, install: new Install() } }, @@ -96,32 +225,39 @@ }, watch: { mysqlUrl(newVal, oldVal) { - this.verified = false + this.install.verified = false } }, methods: { verify() { let that = this; this.install.httpVerify(function () { - that.verified = true + that.install.verified = true that.$message.success("数据库连接可用!") }) }, fetchTableInfoList() { let that = this; - this.install.httpTableInfoList(function (response) { - console.log("获取到待安装表", response.data.data) - }) + this.install.httpTableInfoList() }, + handleClick(tab, event) { let paneName = tab.paneName; }, + createTable() { + //开始建表 + let that = this; + this.install.httpCreateTable(function (response) { + that.$message.success("建表成功!") + + }) + }, goTo(tabName) { if (tabName === "second") { - if (!this.verified) { + if (!this.install.verified) { this.$message.error("请首先验证数据库连接") return } @@ -129,12 +265,20 @@ this.fetchTableInfoList(); } else if (tabName === "third") { - if (!this.tableCreated) { + if (!this.install.tableCreated()) { this.$message.error("请首先创建数据库表") return } } this.activeName = tabName + }, + createAdmin() { + //开始创建管理员 + let that = this; + this.install.httpCreateAdmin(function (response) { + that.$message.success("创建管理员成功!") + + }) } }, mounted() { diff --git a/src/common/directive/directive.js b/src/common/directive/directive.js index 84fb6f4..2880d31 100644 --- a/src/common/directive/directive.js +++ b/src/common/directive/directive.js @@ -1,9 +1,12 @@ import Vue from 'vue' import $ from 'jquery' +//用于表单验证的指令 Vue.directive('validator', { update: function (el, binding, vnode) { if (binding.value && binding.value !== binding.oldValue) { + //先删除之前的,再寻求添加新的 + $(el).find('.validate').children().removeClass('border-danger').next('div').remove() $(el).find('.validate').children().addClass('border-danger').parent().append('
' + binding.value + '
') } else if (!binding.value) { $(el).find('.validate').children().removeClass('border-danger').next('div').remove() diff --git a/src/common/model/install/Install.js b/src/common/model/install/Install.js index 66e745b..008c646 100644 --- a/src/common/model/install/Install.js +++ b/src/common/model/install/Install.js @@ -4,6 +4,8 @@ export default class Install extends BaseEntity { static URL_VERIFY = '/api/install/verify' static URL_TABLE_INFO_LIST = '/api/install/table/info/list' + static URL_CREATE_TABLE = '/api/install/create/table' + static URL_CREATE_ADMIN = '/api/install/create/admin' constructor(args) { super(args) @@ -15,6 +17,19 @@ export default class Install extends BaseEntity { this.mysqlUsername = "tank" this.mysqlPassword = null + //管理员用户名 + this.adminUsername = null + this.adminEmail = null + this.adminPassword = null + this.adminRepassword = null + + //表原信息 + this.tableInfoList = [] + + //数据库连接是否可用 + this.verified = false + + this.validatorSchema = { mysqlPort: { rules: [{required: true, message: 'MySQL端口必填'}], @@ -38,6 +53,45 @@ export default class Install extends BaseEntity { } } + + this.adminValidatorSchema = { + adminUsername: { + rules: [ + {required: true, message: '昵称必填'}, + { + type: 'string', + pattern: /^[0-9a-zA-Z_]+$/, + message: '昵称只能包含字母,数字和"_"' + }], + error: null + }, + adminEmail: { + rules: [ + {required: true, message: '邮箱必填'}, + { + type: 'string', + pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/, + message: '邮箱格式不正确' + }], + error: null + }, + adminPassword: { + rules: [ + {required: true, message: '密码必填'}, + {min: 6, message: '密码长度至少为6位'} + ], + error: null + }, + adminRepassword: { + rules: [ + {required: true, message: '密码必填'}, + {min: 6, message: '密码长度至少为6位'} + ], + error: null + } + + } + } render(obj) { @@ -54,15 +108,35 @@ export default class Install extends BaseEntity { } } - validate() { - return super.validate() + validate(validatorSchema = this.validatorSchema) { + return super.validate(validatorSchema) } + //表创建完毕 + tableCreated() { + if (!this.tableInfoList || this.tableInfoList.length === 0) { + return false + } + for (let i = 0; i < this.tableInfoList.length; i++) { + let tableInfo = this.tableInfoList[i] + if (!tableInfo.tableExist) { + return false + } + + if (tableInfo.tableExist && tableInfo.missingFields.length !== 0) { + return false + } + } + + return true; + } + + httpVerify(successCallback, errorCallback) { let that = this if (!this.validate()) { - that.safeCallback(errorCallback)("验证不通过"); + this.defaultErrorHandler("验证不通过", errorCallback) return } @@ -76,8 +150,68 @@ export default class Install extends BaseEntity { httpTableInfoList(successCallback, errorCallback) { let that = this + if (!this.verified) { + this.defaultErrorHandler("请首先验证数据库连接", errorCallback) + return + } + this.httpPost(Install.URL_TABLE_INFO_LIST, this.getForm(), function (response) { + that.tableInfoList.splice(0, that.tableInfoList.length); + that.tableInfoList.push(...response.data.data) + + that.safeCallback(successCallback)(response) + + }, errorCallback) + } + + httpCreateTable(successCallback, errorCallback) { + let that = this + + if (!this.verified) { + this.defaultErrorHandler("请首先验证数据库连接", errorCallback) + return + } + + this.httpPost(Install.URL_CREATE_TABLE, this.getForm(), function (response) { + + that.tableInfoList.splice(0, that.tableInfoList.length); + that.tableInfoList.push(...response.data.data) + + that.safeCallback(successCallback)(response) + + }, errorCallback) + } + + httpCreateAdmin(successCallback, errorCallback) { + let that = this + + if (!this.tableCreated()) { + this.defaultErrorHandler("请首先创建数据库表", errorCallback) + return + } + + + if (!this.validate(that.adminValidatorSchema)) { + this.defaultErrorHandler("验证不通过", errorCallback) + return + } + + + if (this.adminPassword !== this.adminRepassword) { + this.defaultErrorHandler("两次密码不一致", errorCallback) + return + } + + + let form = this.getForm() + form["adminUsername"] = this.adminUsername + form["adminEmail"] = this.adminEmail + form["adminPassword"] = this.adminPassword + + + this.httpPost(Install.URL_CREATE_ADMIN, form, function (response) { + that.safeCallback(successCallback)(response) }, errorCallback)