tum %!s(int64=2) %!d(string=před) roky
rodič
revize
8ea71a1b96
2 změnil soubory, kde provedl 123 přidání a 5 odebrání
  1. 29 2
      src/composable/settings.ts
  2. 94 3
      src/views/ProfilePage.vue

+ 29 - 2
src/composable/settings.ts

@@ -9,8 +9,8 @@ import { Preferences } from '@capacitor/preferences';
9 9
 
10 10
 export const TOKEN = '173cb9e357a861abd91e8008fab9246e0cc116af'
11 11
 
12
-//export const BASE_URL = 'http://localhost:8020/'
13
-export const BASE_URL = 'https://www.tigermuaythai.live/'
12
+export const BASE_URL = 'http://localhost:8020/'
13
+//export const BASE_URL = 'https://www.tigermuaythai.live/'
14 14
 
15 15
 export const APPLE_CALLBACK = BASE_URL + "soc_accounts/apple/login/callback/";
16 16
 //const axios = setupCache(Axios); 
@@ -422,3 +422,30 @@ export const appleLogin = async(access_token) => {
422 422
   console.log("apple login = ", data)
423 423
   return data
424 424
 }
425
+
426
+export const updateProfile = async (profileObj) => {
427
+  const token = await Preferences.get({ key: 'user_token' });
428
+  console.log("token = ", token)
429
+  const { data } = await axios.post(BASE_URL + `backend/api/profiles/update_profile/`,
430
+    profileObj,
431
+    {
432
+      headers: { 
433
+      'Authorization': `Token ${token.value}`
434
+      }
435
+    })
436
+  console.info(data)
437
+  return data
438
+}
439
+
440
+export const uploadPhoto = async(fileObj) => {
441
+  const token = await Preferences.get({ key: 'user_token' });
442
+  let formData = new FormData();
443
+  formData.append("image", fileObj);
444
+  const { data }  = await axios.post(BASE_URL + 'backend/api/profiles/upload_photo/', formData, {
445
+      headers: {
446
+        'Content-Type': 'multipart/form-data', 
447
+        'Authorization': `Token ${token.value}`
448
+      }
449
+  })
450
+  return data;
451
+}

+ 94 - 3
src/views/ProfilePage.vue

@@ -10,9 +10,44 @@
10 10
       <ion-button @click='clear'>Clear Pref</ion-button>
11 11
       <ion-button @click='btnLogout'>Btn Logout</ion-button> -->
12 12
       <template v-if="refIsLogin && myprofile">
13
-        
13
+        <ion-img :src="myprofile.photo" v-if="myprofile.photo" class='profilePhoto' />
14
+          <div class='ion-text-center'>
15
+        <ion-button class='ion-margin-vertical' id='myqr-modal'>My QRCODE</ion-button>
16
+          </div>
17
+        <ion-modal ref="modal" trigger="myqr-modal">
18
+            <ion-content class="ion-padding">
19
+              <ion-img :src="'data:image/png;base64,'+myprofile.qrcode"/><br>
20
+                <h5 class='ion-text-center'>{{ myprofile.text_qrcode }}</h5>
21
+                    <ion-button expand="full" @click="modal.$el.dismiss()">Close</ion-button>
22
+
23
+            </ion-content>
24
+        </ion-modal>
14 25
         <ion-list>
15 26
           <ion-list-header>
27
+            <ion-label>Info</ion-label>
28
+          </ion-list-header>
29
+          <ion-item>
30
+            <input type='file' @change="onUploadPhoto" />
31
+          </ion-item>
32
+          <ion-item>
33
+            <ion-input label="First Name" label-placement="floating" placeholder="Enter text" :value="myprofile.first_name" @ionInput="onUpdateProfile" ref="first_name" debounce=1000></ion-input>
34
+            <ion-input label="Last Name" label-placement="floating" placeholder="Enter text" :value="myprofile.last_name" @ionInput="onUpdateProfile" ref="last_name" debounce=1000></ion-input>
35
+          </ion-item>
36
+          <ion-item>
37
+            <ion-label>Birthdate</ion-label>
38
+             <ion-datetime-button datetime="datetime"></ion-datetime-button>
39
+
40
+            <ion-modal :keep-contents-mounted="true">
41
+              <ion-datetime id="datetime" presentation="date" :value="myprofile.birth_date" ref='birthdate' @ionBlur="onUpdateProfile" ></ion-datetime>
42
+            </ion-modal>
43
+          </ion-item>
44
+          <ion-item>
45
+            <ion-textarea label="Address" label-placement="floating" placeholder="Enter text" ref='loc' :value="myprofile.location" @ionInput="onUpdateProfile" debounce=1000></ion-textarea>
46
+          </ion-item>
47
+          <ion-item>
48
+            <ion-input label="Tel." type="tel" ref="tel" placeholder="888-888-8888" :value="myprofile.phone_number" @ionInput="onUpdateProfile" debounce=1000></ion-input>
49
+          </ion-item>
50
+          <ion-list-header>
16 51
             <ion-label>Notifications</ion-label>
