Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
 
 
 
 
 
 

127 satır
2.8 KiB

  1. <template>
  2. <div class="page">
  3. <h2>Settings</h2>
  4. <section class="form inputs">
  5. <h3>Avatar</h3>
  6. <canvas class="displayer" width="200" height="200" ref="canvas"></canvas>
  7. <input type="file"
  8. @change="e => uploadAvatar(e.target.files[0])"
  9. />
  10. <button>Upload</button>
  11. <label class="error">{{avatarError}}</label>
  12. </section>
  13. <section class="form inputs">
  14. <h3>Letterhead</h3>
  15. <span>Header as appears on PDFs.</span>
  16. <img src="/assets/image/mintberry.jpg" alt="avatar">
  17. <button>Upload</button>
  18. </section>
  19. <section class="form inputs special">
  20. <h3>Profile</h3>
  21. <label for="">First Name</label>
  22. <input type="text">
  23. <label for="">Last Name</label>
  24. <input type="text">
  25. <label for="">NMLS ID</label>
  26. <input type="text">
  27. <label for="">Branch ID</label>
  28. <input type="text">
  29. <select id="" name="" >
  30. <option value="usa">USA</option>
  31. <option value="canada">Canada</option>
  32. </select>
  33. <button @click="check">Save</button>
  34. </section>
  35. <section class="form inputs special">
  36. <h3>Login</h3>
  37. <label for="">Email</label>
  38. <input type="text">
  39. <label for="">New Password</label>
  40. <input type="text">
  41. <button @click="check">Save</button>
  42. </section>
  43. <Dialog v-if="ready" @close="() => ready = false">
  44. <h3>Confirm your current password to save changes.</h3>
  45. <input type="text">
  46. <button>Confirm</button>
  47. </Dialog>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { ref, watch, onMounted } from "vue"
  52. import Dialog from "./dialog.vue"
  53. let avatar = ref(null)
  54. let ready = ref(false)
  55. let avatarChanged = ref(false)
  56. let avatarError = ref('')
  57. const canvas = ref(null)
  58. const props = defineProps(['user', 'token'])
  59. const emit = defineEmits(['updateAvatar'])
  60. function save() {
  61. }
  62. function check() {
  63. ready.value = true
  64. }
  65. function uploadAvatar(blob) {
  66. changeAvatar(blob)?.then(() => {
  67. canvas.value.toBlob(b => {
  68. fetch(`/api/user/avatar`,
  69. {method: 'POST',
  70. body: b,
  71. headers: {
  72. "Accept": "application/json",
  73. "Authorization": `Bearer ${props.token}`,
  74. },
  75. }).then(resp => {
  76. if (resp.ok) {emit('updateAvatar')}
  77. })
  78. })
  79. })
  80. canvas.value.toBlob(b => {
  81. // uploadAvatar(b)
  82. })
  83. }
  84. function changeAvatar(blob) {
  85. const validTypes = ['image/jpeg', 'image/png']
  86. if (!validTypes.includes(blob.type)) {
  87. avatarError.value = 'Image must be JPEG of PNG format'
  88. return
  89. }
  90. avatarError.value = ''
  91. avatar.value = blob
  92. return createImageBitmap(blob,
  93. {resizeWidth: 200, resizeHeight: 200, resizeQuality: 'medium'}).
  94. then((img) => {
  95. avatar.value = img
  96. canvas.value.getContext("2d").drawImage(img, 0, 0, 200, 200)
  97. })
  98. }
  99. watch(props.user, () => {
  100. if (!props.user.avatar) return
  101. changeAvatar(props.user.avatar)
  102. }, {immediate: true})
  103. </script>