Pārlūkot izejas kodu

上传照片

tags/AL.0.8.0_20240113_base
yuan pirms 1 gada
vecāks
revīzija
4515032586
3 mainītis faili ar 91 papildinājumiem un 13 dzēšanām
  1. +6
    -3
      src/components/contact-form/index.vue
  2. +15
    -5
      src/pages/contact-edit/index.vue
  3. +70
    -5
      src/stores/contact-item.ts

+ 6
- 3
src/components/contact-form/index.vue Parādīt failu

@@ -13,10 +13,11 @@ const props = defineProps(['data'])


const contacts = useContactsStore() const contacts = useContactsStore()
const contact = useContactItemStore() const contact = useContactItemStore()
contact.setNewAvatar("")


const state = reactive({ const state = reactive({
isNickNameSuggestionsShow: false, isNickNameSuggestionsShow: false,
newAvatar: '',
newAvatar: undefined,
isDateSelectorVisible: false isDateSelectorVisible: false
}); });


@@ -29,7 +30,7 @@ const closeSwitch = (param) => {
}; };
const setChooseDate = (param) => { const setChooseDate = (param) => {
contact.contact.nextVisitDate = param[3] contact.contact.nextVisitDate = param[3]
};
}


function setShowSuggestions(isShow: Boolean) { function setShowSuggestions(isShow: Boolean) {
state.isNickNameSuggestionsShow = isShow state.isNickNameSuggestionsShow = isShow
@@ -42,6 +43,7 @@ const updateFacePhoto = () => {
success: function (res) { success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
state.newAvatar = res.tempFilePaths state.newAvatar = res.tempFilePaths
contact.setNewAvatar( res.tempFilePaths[0])
console.log(state.newAvatar) console.log(state.newAvatar)
}, },
}) })
@@ -63,7 +65,8 @@ const updateNickName = (value) => {
<view> <view>
<view class="d-flex justify-content-center"> <view class="d-flex justify-content-center">
<nut-avatar size="192" @click="updateFacePhoto" class="overflow-hidden"> <nut-avatar size="192" @click="updateFacePhoto" class="overflow-hidden">
<img v-if="contact.contact.avatar" :src="contact.contact.avatar" />
<img v-if="state.newAvatar" :src="state.newAvatar"/>
<img v-else-if="contact.contact.avatar" :src="contact.contact.avatar" />
<view v-else class="d-flex align-items-center justify-content-center h-100 w-100"> <view v-else class="d-flex align-items-center justify-content-center h-100 w-100">
<Text class="fas fa-user fa-6x"></Text> <Text class="fas fa-user fa-6x"></Text>
</view> </view>


+ 15
- 5
src/pages/contact-edit/index.vue Parādīt failu

@@ -30,11 +30,21 @@ const onSaveClicked = () => {
}) })
}).catch(error => { }).catch(error => {
Taro.hideLoading() Taro.hideLoading()
Taro.showToast({
title: '网络异常,请稍候重试',
icon: 'none',
duration: 2000
})
if (error) {
Taro.showToast({
title: error,
icon: 'none',
duration: 2000
})
}
else {
Taro.showToast({
title: '网络异常,请稍候重试',
icon: 'none',
duration: 2000
})
}

console.log("error", error) console.log("error", error)
}) })
} }


+ 70
- 5
src/stores/contact-item.ts Parādīt failu

@@ -1,18 +1,23 @@
// https://pinia.esm.dev/introduction.html // https://pinia.esm.dev/introduction.html
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import {GQLRequest} from "../utils";
import {GQLRequest, Session} from "../utils";
import {gql} from "graphql-tag"; import {gql} from "graphql-tag";
import {ContactData} from "./contacts"; import {ContactData} from "./contacts";
import {ref, Ref, UnwrapRef} from "vue"; import {ref, Ref, UnwrapRef} from "vue";
import Taro from "@tarojs/taro";


