PersonalProfile.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <script setup lang="ts">
  2. import dayjs from 'dayjs'
  3. import { isEuropean, getDateFormat } from '@/utils/tools'
  4. import ChangePasswordDialog from '@/views/Layout/src/components/Header/components/ChangePasswordDialog.vue'
  5. import { useUserStore } from '@/stores/modules/user'
  6. import { useThemeStore } from '@/stores/modules/theme'
  7. const themeStore = useThemeStore()
  8. const userStore = useUserStore()
  9. const form = reactive({
  10. firstName: userStore.userInfo?.first_name,
  11. lastName: userStore.userInfo?.last_name,
  12. username: userStore.userInfo?.uname,
  13. email: userStore.userInfo?.email,
  14. password: '**************'
  15. })
  16. const segmented = ref('dateTime')
  17. const handleSegmented = (type: string) => {
  18. segmented.value = type
  19. }
  20. const changePasswordDialogRef = ref()
  21. const handleChangePassword = () => {
  22. changePasswordDialogRef.value.openDialog()
  23. }
  24. const monthMap = {
  25. 'MMM/DD/YYYY': 'MM/DD/YYYY',
  26. 'DD/MMM/YYYY': 'DD/MM/YYYY',
  27. 'YYYY-MMM-DD': 'YYYY-MM-DD'
  28. }
  29. const dateFormat = ref(monthMap[userStore.dateFormat] || userStore.dateFormat)
  30. const monthFormat = ref(userStore.dateFormat)
  31. const dateFormatExample = computed(() => {
  32. return {
  33. 'MM/DD/YYYY': [
  34. {
  35. label: dayjs().format('MM/DD/YYYY'),
  36. value: 'MM/DD/YYYY'
  37. },
  38. {
  39. label: dayjs().format('MMM/DD/YYYY'),
  40. value: 'MMM/DD/YYYY'
  41. }
  42. ],
  43. 'DD/MM/YYYY': [
  44. {
  45. label: dayjs().format('DD/MM/YYYY'),
  46. value: 'DD/MM/YYYY'
  47. },
  48. {
  49. label: dayjs().format('DD/MMM/YYYY'),
  50. value: 'DD/MMM/YYYY'
  51. }
  52. ],
  53. 'YYYY-MM-DD': [
  54. {
  55. label: dayjs().format('YYYY-MM-DD'),
  56. value: 'YYYY-MM-DD'
  57. },
  58. {
  59. label: dayjs().format('YYYY-MMM-DD'),
  60. value: 'YYYY-MMM-DD'
  61. }
  62. ]
  63. }
  64. })
  65. const handleDateFormat = (value: string) => {
  66. monthFormat.value = dateFormatExample.value[value][0].value
  67. }
  68. const initNumbersFormat = () => {
  69. return userStore.userInfo?.numbers_format || (isEuropean() ? 'European' : 'US/UK')
  70. }
  71. const numbersFormat = ref(initNumbersFormat())
  72. const loading = ref(false)
  73. const saveConfig = (model: string) => {
  74. loading.value = true
  75. let params = {}
  76. if (model === 'profile') {
  77. params = {
  78. save_model: 'profile',
  79. first_name: form.firstName,
  80. last_name: form.lastName
  81. }
  82. } else {
  83. params = {
  84. save_model: 'no_profile',
  85. date_format: monthFormat.value,
  86. numbers_format: numbersFormat.value
  87. }
  88. }
  89. $api
  90. .saveUserInfo(params)
  91. .then((res: any) => {
  92. if (res.code === 200) {
  93. const updatedInfo =
  94. model === 'profile'
  95. ? {
  96. ...userStore.userInfo,
  97. first_name: form.firstName,
  98. last_name: form.lastName
  99. }
  100. : {
  101. ...userStore.userInfo,
  102. date_format: monthFormat.value,
  103. numbers_format: numbersFormat.value
  104. }
  105. userStore.setUserInfo(updatedInfo)
  106. ElMessage.success('Save successfully')
  107. } else {
  108. ElMessage.error('Save failed')
  109. }
  110. })
  111. .finally(() => {
  112. loading.value = false
  113. })
  114. }
  115. </script>
  116. <template>
  117. <div class="personal-profile" v-vloading="loading">
  118. <div class="basic-information">
  119. <div class="title">Basic Information</div>
  120. <div class="content">
  121. <div class="row">
  122. <div class="item">
  123. <p class="label">First Name</p>
  124. <el-input size="large" v-model="form.firstName" placeholder="Please enter..." />
  125. </div>
  126. <div class="item">
  127. <p class="label">Last Name</p>
  128. <el-input size="large" v-model="form.lastName" placeholder="Please enter..." />
  129. </div>
  130. </div>
  131. <div class="row">
  132. <div class="item">
  133. <p class="label">User Name</p>
  134. <el-input size="large" :disabled="true" v-model="form.username" />
  135. </div>
  136. <div class="item">
  137. <p class="label">Email</p>
  138. <el-input size="large" :disabled="true" v-model="form.email" />
  139. </div>
  140. </div>
  141. <div class="row">
  142. <div class="item">
  143. <p class="label">
  144. Password
  145. <span style="margin: 0 2px 0 8px" class="font_family icon-icon_time_b"></span>
  146. <span>Your password will be expire in</span>
  147. <span style="margin-left: 4px; color: var(--color-theme)"
  148. >{{ userStore.expireDay }} day(s)</span
  149. >
  150. </p>
  151. <div class="password-change">
  152. <el-input
  153. size="large"
  154. type="password"
  155. style="width: 330px"
  156. :disabled="true"
  157. v-model="form.password"
  158. />
  159. <el-button
  160. @click="handleChangePassword"
  161. class="el-button--main el-button--pain-theme"
  162. plain
  163. size="large"
  164. >Change Password</el-button
  165. >
  166. </div>
  167. </div>
  168. </div>
  169. <div class="row">
  170. <el-button @click="saveConfig('profile')" class="el-button--dark save-icon" size="large"
  171. >Save</el-button
  172. >
  173. </div>
  174. </div>
  175. </div>
  176. <div class="personal-preferences">
  177. <div class="title">Personal Preferences</div>
  178. <div class="segmented">
  179. <div
  180. style="width: 121px"
  181. :class="{ 'is-active': segmented === 'dateTime' }"
  182. @click="handleSegmented('dateTime')"
  183. class="item"
  184. >
  185. Date & Time
  186. </div>
  187. <div
  188. style="width: 162px"
  189. :class="{ 'is-active': segmented === 'numbersFormat' }"
  190. @click="handleSegmented('numbersFormat')"
  191. class="item"
  192. >
  193. Numbers Format
  194. </div>
  195. </div>
  196. <div class="date-format" v-if="segmented === 'dateTime'">
  197. <div class="title">Date Format</div>
  198. <div class="content">
  199. <el-radio-group v-model="dateFormat" label="string" @change="handleDateFormat">
  200. <el-row>
  201. <el-col v-for="(list, key) in dateFormatExample" :key="key">
  202. ><el-radio :value="key">
  203. <template #default>
  204. <span>{{ key }}</span>
  205. <el-select
  206. style="margin-left: 28px; width: 320px"
  207. v-if="dateFormat === key"
  208. size="large"
  209. v-model="monthFormat"
  210. >
  211. <el-option
  212. v-for="item in list"
  213. :key="item.value"
  214. :label="item.label"
  215. :value="item.value"
  216. ></el-option>
  217. </el-select>
  218. </template>
  219. </el-radio>
  220. </el-col>
  221. <el-col>
  222. <el-button
  223. @click="saveConfig('no_profile')"
  224. style="padding: 0 40px"
  225. class="el-button--dark save-icon"
  226. size="large"
  227. >Save</el-button
  228. >
  229. </el-col>
  230. </el-row>
  231. </el-radio-group>
  232. </div>
  233. </div>
  234. <div class="numbers-format" v-if="segmented === 'numbersFormat'">
  235. <div class="title">Numbers Format</div>
  236. <div class="content">
  237. <el-radio-group v-model="numbersFormat" label="string">
  238. <el-row>
  239. <el-col
  240. ><el-radio value="US/UK">
  241. <template #default>
  242. <span>1,234.56 (US/UK)</span>
  243. </template>
  244. </el-radio></el-col
  245. >
  246. <el-col
  247. ><el-radio value="European">
  248. <template #default>
  249. <span>1.234,56 (European)</span>
  250. </template>
  251. </el-radio></el-col
  252. >
  253. <el-col>
  254. <el-button
  255. @click="saveConfig('no_profile')"
  256. style="padding: 0 40px"
  257. class="el-button--dark save-icon"
  258. size="large"
  259. >Save</el-button
  260. >
  261. </el-col>
  262. </el-row>
  263. </el-radio-group>
  264. </div>
  265. </div>
  266. </div>
  267. <ChangePasswordDialog ref="changePasswordDialogRef"></ChangePasswordDialog>
  268. </div>
  269. </template>
  270. <style scoped lang="scss">
  271. .personal-profile {
  272. padding: 24px;
  273. padding-top: 9px;
  274. .basic-information,
  275. .personal-preferences {
  276. border: 1px solid var(--color-border);
  277. border-radius: 12px;
  278. padding: 16px 16px 32px;
  279. & > .title {
  280. margin-bottom: 21px;
  281. font-size: 18px;
  282. font-weight: 700;
  283. }
  284. }
  285. }
  286. .basic-information {
  287. .content {
  288. .row {
  289. display: flex;
  290. gap: 8px;
  291. .item {
  292. flex: 1;
  293. margin-bottom: 16px;
  294. .label {
  295. margin-bottom: 4px;
  296. font-size: 12px;
  297. color: var(--color-neutral-2);
  298. & > span {
  299. font-size: 12px;
  300. color: var(--color-neutral-3);
  301. }
  302. }
  303. .password-change {
  304. display: flex;
  305. gap: 8px;
  306. }
  307. }
  308. }
  309. .save-icon {
  310. margin-top: 16px;
  311. padding: 0 40px;
  312. }
  313. }
  314. }
  315. .personal-profile {
  316. div.personal-preferences {
  317. margin-top: 16px;
  318. padding-bottom: 8px;
  319. .segmented {
  320. width: 291px;
  321. height: 40px;
  322. margin-bottom: 8px;
  323. padding: 4px;
  324. border-radius: 12px;
  325. background-color: var(--color-personal-preference-bg);
  326. .item {
  327. display: inline-block;
  328. height: 32px;
  329. line-height: 32px;
  330. font-weight: 700;
  331. font-size: 16px;
  332. text-align: center;
  333. border-radius: 6px;
  334. color: var(--color-neutral-2);
  335. cursor: pointer;
  336. &.is-active {
  337. background-color: var(--color-table-stripe-bg);
  338. color: var(--color-neutral-1);
  339. }
  340. }
  341. }
  342. .date-format,
  343. .numbers-format {
  344. padding: 0px 16px 32px;
  345. background-color: var(--color-personal-preference-bg);
  346. border-radius: 12px;
  347. .title {
  348. height: 40px;
  349. font-size: 14px;
  350. font-weight: 700;
  351. line-height: 40px;
  352. }
  353. .el-col {
  354. margin-bottom: 8px;
  355. &:last-child {
  356. margin-bottom: 0;
  357. margin-top: 32px;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. </style>