PersonalProfile.vue 10 KB

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