-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 additions
and
6 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/dashboard-front-new/src/components/member-select/Tpl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineComponent } from 'vue'; | ||
|
||
export default defineComponent({ | ||
props: { | ||
englishName: { | ||
type: String, | ||
default: '', | ||
}, | ||
chineseName: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
setup(props) { | ||
return () => ( | ||
<div class="flex-row align-items-center flex-1 p10"> | ||
{props.englishName} ({props.chineseName}) | ||
</div> | ||
); | ||
}, | ||
}); |
129 changes: 129 additions & 0 deletions
129
src/dashboard-front-new/src/components/member-select/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { useStaffStore } from '@/store'; | ||
import { Staff, StaffType } from '@/types'; | ||
import { Loading, TagInput } from 'bkui-vue'; | ||
import { computed, defineComponent, onMounted, PropType, ref, watch, nextTick } from 'vue'; | ||
import _ from 'lodash'; | ||
|
||
import './member-select.scss'; | ||
import Tpl from './Tpl'; | ||
|
||
export default defineComponent({ | ||
props: { | ||
disabled: { | ||
type: Boolean, | ||
}, | ||
modelValue: { | ||
type: Array as PropType<string[]>, | ||
}, | ||
type: { | ||
type: String as PropType<StaffType>, | ||
default: StaffType.RTX, | ||
}, | ||
multiple: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
clearable: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
allowCreate: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
emits: ['change', 'input', 'blur'], | ||
setup(props, ctx) { | ||
const tagInputRef = ref(null); | ||
const staffStore = useStaffStore(); | ||
const searchKey = ['username']; | ||
const userList: any = ref([]); | ||
const maxData = computed(() => (!props.multiple ? { | ||
maxData: 1, | ||
} : {})); | ||
const popoverProps = { | ||
boundary: document.body, | ||
fixOnBoundary: true, | ||
}; | ||
|
||
onMounted(() => { | ||
if (staffStore.list.length === 0) { | ||
staffStore.fetchStaffs(); | ||
} | ||
}); | ||
|
||
function tpl(node: Staff) { | ||
return ( | ||
<Tpl | ||
englishName={node.username} | ||
chineseName={node.display_name} | ||
/> | ||
); | ||
} | ||
function handleChange(val: Staff[]) { | ||
ctx.emit('input', val); | ||
ctx.emit('change', val); | ||
} | ||
|
||
function handleBlur(val: Staff[]) { | ||
ctx.emit('blur', val); | ||
} | ||
|
||
const getUserList = _.debounce((userName: string) => { | ||
if (staffStore.fetching || !userName) return; | ||
staffStore.fetchStaffs(userName); | ||
}, 500); | ||
|
||
function handleInput(userName: string) { | ||
getUserList(userName); | ||
} | ||
|
||
watch( | ||
() => staffStore.list, | ||
(list) => { | ||
if (list.length) { | ||
nextTick(() => { | ||
userList.value = _.cloneDeep(list); | ||
}); | ||
} | ||
}, | ||
{ immediate: true, deep: true }, | ||
); | ||
|
||
return () => ( | ||
<TagInput | ||
{...ctx.attrs} | ||
{...maxData.value} | ||
// disabled={props.disabled || staffStore.fetching} | ||
list={userList} | ||
ref={tagInputRef} | ||
displayKey="display_name" | ||
saveKey="username" | ||
is-async-list | ||
searchKey={searchKey} | ||
// filterCallback={handleSearch} | ||
modelValue={props.modelValue} | ||
onChange={handleChange} | ||
onBlur={handleBlur} | ||
onInput={handleInput} | ||
tpl={tpl} | ||
tagTpl={tpl} | ||
clearable={props.clearable} | ||
allowCreate={props.allowCreate} | ||
popoverProps={popoverProps} | ||
> | ||
{{ | ||
suffix: () => staffStore.fetching && ( | ||
<Loading | ||
class="mr10" | ||
loading={staffStore.fetching} | ||
mode="spin" | ||
size="mini" | ||
|
||
/> | ||
), | ||
}} | ||
</TagInput> | ||
); | ||
}, | ||
}); |
9 changes: 9 additions & 0 deletions
9
src/dashboard-front-new/src/components/member-select/member-select.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.bk-metrics-staff-li { | ||
height: 40px; | ||
} | ||
.bk-metrics-staff-memeber-pic { | ||
width: 20px; | ||
height: 20px; | ||
border-radius: 50%; | ||
margin: 0 6px 0 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// @ts-check | ||
import { defineStore } from 'pinia'; | ||
import QueryString from 'qs'; | ||
import { shallowRef } from 'vue'; | ||
import _ from 'lodash'; | ||
const { BK_LIST_USERS_API_URL } = window; | ||
|
||
|
||
export const useStaffStore = defineStore({ | ||
id: 'staffStore', | ||
state: () => ({ | ||
fetching: false, | ||
list: shallowRef([]), | ||
}), | ||
actions: { | ||
async fetchStaffs(name?: string) { | ||
if (this.fetching) return; | ||
this.fetching = true; | ||
const usersListPath = `${BK_LIST_USERS_API_URL}`; | ||
const params: any = { | ||
app_code: 'bk-magicbox', | ||
page: 1, | ||
page_size: 200, | ||
callback: 'callbackStaff', | ||
}; | ||
if (name) { | ||
params.fuzzy_lookups = name; | ||
} | ||
const scriptTag = document.createElement('script'); | ||
scriptTag.setAttribute('type', 'text/javascript'); | ||
scriptTag.setAttribute('src', `${usersListPath}?${QueryString.stringify(params)}`); | ||
|
||
const headTag = document.getElementsByTagName('head')[0]; | ||
// @ts-ignore | ||
window[params.callback] = ({ data, result }: { data: any, result: boolean }) => { | ||
if (result) { | ||
this.fetching = false; | ||
this.list = _.unionBy(this.list, data.results, 'id'); | ||
} | ||
headTag.removeChild(scriptTag); | ||
// @ts-ignore | ||
delete window[params.callback]; | ||
}; | ||
headTag.appendChild(scriptTag); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters