|
|
|
@@ -1,18 +1,23 @@ |
|
|
|
// https://pinia.esm.dev/introduction.html |
|
|
|
import { defineStore } from 'pinia' |
|
|
|
import {GQLRequest} from "../utils"; |
|
|
|
import {GQLRequest, Session} from "../utils"; |
|
|
|
import {gql} from "graphql-tag"; |
|
|
|
import {ContactData} from "./contacts"; |
|
|
|
import {ref, Ref, UnwrapRef} from "vue"; |
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
|
|
|
export const useContactItemStore = defineStore('contact-item', () => { |
|
|
|
|
|
|
|
const contact: Ref<UnwrapRef<ContactData>> = ref(getEmptyContactData()) |
|
|
|
const contactNewAvatar: Ref<UnwrapRef<string>> = ref("") |
|
|
|
|
|
|
|
function setContact(contactItem: ContactData) { |
|
|
|
contact.value = contactItem |
|
|
|
console.log("setContact", contact.value) |
|
|
|
} |
|
|
|
function setNewAvatar(avatar: string) { |
|
|
|
contactNewAvatar.value = avatar |
|
|
|
} |
|
|
|
|
|
|
|
function getEmptyContactData(): ContactData { |
|
|
|
return { |
|
|
|
@@ -73,10 +78,29 @@ export const useContactItemStore = defineStore('contact-item', () => { |
|
|
|
const isVIP = contact.value.isVIP |
|
|
|
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() { |
|
|
|
|
|
|
|
const id = contact.value.id |
|
|
|
const name = contact.value.name |
|
|
|
const nickName = contact.value.nickName |
|
|
|
@@ -85,8 +109,27 @@ export const useContactItemStore = defineStore('contact-item', () => { |
|
|
|
const isVIP = contact.value.isVIP |
|
|
|
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() { |
|
|
|
@@ -95,6 +138,28 @@ export const useContactItemStore = defineStore('contact-item', () => { |
|
|
|
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} |
|
|
|
}) |