17 52
           </ion-list-header>
18 53
           <ion-item>
@@ -82,12 +117,12 @@
82 117
 </template>
83 118
 
84 119
 <script setup lang="ts">
85
-import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption, IonList, IonListHeader, IonItem, IonText, IonImg, isPlatform } from '@ionic/vue';
120
+import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonButton, onIonViewWillEnter, IonRow, IonCol, IonGrid, IonToggle, IonLabel, IonChip, IonIcon, IonSelect, IonSelectOption, IonList, IonListHeader, IonItem, IonText, IonImg, isPlatform, IonDatetime, IonDatetimeButton, IonModal, IonTextarea, IonInput } from '@ionic/vue';
86 121
 import ExploreContainer from '@/components/ExploreContainer.vue';
87 122
 import LoginForm from '@/components/LoginForm.vue';
88 123
 import { defineComponent, onMounted } from 'vue';
89 124
 import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
90
-import { facebookLogin, setUserToken, logout, clearPref, BASE_URL, listCourses, getPref, likeCourse, isLogin, ggLogin, updateNoti, APPLE_CALLBACK, appleLogin } from '@/composable/settings';
125
+import { facebookLogin, setUserToken, logout, clearPref, BASE_URL, listCourses, getPref, likeCourse, isLogin, ggLogin, updateNoti, APPLE_CALLBACK, appleLogin, updateProfile, uploadPhoto } from '@/composable/settings';
91 126
 import { InAppBrowser } from '@capgo/inappbrowser'
92 127
 import { close, closeCircle, pin, logoApple, logoFacebook, logoGoogle  } from 'ionicons/icons';
93 128
 
@@ -133,6 +168,14 @@ const list_courses = ref([])
133 168
 const formError = ref(null)
134 169
 const selecteds = ref([])
135 170
 const myprofile = ref()
171
+
172
+const first_name = ref();
173
+const last_name = ref();
174
+const birthdate = ref();
175
+const loc = ref();
176
+const tel = ref();
177
+const modal = ref();
178
+
136 179
 const noti = reactive({liveNoti: true, newsNoti: true});
137 180
 const openReset = async () => {
138 181
   console.log("open Reset")
@@ -244,6 +287,7 @@ onIonViewWillEnter(async () => {
244 287
   refIsLogin.value = await isLogin()
245 288
   if( refIsLogin.value == true ) {
246 289
     myprofile.value  = await getPref()
290
+    console.log(myprofile.value)
247 291
     noti.liveNoti = myprofile.value.live_noti;
248 292
     noti.newsNoti = myprofile.value.news_noti;
249 293
   }
@@ -352,4 +396,51 @@ const onAppleLogin = async () => {
352 396
     // Handle error
353 397
   });
354 398
 }
399
+const onUpdateProfile = async() => {
400
+  console.log("update profile");
401
+  console.log(typeof birthdate.value.$el.value)
402
+  let obj = { 
403
+    first_name: first_name.value.$el.value, 
404
+    last_name: last_name.value.$el.value, 
405
+    birth_date: birthdate.value.$el.value.substring(0, 10), 
406
+    loc: loc.value.$el.value, 
407
+    phone_number: tel.value.$el.value
408
+  }
409
+  try{
410
+    myprofile.value = await updateProfile(obj)
411
+  }catch(error) {
412
+    alert(error)
413
+  }
414
+  console.log(obj);
415
+  
416
+}
417
+const onUploadPhoto = async($event) => {
418
+  console.log("upload photo")
419
+  console.log($event.target.files)
420
+  const fileObj = $event.target.files[0]
421
+  try{
422
+    myprofile.value = await uploadPhoto(fileObj)
423
+  }catch(error) {
424
+    alert(error)
425
+  }
426
+}
355 427
 </script>
428
+<style scoped>
429
+ion-datetime {
430
+  --background: #151515;
431
+  --wheel-fade-background-rgb: 5,5,5;
432
+}
433
+ion-datetime::part(wheel-item) {
434
+}
435
+ion-datetime::part(wheel-item active) {
436
+}
437
+.profilePhoto::part(image) {
438
+  width:160px;
439
+  height:160px;
440
+  object-fit:cover;
441
+  border-radius:80px;
442
+  margin:auto;
443
+  display:block;
444
+  border:2px solid #fff;
445
+}
446
+</style>