删除 Mobx 相关使用
parent
d3109a1da2
commit
c8924ee764
@ -1,115 +0,0 @@
|
|||||||
import { makeAutoObservable, runInAction } from 'mobx'
|
|
||||||
import { fetchJSON, postForm } from '@/utils/request'
|
|
||||||
import { prepareUrl, isNotEmpty, isEmpty } from '@/utils/commons'
|
|
||||||
|
|
||||||
class Order {
|
|
||||||
|
|
||||||
constructor(root) {
|
|
||||||
makeAutoObservable(this, { rootStore: false })
|
|
||||||
this.root = root
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchOptionList() {
|
|
||||||
const fetchCountryUrl = 'https://p9axztuwd7x8a7.mycht.cn/service-InfoSys/InfoSys/GetCountryList'
|
|
||||||
const fetchPhotographerUrl = 'https://p9axztuwd7x8a7.mycht.cn/service-InfoSys/InfoSys/GetphotographerList'
|
|
||||||
const fetchTagUrl = 'https://p9axztuwd7x8a7.mycht.cn/service-InfoSys/InfoSys/GetPhotoTagList'
|
|
||||||
|
|
||||||
const countryPromise = fetchJSON(fetchCountryUrl)
|
|
||||||
.then(json => {
|
|
||||||
if (json.errcode == 0) {
|
|
||||||
const countryOptionList = (json?.result ?? []).map((data, index) => {
|
|
||||||
return {
|
|
||||||
value: data.COI_SN,
|
|
||||||
label: data.COI_Name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
countryOptionList.unshift({value:-1, label: '未知'})
|
|
||||||
return countryOptionList
|
|
||||||
} else {
|
|
||||||
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const cityPromise = this.fetchCityList('')
|
|
||||||
|
|
||||||
const photographerPromise = fetchJSON(fetchPhotographerUrl)
|
|
||||||
.then(json => {
|
|
||||||
if (json.errcode == 0) {
|
|
||||||
const photographerOptionList = (json?.result ?? []).map((data, index) => {
|
|
||||||
return {
|
|
||||||
value: data.U_Name,
|
|
||||||
label: data.U_Name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return photographerOptionList
|
|
||||||
} else {
|
|
||||||
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const tagPromise = fetchJSON(fetchTagUrl)
|
|
||||||
.then(json => {
|
|
||||||
if (json.errcode == 0) {
|
|
||||||
const tagOptionList = (json?.result ?? []).map((data, index) => {
|
|
||||||
return {
|
|
||||||
value: data.Tag_SN,
|
|
||||||
label: data.Tag_Name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return tagOptionList
|
|
||||||
} else {
|
|
||||||
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return Promise.all([countryPromise, cityPromise, photographerPromise, tagPromise])
|
|
||||||
.then(results => {
|
|
||||||
return {
|
|
||||||
countryOptionList: results[0],
|
|
||||||
cityOptionList: results[1],
|
|
||||||
photographerOptionList: results[2],
|
|
||||||
tagOptionList: results[3]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fetchCityList(countryId) {
|
|
||||||
const fetchCityUrl =
|
|
||||||
prepareUrl('https://p9axztuwd7x8a7.mycht.cn/service-InfoSys/InfoSys/GetCityList')
|
|
||||||
.append('coi_sn', countryId)
|
|
||||||
.build()
|
|
||||||
return fetchJSON(fetchCityUrl)
|
|
||||||
.then(json => {
|
|
||||||
if (json.errcode == 0) {
|
|
||||||
const cityOptionList = (json?.result ?? []).map((data, index) => {
|
|
||||||
return {
|
|
||||||
value: data.CII_SN,
|
|
||||||
label: data.CII_Name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
cityOptionList.unshift({value:-1, label: '未知'})
|
|
||||||
return cityOptionList
|
|
||||||
} else {
|
|
||||||
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
useImage(imageId, userId, website) {
|
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('PII_SN', imageId)
|
|
||||||
const postUrl = 'https://p9axztuwd7x8a7.mycht.cn/service-InfoSysSOA/use_image'
|
|
||||||
|
|
||||||
return postForm(postUrl, formData)
|
|
||||||
.then(json => {
|
|
||||||
if (json.errcode == 0) {
|
|
||||||
console.info(json)
|
|
||||||
} else {
|
|
||||||
throw new Error(json.errmsg + ': ' + json.errcode)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Order
|
|
@ -1,60 +0,0 @@
|
|||||||
import { makeAutoObservable } from 'mobx'
|
|
||||||
import Auth from './Auth'
|
|
||||||
import Order from './Order'
|
|
||||||
|
|
||||||
class Root {
|
|
||||||
constructor() {
|
|
||||||
this.orderStore = new Order(this)
|
|
||||||
this.authStore = new Auth(this)
|
|
||||||
makeAutoObservable(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
clearSession() {
|
|
||||||
if (window.sessionStorage) {
|
|
||||||
const sessionStorage = window.sessionStorage
|
|
||||||
sessionStorage.clear()
|
|
||||||
} else {
|
|
||||||
console.error('browser not support sessionStorage!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getSession(key) {
|
|
||||||
if (window.sessionStorage) {
|
|
||||||
const sessionStorage = window.sessionStorage
|
|
||||||
return sessionStorage.getItem(key)
|
|
||||||
} else {
|
|
||||||
console.error('browser not support sessionStorage!')
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
putSession(key, value) {
|
|
||||||
if (window.sessionStorage) {
|
|
||||||
const sessionStorage = window.sessionStorage
|
|
||||||
return sessionStorage.setItem(key, value)
|
|
||||||
} else {
|
|
||||||
console.error('browser not support sessionStorage!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getLocal(key) {
|
|
||||||
if (window.localStorage) {
|
|
||||||
const localStorage = window.localStorage
|
|
||||||
return localStorage.getItem(key)
|
|
||||||
} else {
|
|
||||||
console.error('browser not support localStorage!')
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
putLocal(key, value) {
|
|
||||||
if (window.localStorage) {
|
|
||||||
const localStorage = window.localStorage
|
|
||||||
return localStorage.setItem(key, value)
|
|
||||||
} else {
|
|
||||||
console.error('browser not support localStorage!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Root
|
|
@ -1,7 +0,0 @@
|
|||||||
import { createContext, useContext } from 'react'
|
|
||||||
|
|
||||||
export const StoreContext = createContext()
|
|
||||||
|
|
||||||
export function useStore() {
|
|
||||||
return useContext(StoreContext)
|
|
||||||
}
|
|
Loading…
Reference in New Issue