|
|
|
@ -2,12 +2,13 @@ import { create } from 'zustand'
|
|
|
|
|
import { devtools } from 'zustand/middleware'
|
|
|
|
|
import { fetchJSON, postForm } from '@/utils/request'
|
|
|
|
|
import { API_HOST } from '@/config'
|
|
|
|
|
import { isNotEmpty, prepareUrl } from '@/utils/commons'
|
|
|
|
|
import { isNotEmpty, copy } from '@/utils/commons'
|
|
|
|
|
|
|
|
|
|
const useSnippetStore = create(devtools((set, get) => ({
|
|
|
|
|
|
|
|
|
|
ownerList: [],
|
|
|
|
|
typeList: [],
|
|
|
|
|
typeAllList: [],
|
|
|
|
|
snippetList: [],
|
|
|
|
|
drawerOpen: false,
|
|
|
|
|
|
|
|
|
@ -30,43 +31,37 @@ const useSnippetStore = create(devtools((set, get) => ({
|
|
|
|
|
return fetchJSON(fetchOwnerUrl, params)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode === 0) {
|
|
|
|
|
console.info(json)
|
|
|
|
|
const mapTypeList = json?.result?.type.map(item => {
|
|
|
|
|
return { value: item.vsn, label: item.vname }
|
|
|
|
|
})
|
|
|
|
|
mapTypeList.unshift({ value: '', label: '全部' })
|
|
|
|
|
const mapTypeAllList = copy(mapTypeList);
|
|
|
|
|
mapTypeAllList.unshift({ value: '', label: '全部' });
|
|
|
|
|
set(() => ({
|
|
|
|
|
ownerList: json?.result?.owner.map(item => {
|
|
|
|
|
return { value: item.vsn, label: item.vname }
|
|
|
|
|
}),
|
|
|
|
|
typeList: mapTypeList
|
|
|
|
|
typeList: mapTypeList,
|
|
|
|
|
typeAllList: mapTypeAllList
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json?.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fetchSnippetList: async (formValues) => {
|
|
|
|
|
const fetchSnippetListUrl = `${API_HOST}/v2/QueryAutoDocInfo`
|
|
|
|
|
const params = {owner: '1/1', type: '234004', title: '中国'};
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchSnippetListUrl, formValues)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode === 0) {
|
|
|
|
|
console.info(json)
|
|
|
|
|
set(() => ({
|
|
|
|
|
snippetList: json?.result
|
|
|
|
|
// ownerList: json?.result?.owner.map(item => {
|
|
|
|
|
// return { value: item.vsn, label: item.vname }
|
|
|
|
|
// }),
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json?.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fetchSnippetDetail: async (snippetId) => {
|
|
|
|
@ -82,7 +77,26 @@ const useSnippetStore = create(devtools((set, get) => ({
|
|
|
|
|
throw new Error(json?.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
saveOrUpdateSnippet: async (formValues) => {
|
|
|
|
|
const postSnippetUrl = `${API_HOST}/v2/AddAutoDocInfo`
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('adi_sn', formValues.snippetId)
|
|
|
|
|
formData.append('owner', 383)
|
|
|
|
|
formData.append('type', formValues.category)
|
|
|
|
|
formData.append('title', formValues.title)
|
|
|
|
|
formData.append('adi_content', formValues.content.html)
|
|
|
|
|
formData.append('opi_sn', 383)
|
|
|
|
|
|
|
|
|
|
return postForm(postSnippetUrl, formData)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode === 0) {
|
|
|
|
|
console.info(json)
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json?.errmsg + ': ' + json.errcode)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
}), { name: 'snippetStore' }))
|
|
|
|
|
|
|
|
|
|