export const useContactItemStore = defineStore('contact-item', () => { export const useContactItemStore = defineStore('contact-item', () => {


const contact: Ref<UnwrapRef<ContactData>> = ref(getEmptyContactData()) const contact: Ref<UnwrapRef<ContactData>> = ref(getEmptyContactData())
const contactNewAvatar: Ref<UnwrapRef<string>> = ref("")


function setContact(contactItem: ContactData) { function setContact(contactItem: ContactData) {
contact.value = contactItem contact.value = contactItem
console.log("setContact", contact.value) console.log("setContact", contact.value)
} }
function setNewAvatar(avatar: string) {
contactNewAvatar.value = avatar
}


function getEmptyContactData(): ContactData { function getEmptyContactData(): ContactData {
return { return {
@@ -73,10 +78,29 @@ export const useContactItemStore = defineStore('contact-item', () => {
const isVIP = contact.value.isVIP const isVIP = contact.value.isVIP
const flexVisit = contact.value.flexVisit const flexVisit = contact.value.flexVisit


return GQLRequest.query(CREATE_VISITOR, { name, nickName, phone, company, isVIP, flexVisit })
return new Promise((resolve, reject) => {
if (contactNewAvatar.value !== "") {
uploadFace().then(r => {
console.log(r)
const resourceId = r.data.resourceId
GQLRequest.query(CREATE_VISITOR, { name, nickName, phone, company, isVIP, flexVisit, resourceId })
.then(r=> resolve(r))
.catch(e=> reject(e))
}).catch(e => {
reject(e.msg)
})
}
else {
GQLRequest.query(CREATE_VISITOR, { name, nickName, phone, company, isVIP, flexVisit })
.then(r=> resolve(r))
.catch(e=> reject(e))
}
})

} }


function updateVisitor() { function updateVisitor() {

const id = contact.value.id const id = contact.value.id
const name = contact.value.name const name = contact.value.name
const nickName = contact.value.nickName const nickName = contact.value.nickName
@@ -85,8 +109,27 @@ export const useContactItemStore = defineStore('contact-item', () => {
const isVIP = contact.value.isVIP const isVIP = contact.value.isVIP
const flexVisit = contact.value.flexVisit const flexVisit = contact.value.flexVisit


console.log(contact.value)
return GQLRequest.query(UPDATE_VISITOR, {id, name, nickName, phone, company, isVIP, flexVisit })

return new Promise((resolve, reject) => {
if (contactNewAvatar.value !== "") {
uploadFace().then(r => {
console.log(r)
const resourceId = r.data.resourceId
GQLRequest.query(UPDATE_VISITOR, {id, name, nickName, phone, company, isVIP, flexVisit, resourceId })
.then(r=> resolve(r))
.catch(e=> reject(e))
}).catch(e => {
reject(e.msg)
})
}
else {
GQLRequest.query(UPDATE_VISITOR, {id, name, nickName, phone, company, isVIP, flexVisit })
.then(r=> resolve(r))
.catch(e=> reject(e))
}
})


} }


function deleteVisitor() { function deleteVisitor() {
@@ -95,6 +138,28 @@ export const useContactItemStore = defineStore('contact-item', () => {
return GQLRequest.query(DELETE_VISITOR, { id }) return GQLRequest.query(DELETE_VISITOR, { id })
} }


function uploadFace() {
return new Promise((resolve, reject) => {
console.log("aaaaaaaa", contactNewAvatar.value)
Taro.uploadFile({
url: SERVER_URL + '/system/resources/upload-face',
header: {
Authorization: 'Bearer ' + Session.get('access_token'),
},
name: "file",
filePath: contactNewAvatar.value,
success: result => {
const data = JSON.parse(result.data)
if (result.statusCode == 200 && data.code !== 500) resolve(data)
else reject(data)
},
fail: res => {
reject(res)
}
})
})
}



return { contact, setContact, createVisitor, updateVisitor, deleteVisitor, getEmptyContactData}
return { contact, setContact, createVisitor, updateVisitor, deleteVisitor, getEmptyContactData, setNewAvatar}
}) })

Notiek ielāde…
Atcelt
Saglabāt