|
@@ -526,14 +526,14 @@ class TreeService extends Service {
|
|
|
* @return {Promise<*>}
|
|
|
* @private
|
|
|
*/
|
|
|
- async _deleteNodeData(mid, deleteNode) {
|
|
|
+ async _deletePosterity(mid, node) {
|
|
|
this.initSqlBuilder();
|
|
|
this.sqlBuilder.setAndWhere(this.setting.mid, {
|
|
|
value: mid,
|
|
|
operate: '=',
|
|
|
});
|
|
|
this.sqlBuilder.setAndWhere(this.setting.fullPath, {
|
|
|
- value: this.db.escape(deleteNode[this.setting.fullPath] + '%'),
|
|
|
+ value: this.db.escape(node[this.setting.fullPath] + '-%'),
|
|
|
operate: 'Like',
|
|
|
});
|
|
|
const [sql, sqlParam] = this.sqlBuilder.build(this.tableName, 'delete');
|
|
@@ -555,13 +555,15 @@ class TreeService extends Service {
|
|
|
if (!select) throw '删除节点数据错误';
|
|
|
const parent = await this.getDataByKid(mid, select[this.setting.pid]);
|
|
|
// 获取将要被删除的数据
|
|
|
- const deleteData = await this.getDataByFullPath(mid, select[this.setting.fullPath] + '%');
|
|
|
+ const deleteData = await this.getDataByFullPath(mid, select[this.setting.fullPath] + '-%');
|
|
|
+ deleteData.unshift(select);
|
|
|
if (deleteData.length === 0) throw '删除节点数据错误';
|
|
|
|
|
|
this.transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 删除
|
|
|
- const operate = await this._deleteNodeData(mid, select);
|
|
|
+ await this.transaction.delete(this.tableName, { id: select.id });
|
|
|
+ const operate = await this._deletePosterity(mid, select);
|
|
|
// 选中节点--父节点 只有一个子节点时,应升级isLeaf
|
|
|
if (parent) {
|
|
|
const count = await this.db.count(this.tableName, this.getCondition({mid: mid, pid: select[this.setting.pid]}));
|
|
@@ -601,14 +603,16 @@ class TreeService extends Service {
|
|
|
const childCount = parent ? await this.count(this.getCondition({mid: mid, pid: parent[this.setting.kid]})) : -1;
|
|
|
let deleteData = [];
|
|
|
for (const s of selects) {
|
|
|
- deleteData = deleteData.concat(await this.getDataByFullPath(mid, s[this.setting.fullPath] + '%'));
|
|
|
+ deleteData = deleteData.concat(await this.getDataByFullPath(mid, s[this.setting.fullPath] + '-%'));
|
|
|
+ deleteData.push(s);
|
|
|
}
|
|
|
|
|
|
this.transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
// 删除
|
|
|
+ await this.transaction.delete(this.tableName, { id: selects.map(x => { return x.id }) });
|
|
|
for (const s of selects) {
|
|
|
- const operate = await this._deleteNodeData(mid, s);
|
|
|
+ const operate = await this._deletePosterity(mid, s);
|
|
|
}
|
|
|
// 选中节点--父节点 只有一个子节点时,应升级isLeaf
|
|
|
if (parent && childCount === count) {
|
|
@@ -982,7 +986,7 @@ class TreeService extends Service {
|
|
|
let updateData = await this.getNextsData(mid, pre[this.setting.pid], pre[this.setting.order] - 1);
|
|
|
// 选中节点及子节点
|
|
|
for (const p of newPath) {
|
|
|
- updateData = updateData.concat(await this.getDataByFullPath(mid, p + '%'));
|
|
|
+ updateData = updateData.concat(await this.getDataByFullPath(mid, p + '-%'));
|
|
|
}
|
|
|
// 选中节点--原前兄弟节点&全部后兄弟节点
|
|
|
return { update: updateData };
|