From 9183b87dcdf29e61d83603ea24a7d1ee89d8eb6a Mon Sep 17 00:00:00 2001
From: polo <826770122@qq.com>
Date: Thu, 21 Dec 2023 15:17:43 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=BA=E5=91=98?=
=?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/member-select/Tpl.tsx | 21 +++
.../src/components/member-select/index.tsx | 129 ++++++++++++++++++
.../member-select/member-select.scss | 9 ++
src/dashboard-front-new/src/store/index.ts | 1 +
src/dashboard-front-new/src/store/staff.ts | 47 +++++++
src/dashboard-front-new/src/types/common.ts | 10 ++
src/dashboard-front-new/src/views/home.vue | 8 +-
src/dashboard-front-new/types/global.d.ts | 1 +
8 files changed, 220 insertions(+), 6 deletions(-)
create mode 100644 src/dashboard-front-new/src/components/member-select/Tpl.tsx
create mode 100644 src/dashboard-front-new/src/components/member-select/index.tsx
create mode 100644 src/dashboard-front-new/src/components/member-select/member-select.scss
create mode 100644 src/dashboard-front-new/src/store/staff.ts
diff --git a/src/dashboard-front-new/src/components/member-select/Tpl.tsx b/src/dashboard-front-new/src/components/member-select/Tpl.tsx
new file mode 100644
index 000000000..c6fbf3546
--- /dev/null
+++ b/src/dashboard-front-new/src/components/member-select/Tpl.tsx
@@ -0,0 +1,21 @@
+import { defineComponent } from 'vue';
+
+export default defineComponent({
+ props: {
+ englishName: {
+ type: String,
+ default: '',
+ },
+ chineseName: {
+ type: String,
+ default: '',
+ },
+ },
+ setup(props) {
+ return () => (
+
+ {props.englishName} ({props.chineseName})
+
+ );
+ },
+});
diff --git a/src/dashboard-front-new/src/components/member-select/index.tsx b/src/dashboard-front-new/src/components/member-select/index.tsx
new file mode 100644
index 000000000..8c22c19f3
--- /dev/null
+++ b/src/dashboard-front-new/src/components/member-select/index.tsx
@@ -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,
+ },
+ type: {
+ type: String as PropType,
+ 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 (
+
+ );
+ }
+ 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 () => (
+
+ {{
+ suffix: () => staffStore.fetching && (
+
+ ),
+ }}
+
+ );
+ },
+});
diff --git a/src/dashboard-front-new/src/components/member-select/member-select.scss b/src/dashboard-front-new/src/components/member-select/member-select.scss
new file mode 100644
index 000000000..2205e865f
--- /dev/null
+++ b/src/dashboard-front-new/src/components/member-select/member-select.scss
@@ -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;
+}
diff --git a/src/dashboard-front-new/src/store/index.ts b/src/dashboard-front-new/src/store/index.ts
index b18bf5448..3404be279 100644
--- a/src/dashboard-front-new/src/store/index.ts
+++ b/src/dashboard-front-new/src/store/index.ts
@@ -5,3 +5,4 @@ export * from './resourceVersion';
export * from './permission';
export * from './accessLog';
export * from './operate-records';
+export * from './staff';
diff --git a/src/dashboard-front-new/src/store/staff.ts b/src/dashboard-front-new/src/store/staff.ts
new file mode 100644
index 000000000..5fbaa4b9d
--- /dev/null
+++ b/src/dashboard-front-new/src/store/staff.ts
@@ -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);
+ },
+ },
+});
diff --git a/src/dashboard-front-new/src/types/common.ts b/src/dashboard-front-new/src/types/common.ts
index bc15a5a30..81ab35fde 100644
--- a/src/dashboard-front-new/src/types/common.ts
+++ b/src/dashboard-front-new/src/types/common.ts
@@ -29,3 +29,13 @@ export interface IDropList {
label: string
disabled?: boolean
}
+
+export enum StaffType {
+ RTX = 'rtx',
+}
+export interface Staff {
+ english_name: string;
+ chinese_name: string;
+ username: string;
+ display_name: string;
+}
diff --git a/src/dashboard-front-new/src/views/home.vue b/src/dashboard-front-new/src/views/home.vue
index 04d23e510..80a3a7389 100644
--- a/src/dashboard-front-new/src/views/home.vue
+++ b/src/dashboard-front-new/src/views/home.vue
@@ -147,12 +147,7 @@
property="maintainers"
required
>
-
+