123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- import { StoreOptions } from 'vuex'
- import Vue from 'vue'
- import {
- getHomeHot,
- getHomeActivity,
- getCashOutInfo,
- submitCashOutInfo,
- getDetails,
- getRemove,
- getAdd,
- getCoin,
- getDocPay
- } from '@/api/main'
- interface InterfaceStore<S> extends StoreOptions<S> {
- namespaced?: boolean;
- }
- type APIStructure = Record<string, any>;
- type modulesOption = InterfaceStore<any>;
- function recoveryPageData (key: string, defaultValues = {}) {
- return sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key) || '') : defaultValues
- }
- function checkType (type: string | number) {
- let typeStr = ''
- switch (type) {
- case 1: {
- typeStr = 'word'
- break
- }
- case 2: {
- typeStr = 'pdf'
- break
- }
- case 3: {
- typeStr = 'excel'
- break
- }
- case 4: {
- typeStr = 'ppt'
- break
- }
- case 'doc': {
- typeStr = 'word'
- break
- }
- case 'xls': {
- typeStr = 'excel'
- break
- }
- }
- return typeStr
- }
- function formatData (v: APIStructure) {
- return {
- img: v?.docImg,
- type: checkType(v?.docFileType),
- id: v.docId,
- title: v?.docName || v?.docTitle,
- money: v.price,
- size: v?.docFileSize,
- page: v?.docPageSize,
- down: v?.downTimes,
- contribution: v?.sourceUserId
- }
- }
- const modulesOption: modulesOption = {
- namespaced: true,
- state: {
- // 提现页面数据缓存(用于跳出页面返回时恢复)
- cashOutInfo: recoveryPageData('partner-cashout'),
- cashOutSuccess: recoveryPageData('partner-cashout-success'),
- homePageData: recoveryPageData('jy-docs-home-page')
- },
- mutations: {
- // 保存提现页面数据
- saveCashOutInfo (state, data) {
- for (const key in data) {
- state.cashOutInfo[key] = data[key]
- }
- sessionStorage.setItem('partner-cashout', JSON.stringify(data))
- },
- // 清除提现页面数据
- clearCashOutInfo (state) {
- state.cashOutInfo = {}
- sessionStorage.setItem('partner-cashout', JSON.stringify({}))
- },
- // 保存提现成功数据
- saveCashOutSuccessInfo (state, data) {
- for (const key in data) {
- state.cashOutSuccess[key] = data[key]
- }
- sessionStorage.setItem('partner-cashout-success', JSON.stringify(data))
- },
- // 清除提现成功数据
- clearCashOutSuccessInfo (state) {
- state.cashOutSuccess = {}
- sessionStorage.setItem('partner-cashout-success', JSON.stringify({}))
- },
- // 保存首页数据
- saveHomeData (state, data) {
- for (const key in data) {
- Vue.set(state.homePageData, key, data[key])
- }
- sessionStorage.setItem('jy-docs-home-page', JSON.stringify(state.homePageData))
- }
- },
- actions: {
- // 首页数据
- async getHome (state) {
- getHomeHot({ sign: 'new', num: 5 }).then((res: APIStructure) => {
- if (!res.data.error_msg.length) {
- state.commit('saveHomeData', {
- new: res.data.data.map((v: APIStructure) => formatData(v))
- })
- }
- })
- getHomeHot({ sign: 'hot', num: 5 }).then((res: APIStructure) => {
- if (!res.data.error_msg.length) {
- state.commit('saveHomeData', {
- hot: res.data.data.map((v: APIStructure) => formatData(v))
- })
- }
- })
- getHomeActivity({ code: 3, size: 3, num: 1 }).then((res: APIStructure) => {
- if (!res.data.error_msg.length) {
- state.commit('saveHomeData', {
- keep: res.data.data.map((v: APIStructure) => formatData(v))
- })
- }
- })
- },
- // 文库购买
- async getDocPay (state, data) {
- try {
- const res = await getDocPay(data)
- return res.data
- } catch (error) {}
- },
- // 提现查询
- async getCashOutInfo (state, data) {
- try {
- const res = await getCashOutInfo(data)
- return res.data
- } catch (error) {}
- },
- // 提现提交
- async submitCashOutInfo (state, data) {
- try {
- const res = await submitCashOutInfo(data)
- return res.data
- } catch (error) {}
- },
- // 详情
- async getDetails (state, data) {
- try {
- const res = await getDetails(data)
- console.log(res)
- return res.data
- } catch (error) {}
- },
- // 文库收藏
- async getAdd (state, data) {
- try {
- const res = await getAdd(data)
- console.log(res)
- return res.data
- } catch (error) {}
- },
- // 文库取消收藏
- async getRemove (state, data) {
- try {
- const res = await getRemove(data)
- console.log(res)
- return res.data
- } catch (error) {}
- },
- // 剑鱼币
- async getCoin (state, data) {
- try {
- const res = await getCoin(data)
- console.log(res)
- return res.data
- } catch (error) {}
- }
- },
- getters: {}
- }
- export default modulesOption
|