| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- import axios from "axios"
- import store from "@/store/index.js"
- import router from "@/router"
- axios.interceptors.response.use(function (response) {
- // 2xx 范围内的状态码都会触发该函数。
- if (response.data.code === 5001 || response.data.code === 5002) {
- store.commit('logoutCallback')
- // router.push({ name: 'HomeView' })
- location.href = `https://open.weixin.qq.com/connect/qrconnect?appid=wxd6467a266a4dfda9&redirect_uri=https%3A%2F%2Fwuxicharitymuseum.cn%2F%23%2Flogin-temp&response_type=code&scope=snsapi_login&state=${encodeURIComponent(router.currentRoute.value.name)}#wechat_redirect`
- return Promise.reject('登录态过期')
- }
- return response
- }, function (error) {
- return error
- })
- export function reportVisitPage(pageId) {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/visit/addVisit`,
- data: {
- device: 'pc',
- id: pageId,
- }
- })
- }
- // export async function checkLoginStatusAndProcess() {
- // const lastToken = localStorage.getItem('token')
- // const lastUserInfoStr = localStorage.getItem('userInfo')
- // if (lastToken && lastUserInfoStr) {
- // const res = await axios({
- // method: 'get',
- // url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/checkLogin`,
- // headers: {
- // token: lastToken,
- // }
- // })
- // if (res?.data?.code === 0 && res?.data?.data) {
- // store.commit('setLoginStatus', store.getters.loginStatusEnum.notLogin)
- // store.commit('setToken', lastToken)
- // store.commit('setUserInfo', JSON.parse(lastUserInfoStr))
- // return true
- // } else {
- // store.commit('logoutCallback')
- // return false
- // }
- // } else {
- // store.commit('logoutCallback')
- // return false
- // }
- // }
- export function loginByWxCode(code) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/wx/pcLogin/${code}`,
- }).then((res) => {
- return res.data.data
- })
- }
- export function getUserFromStorageIfNeed() {
- if (!store.state.token || !store.state.userInfo) {
- const lastToken = localStorage.getItem('token')
- const lastUserInfoStr = localStorage.getItem('userInfo')
- if (process.env.VUE_APP_CLI_MODE !== 'dev') {
- if (lastToken && lastUserInfoStr) {
- store.commit('setLoginStatus', store.getters.loginStatusEnum.wxUser)
- store.commit('setToken', lastToken)
- store.commit('setUserInfo', JSON.parse(lastUserInfoStr))
- }
- } else {
- if (lastToken) {
- store.commit('setLoginStatus', store.getters.loginStatusEnum.wxUser)
- store.commit('setToken', lastToken)
- }
- }
- }
- }
- export function getRelicList(searchKey, region) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/visit/getList`,
- // headers: {
- // appId: "CA02F83A5FA162B930AA2F962D202F43B0F6DE0B51AD79FEDB03FA8202BB4909330105B3B347510D87C97060C4288280D4A744E00565A4EC",
- // "Content-Type": "application/json",
- // },
- params: {
- type: 'scene',
- searchKey,
- region
- },
- }).then((res) => {
- return res.data.data
- })
- }
- export function submitFeedback (name, phone, content, randCode) {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/message`,
- headers: {
- token: store.state.token,
- },
- data: {
- name,
- phone,
- content,
- randCode,
- }
- }).then((res) => {
- if (res.data.code !== 0) {
- throw (res.data)
- } else {
- return
- }
- })
- }
- export function getPrizeList (pageNum, pageSize) {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/prize/pageList`,
- headers: {
- token: store.state.token,
- },
- data: {
- pageNum,
- pageSize,
- searchKey: '',
- }
- }).then((res) => {
- return res.data.data
- })
- }
- export function getMyScore () {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/getPoint`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data.data.total
- })
- }
- export function getShopContact() {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/getRuleConfig`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data.data
- })
- }
- export function getRedeemRecord() {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/point/getList`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data.data
- })
- }
- export function getRankingListApi (limit = 10) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/point/user/getSort`,
- headers: {
- token: store.state.token,
- },
- params: {
- limit
- }
- }).then((res) => {
- return res.data.data
- })
- }
- export const checkRedeemApi = () => {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/redeem/check`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data.data
- })
- }
- export const getRedeemApi = () => {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/redeem/info`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data.data
- })
- }
- export function redeemApi(data) {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/prize/redeem`,
- headers: {
- token: store.state.token,
- },
- data
- }).then((res) => {
- return res.data
- })
- }
- export function validateNickName (name) {
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/show/saveNickname/${name}`,
- headers: {
- token: store.state.token,
- },
- }).then((res) => {
- return res.data
- })
- }
- export function uploadFile(fileData) {
- console.log(fileData)
- const file = new window.File(
- [fileData],
- '锡善云城-证书.jpg',
- { type: 'image/jpeg', }
- )
- console.log('file', file)
- const formData = new FormData()
- formData.append("type", 'img')
- formData.append("file", file)
- return axios({
- method: 'post',
- url: `${process.env.VUE_APP_DEPLOY_ORIGIN}/api/cms/game/upload`,
- headers: {
- token: store.state.token,
- 'Content-Type': 'multipart/form-data',
- },
- data: formData
- }).then((res) => {
- return res.data.data.filePath
- })
- }
- // type:从雨花台项目搬来的类型,用于demo。
- // type: straw(手稿) book(书刊) tool(用具) clothing(服装) Italy(油画)
- export function fetchRelicList(type = 'all', keyword = '', pageNum = 0, pageSize = 20) {
- const filtered = staticConfig.collectionList.filter((item) => {
- return item.type === type || type === 'all'
- }).filter((item) => {
- return item.name.includes(keyword) || keyword === ''
- })
- return {
- list: filtered.slice(pageNum * pageSize, pageNum * pageSize + pageSize),
- total: filtered.length
- }
- }
- export function getNewsCarouselListApi () {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/news/carousel`,
- params: {
- limit: 3
- }
- }).then((res) => {
- return res.data.data
- })
- }
- export function getNewsListApi () {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/news`,
- params: {
- limit: 999
- }
- }).then((res) => {
- return res.data.rows
- })
- }
- export function getNewsDetailApi (id) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/news/${id}`,
- }).then((res) => {
- return res.data.data
- })
- }
- export function getCulturalRelicsTypeListApi () {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/culturalRelics/type/list`,
- }).then((res) => {
- return res.data.data
- })
- }
- export function getCulturalRelicsListApi (params) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/culturalRelics`,
- params
- }).then((res) => {
- return res.data
- })
- }
- export function getCulturalRelicsDetailApi (id) {
- return axios({
- method: 'get',
- url: `${process.env.VUE_APP_ARTICLE_ORIGIN}/api/web/culturalRelics/${id}`,
- }).then((res) => {
- return res.data.data
- })
- }
|