jobdone-shared-files 1.0.53 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,196 @@
1
+ <template>
2
+ <div class="input-content">
3
+ <div class="user-pick-autocomplete-select-box-group">
4
+ <div class="user-pick-autocomplete-select-box">
5
+ <autocomplete-select
6
+ :trigger-class="`${organSelectClass} ${organInvalid && !organPicked?.organId ? 'is-invalid' : ''}`"
7
+ :clear-btn="clearBtn" :opts="optsAdjust" preview-key="organName" :filter-keys="['organName']"
8
+ :selected-data="organPicked" placeholder="所屬公司 / 協力廠商 / 專案成員" searchPlaceholder="文字篩選"
9
+ @select="(v) => selectOrgan(v)" :reset-value="defaultOrgan" />
10
+ <small class="text-danger mt-1" v-if="organInvalid && !organPicked?.organId">必填</small>
11
+ </div>
12
+ <div class="user-pick-autocomplete-select-box">
13
+ <autocomplete-select ref="userPicker" :trigger-class="`${userSelectClass} ${userInvalid && !userPicked?.userId ? 'is-invalid' : ''}`"
14
+ :opts="organPickedUsers"
15
+ :clear-btn="clearBtn" :disabled="!organPicked?.organId"
16
+ :preview-key="userPicked.userId ? `displayName + ' ( ' + lastName +' ' + firstName + ' ) ' + '( 電話: ' + phoneNumber + ' )'` : 'displayName'"
17
+ :filter-keys="['displayName', 'firstName', 'lastName', 'phoneNumber']" :selected-data="userPicked"
18
+ :placeholder="organPicked?.organId ? '選擇受文者' : '請先選擇受文者所屬公司 / 協力廠商 / 專案成員'"
19
+ searchPlaceholder="文字篩選名稱 / 電話" @select="(v) => selectUser(v)" :reset-value="defaultUser"
20
+ opt-class="border-bottom" :html-option='true'>
21
+ <template #option="{ optData }">
22
+ <small class="text-gray-500">
23
+ {{ optData.phoneNumber }}
24
+ </small>
25
+ <div>
26
+ {{ optData.displayName }} ( {{ optData.lastName }} {{ optData.firstName }} )
27
+ </div>
28
+ </template>
29
+ </autocomplete-select>
30
+ <small class="text-danger mt-1" v-if="userInvalid && !userPicked?.userId">必填</small>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </template>
35
+ <script setup>
36
+ import { computed, ref, reactive, nextTick } from "vue"
37
+ import { renewReactiveAry } from "./common/helper.js"
38
+ import autocompleteSelect from "./autocompleteSelect.vue";
39
+
40
+ const emit = defineEmits(['selectUser', 'resetSelected'])
41
+ const props = defineProps({
42
+ opts: {
43
+ type: Array,
44
+ default: []
45
+ },
46
+ clearBtn: {
47
+ type: Boolean,
48
+ default: true
49
+ },
50
+ organInvalid: {
51
+ type: Boolean,
52
+ default: false
53
+ },
54
+ userInvalid: {
55
+ type: Boolean,
56
+ default: false
57
+ },
58
+ organSelectClass: {
59
+ type: String,
60
+ default: ''
61
+ },
62
+ userSelectClass: {
63
+ type: String,
64
+ default: ''
65
+ }
66
+ })
67
+
68
+ const optsAdjust = computed((rowOpts = props.opts || []) => {
69
+ let ary = rowOpts.map(i => {
70
+ return {
71
+ organName: i.organization?.name || '無所屬公司',
72
+ organId: i.organization?.id || `fakeId_${crypto.randomUUID()}`,
73
+ users: i.users || [],
74
+ }
75
+ })
76
+ return ary || []
77
+ })
78
+ const resetSelected = () => {
79
+ selectOrgan(defaultOrgan)
80
+ selectUser(defaultUser)
81
+ renewReactiveAry(organPickedUsers, [])
82
+ }
83
+ const setOrganSelectFirst = () => {
84
+ selectOrgan(optsAdjust.value[0] || defaultOrgan)
85
+ }
86
+ const setSelected = (userId) => {
87
+ if (!userId) {
88
+ resetSelected()
89
+ return
90
+ }
91
+ let userIdList = optsAdjust.value.flatMap(i => i.users.map(item => (
92
+ {
93
+ ...item,
94
+ organization: {
95
+ organName: i.organName,
96
+ organId: i.organId,
97
+ users: i.users
98
+ }
99
+ }
100
+ ))) || []
101
+ let user = userIdList.find(i => i.userId == userId)
102
+ if (!user) {
103
+ resetSelected()
104
+ return
105
+ }
106
+ selectOrgan(user.organization)
107
+ selectUser(user, true)
108
+ }
109
+
110
+ const defaultOrgan = {
111
+ organName: '',
112
+ organId: '',
113
+ users: []
114
+ }
115
+
116
+ const defaultUser = {
117
+ employeeId: null,
118
+ userId: null,
119
+ account: "",
120
+ phoneNumber: "",
121
+ email: "",
122
+ firstName: "",
123
+ lastName: "",
124
+ displayName: "",
125
+ picture: "",
126
+ isAdmin: false,
127
+ permission: 0,
128
+ organizationId: "",
129
+ organizationName: "",
130
+ organizationLocation: "",
131
+ organizationLicenseNo: "",
132
+ organizationIndustryType: "",
133
+ organizationDescription: "",
134
+ organizationLogoUrl: "",
135
+ fullName: ""
136
+ }
137
+
138
+ const organPicked = reactive({ ...defaultOrgan })
139
+ const organPickedUsers = reactive([])
140
+ const selectOrgan = (organ) => {
141
+ organPicked.organName = organ.organName
142
+ organPicked.organId = organ.organId
143
+ renewReactiveAry(organPickedUsers, organ.users)
144
+ selectUser(defaultUser)
145
+ }
146
+
147
+ const userPicker = ref(null)
148
+ const userPicked = reactive({ ...defaultUser })
149
+ const selectUser = async (userInfo, isSetSelected = false) => {
150
+ if (!userInfo) {
151
+ return
152
+ }
153
+ userPicked.employeeId = userInfo.employeeId;
154
+ userPicked.userId = userInfo.userId;
155
+ userPicked.account = userInfo.account;
156
+ userPicked.phoneNumber = userInfo.phoneNumber;
157
+ userPicked.email = userInfo.email;
158
+ userPicked.firstName = userInfo.firstName;
159
+ userPicked.lastName = userInfo.lastName;
160
+ userPicked.displayName = userInfo.displayName;
161
+ userPicked.displayName = userInfo.displayName;
162
+ userPicked.picture = userInfo.picture;
163
+ userPicked.isAdmin = userInfo.isAdmin;
164
+ userPicked.permission = userInfo.permission;
165
+ userPicked.organizationId = userInfo.organization?.id || '';
166
+ userPicked.organizationName = userInfo.organization?.name || '';
167
+ userPicked.organizationLocation = userInfo.organization?.location || '';
168
+ userPicked.organizationLicenseNo = userInfo.organization?.licenseNo || '';
169
+ userPicked.organizationIndustryType = userInfo.organization?.industryType || '';
170
+ userPicked.organizationIndustryType = userInfo.organization?.description || '';
171
+ userPicked.organizationIndustryType = userInfo.organization?.logoUrl || '';
172
+ userPicked.fullName = userInfo.fullName;
173
+ await nextTick()
174
+ emit('selectUser', userPicked)
175
+ };
176
+ defineExpose({ setSelected, resetSelected, setOrganSelectFirst })
177
+ </script>
178
+ <style lang="scss" scoped>
179
+ .input-content {
180
+ display: flex;
181
+ flex: 1;
182
+ gap: .5rem;
183
+ align-self: baseline;
184
+ flex-direction: column;
185
+ }
186
+
187
+ .user-pick-autocomplete-select-box {
188
+ display: block;
189
+ }
190
+
191
+ .user-pick-autocomplete-select-box-group {
192
+ display: grid;
193
+ gap: .5rem;
194
+ grid-template-columns: 1fr 2fr;
195
+ }
196
+ </style>
@@ -0,0 +1,12 @@
1
+ export const renewReactiveAry = (rowData, newData) => {
2
+ if (rowData?.length > 0) {
3
+ rowData.splice(0, rowData.length)
4
+ }
5
+ if (newData?.length > 0) {
6
+ let newD = JSON.parse(JSON.stringify(newData))
7
+ newD.forEach(element => {
8
+ rowData.push(element)
9
+ });
10
+ }
11
+
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jobdone-shared-files",
3
- "version": "1.0.53",
3
+ "version": "1.1.0",
4
4
  "description": "Shared JS and SCSS for Jobdone Enterprise.",
5
5
  "main": "index.js",
6
6
  "scripts": {