Skip to content

Commit

Permalink
feat: 完善联动组件下的disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Qymh committed Dec 26, 2019
1 parent 268bfdc commit 35954aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ const data5 = [
children: [
{
value: '猪肉',
disabled: true,
children: [
{
value: '前腿肉'
Expand Down
47 changes: 30 additions & 17 deletions packages/@qymh/q-select/src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,30 @@ class Layer {
);
}

/**
* 获取disabled后的索引
* @param data 当前转换值
* @param index 索引
*/
getDisabledAfterIndex(data: DataTrans[], index: number) {
if (!data || !data[index]) {
return index;
}
while (data[index].disabled) {
index++;
if (index === this.data.length) {
index--;
break;
}
}
if (index === this.data.length - 1) {
while (data[index].disabled) {
index--;
}
}
return index;
}

/**
* 格式化index
* @param dataTransLater 之后的数据
Expand All @@ -329,22 +353,10 @@ class Layer {
this.index[i] = len - 1;
}
}
let index = this.index[i];
if (this.dataTrans[i]) {
while (this.dataTrans[i][index].disabled) {
index++;
if (index === this.dataTrans[i].length) {
index--;
break;
}
}
if (index === this.dataTrans[i].length - 1) {
while (this.dataTrans[i][index].disabled) {
index--;
}
}
}
this.index[i] = index;
this.index[i] = this.getDisabledAfterIndex(
this.dataTrans[i],
this.index[i]
);
return v;
});
const lenDiff = this.index.length - dataTransLater.length;
Expand Down Expand Up @@ -898,7 +910,8 @@ class Layer {
delete obj.children;
dataTrans[index].push(obj as DataTrans);
}
const curIndex = (preciseIndex || [])[index] || 0;
let curIndex = (preciseIndex || [])[index] || 0;
curIndex = this.getDisabledAfterIndex(dataTrans[index], curIndex);
index++;
if (child[curIndex]) {
if (child[curIndex].children.length) {
Expand Down
3 changes: 3 additions & 0 deletions packages/@qymh/q-select/types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ export type NotGangedData<K, V> =
export type NotGangedDataObj<K, V> = {
key?: K;
value: V;
disabled?: boolean;
};

export type GangedData<K, V> = {
key?: K;
value: V;
disabled?: boolean;
children: GangedData<K, V>[] | Array<string | number>;
};

export type DataCallBack<K, V> = {
key: K;
value: V;
disabled?: boolean;
index: number;
};

Expand Down
3 changes: 3 additions & 0 deletions packages/@qymh/vue-q-select/types/component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ export type NotGangedData<K, V> =
export type NotGangedDataObj<K, V> = {
key?: K;
value: V;
disabled?: boolean;
};

export type GangedData<K, V> = {
key?: K;
value: V;
disabled?: boolean;
children: GangedData<K, V>[] | Array<string | number>;
};

export type DataCallBack<K, V> = {
key: K;
value: V;
disabled?: boolean;
index: number;
};

Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare interface DataCallback extends DataTrans {

declare type GangedData = {
key?: any;
disabled?: boolean;
value: any;
children: GangedData[];
};
Expand Down

0 comments on commit 35954aa

Please sign in to comment.