settingModal.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <v-dialog
  3. v-model="props.isSettingModal"
  4. persistent
  5. width="91.875rem"
  6. >
  7. <div class="v-common-dialog-wrapper custom-dialog alert">
  8. <div class="modal-tit">
  9. <strong>Dashborad</strong>
  10. <button
  11. class="btn-close"
  12. @click="fnClose()"
  13. />
  14. </div>
  15. <div class="v-common-dialog-content type--z">
  16. <div class="dash--set--contents">
  17. <div class="set--list">
  18. <!-- 왼쪽 배열 리스트 : S -->
  19. <div class="left--cell">
  20. <v-radio-group
  21. v-model="layoutType"
  22. class="custom-radio"
  23. @change="fnLayoutChange"
  24. >
  25. <v-radio
  26. v-for="(item, index) in layoutTypeList"
  27. :key="index"
  28. :label="item.value"
  29. :value="item.value"
  30. class="radio_n"
  31. >
  32. <template #label>
  33. <div class="db--list--set--wrap">
  34. <h2>{{ item.name }}</h2>
  35. <div :class="item.class" />
  36. </div>
  37. </template>
  38. </v-radio>
  39. </v-radio-group>
  40. </div>
  41. <!-- 왼쪽 배열 리스트 : E -->
  42. <!-- 오른쪽 디테일 리스트 : S -->
  43. <div class="right--cell">
  44. <div>
  45. <h2>{{ fnGetLayoutTypeInfo('name') }}</h2>
  46. <div class="dashboard--detail--contents">
  47. <div class="detail--list">
  48. <div
  49. v-for="(type, index) in fnGetLayoutTypeInfo('sort')"
  50. :key="`${type}-${index}`"
  51. >
  52. <h2>{{ fnGetLayoutTypeInfo(type) }}</h2>
  53. <div class="group--wrapper">
  54. <v-radio-group
  55. v-model="widgetType[type]"
  56. class="custom-radio"
  57. >
  58. <v-radio
  59. v-for="(widgets, idx) in widgetDetails[type]"
  60. :key="`${type}-widget-${idx}`"
  61. :label="widgets.widgetId"
  62. :value="widgets.widgetId"
  63. class="radio_n"
  64. >
  65. <template #label>
  66. <div class="db--detail--list--set--wrap size--14">
  67. <h2>{{ widgets.widgetName }}</h2>
  68. <div class="db--set--01 size--v--box">
  69. {{ widgets.widgetName }} Image
  70. </div>
  71. </div>
  72. </template>
  73. </v-radio>
  74. </v-radio-group>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <!-- 오른쪽 디테일 리스트 : E -->
  82. </div>
  83. </div>
  84. </div>
  85. <div class="btn-wrap nw--btn--wrap">
  86. <div />
  87. <div class="inner--btn--wrap">
  88. <v-btn
  89. class="custom-btn btn-white mini"
  90. @click="fnClose()"
  91. >
  92. <i class="ico" />
  93. 취소
  94. </v-btn>
  95. <v-btn
  96. class="custom-btn btn-blue mini"
  97. @click="fnSaveDashboardSetting()"
  98. >
  99. <i class="ico" />
  100. 확인
  101. </v-btn>
  102. </div>
  103. </div>
  104. </div>
  105. </v-dialog>
  106. </template>
  107. <script setup>
  108. /***********************
  109. * import
  110. ************************/
  111. import apiUrl from '@/composables/useApi';
  112. import useAxios from '@/composables/useAxios';
  113. import { useI18n } from "vue-i18n";
  114. /***********************
  115. * plugins inject
  116. ************************/
  117. const { $toast, $log, $dayjs, $eventBus } = useNuxtApp()
  118. // props
  119. const props = defineProps({
  120. isSettingModal: Boolean,
  121. })
  122. // 참조가능 데이터 설정
  123. defineExpose({
  124. fnInit,
  125. })
  126. // 발신 이벤트 선언
  127. const emit = defineEmits(["closeModal"]);
  128. const i18n = useI18n();
  129. /***********************
  130. * data & created
  131. ************************/
  132. // Layout 목록
  133. const layoutTypeList = ref([
  134. {name: 'Dashboard #1', value: 'LAYOUT01', class: 'db--set--01', sort: ['CORE', 'USER', 'RANE'], CORE: 'CORE (12 X 14)', USER: '가입자 (12 X 10)', RANE: 'RAN (12 X 24)'},
  135. {name: 'Dashboard #2', value: 'LAYOUT02', class: 'db--set--02', sort: ['CORE', 'USER', 'RANE'], CORE: 'CORE (12 X 12)', USER: '가입자 (12 X 12)', RANE: 'RAN (24 X 12)'},
  136. {name: '현황판', value: 'LAYOUT03', class: 'db--set--03', sort: ['CORE', 'RANE', 'USER'], CORE: 'CORE (6 X 24)', USER: '가입자 (6 X 24)', RANE: 'RAN (12 X 24)'},
  137. ]);
  138. // 사용자 위젯 정보
  139. const userDashType = computed(() => useAuthStore().getDashType || layoutGroupList[0].value);
  140. // 사용자 위젯 정보
  141. const userWidget = computed(() => useAuthStore().getWidgets || [])
  142. // 레이아웃별 위젯 목록 (전체 목록)
  143. const widgetDetails = ref({
  144. CORE: [],
  145. USER: [],
  146. RANE: [],
  147. });
  148. // 레이아웃 타입
  149. const layoutType = ref();
  150. // 위젯 타입
  151. const widgetType = ref({
  152. CORE: '',
  153. USER: '',
  154. RANE: '',
  155. });
  156. /***********************
  157. * Methods
  158. ************************/
  159. /** 모달 시작 */
  160. function fnInit() {
  161. //레이아웃 기본값 셋팅
  162. layoutType.value = useAuthStore().getDashType || layoutGroupList[0].value;
  163. fnGetDashboardWidgetList(layoutType.value);
  164. }
  165. /** 모달 닫기 */
  166. function fnClose(isReload = false) {
  167. fnReset()
  168. emit('closeModal', {isReload: isReload})
  169. }
  170. /** 데이터 초기화 */
  171. function fnReset() {
  172. widgetDetails.value = {
  173. CORE: [],
  174. USER: [],
  175. RANE: [],
  176. }
  177. widgetType.value = {
  178. CORE: '',
  179. USER: '',
  180. RANE: '',
  181. }
  182. }
  183. /** 레이아웃 선택 */
  184. function fnLayoutChange() {
  185. fnGetDashboardWidgetList(layoutType.value)
  186. }
  187. /** 레이아웃 정보 가져오기 from layoutTypeList */
  188. function fnGetLayoutTypeInfo(key, type) {
  189. if(!type) type = layoutType.value;
  190. const layout = layoutTypeList.value.find((item) => item.value == type);
  191. return layout ? (layout[key] || '') : '';
  192. }
  193. /** 사용자 지정 위젯 정보 가져오기 from userWidget */
  194. function fnGetUserWidgetInfo(key, type) {
  195. const widget = userWidget.value.find((item) => item.widgetGrp == type);
  196. return widget ? (widget[key] || '') : '';
  197. }
  198. /** 위젯 리스트 조회 (전체 리스트) */
  199. function fnGetDashboardWidgetList(type) {
  200. fnReset();
  201. const params = {layoutType: type}
  202. useAxios().get(apiUrl.getDashboardWidgetList, {params: params}).then((res) => {
  203. if(res.data.resCode === '200') {
  204. const widgets = res?.data?.data || [];
  205. // 타입별 Object 생성
  206. if(widgets && widgets.length > 0) {
  207. widgetDetails.value = widgets.reduce((acc, cur, idx) => {
  208. const { widgetGrp } = cur;
  209. if(acc[widgetGrp]) acc[widgetGrp].push(cur);
  210. else acc[widgetGrp] = [cur];
  211. // 기본값 셋팅
  212. if(cur.defaultYN == 'Y') {
  213. widgetType.value[cur.widgetGrp] = cur.widgetId;
  214. }
  215. return acc;
  216. }, {})
  217. }
  218. // 선택한 레이아웃이 사용자지정 레이아웃인 경우 사용자가 선택한 값으로 기본값 셋팅
  219. if(type == userDashType.value) {
  220. widgetType.value.CORE = fnGetUserWidgetInfo('widgetId', 'CORE');
  221. widgetType.value.USER = fnGetUserWidgetInfo('widgetId', 'USER');
  222. widgetType.value.RANE = fnGetUserWidgetInfo('widgetId', 'RANE');
  223. }
  224. }
  225. $log.debug("[settingModal][fnGetTenantList][success]")
  226. }).catch((error)=>{
  227. $log.debug("[settingModal][fnGetDashboardWidgetList][error]")
  228. useErrorHandler().fnSetCommErrorHandle(error, fnGetDashboardWidgetList)
  229. }).finally(()=>{
  230. $log.debug("[settingModal][fnGetDashboardWidgetList][finished]")
  231. })
  232. }
  233. function fnSaveDashboardSetting() {
  234. const params = {
  235. dashType: layoutType.value,
  236. widgets: [
  237. {
  238. areaType: 'AREA01', widgetId: widgetType.value.CORE
  239. },
  240. {
  241. areaType: layoutType.value == 'LAYOUT03' ? 'AREA03' : 'AREA02', widgetId: widgetType.value.USER
  242. },
  243. {
  244. areaType: layoutType.value == 'LAYOUT03' ? 'AREA02' : 'AREA03', widgetId: widgetType.value.RANE
  245. },
  246. ]
  247. }
  248. useAxios().post(apiUrl.myInfoUpdate, params).then((res) => {
  249. $toast.success(i18n.t('common.updateSuccessMsg'))
  250. useAuthStore().setDashType(layoutType.value);
  251. const authWidget = Object.keys(widgetType.value).map((type) => {
  252. const widgetId = widgetType.value[type];
  253. const widgetDetail = widgetDetails.value[type].find((w) => w.widgetId == widgetId);
  254. const param = params.widgets.find((w) => w.widgetId == widgetId);
  255. return {
  256. accountId: useAuthStore().getAccountId,
  257. areaType: param.areaType,
  258. widgetGrp: type,
  259. widgetId: widgetId,
  260. widgetName: widgetDetail.widgetName,
  261. widgetSize: widgetDetail.widgetSize,
  262. widgetWh: widgetDetail.widgetWh
  263. }
  264. })
  265. useAuthStore().setWidgetsUpdate(authWidget);
  266. fnClose(true);
  267. $log.debug("[settingModal][fnSaveDashboardSetting][success]")
  268. }).catch((error)=>{
  269. $log.debug("[settingModal][fnSaveDashboardSetting][error]", error)
  270. useErrorHandler().fnSetCommErrorHandle(error, fnSaveDashboardSetting)
  271. }).finally(()=>{
  272. $log.debug("[settingModal][fnSaveDashboardSetting][finished]")
  273. })
  274. }
  275. </script>