index.ts 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. import Taro from "@tarojs/taro";
  2. import indexStore from "@src/store/index";
  3. import { setApp } from "@src/config";
  4. /**
  5. * 获取小程序组件配置列表
  6. * */
  7. // export function getAppComponent() {
  8. // return new Promise(async (resolve, reject) => {
  9. // try {
  10. // // 初始化
  11. // Taro.request({
  12. // url: '/app/appComponent/list',
  13. // method: 'GET',
  14. // success: (res) => {
  15. // resolve(res)
  16. // },
  17. // fail: (err) => {
  18. // reject(err);
  19. // }
  20. // })
  21. // } catch (error) {
  22. // reject(error);
  23. // }
  24. // })
  25. // }
  26. /**
  27. * 获取短篇首页banners列表
  28. * */
  29. export function getShortBanners(workDirection) {
  30. return new Promise(async (resolve, reject) => {
  31. try {
  32. // 初始化
  33. Taro.request({
  34. url: '/app/appComponent/getBanners',
  35. method: 'GET',
  36. data: { workDirection },
  37. success: (res) => {
  38. if(JSON.stringify(indexStore.indexBanners) !== JSON.stringify(res.data.data)){
  39. indexStore.setData({ indexBanners: res.data.data })
  40. }
  41. resolve(res)
  42. },
  43. fail: (err) => {
  44. reject(err);
  45. }
  46. })
  47. } catch (error) {
  48. reject(error);
  49. }
  50. })
  51. }
  52. /**
  53. * 获取短篇首页热门分类列表
  54. * */
  55. export function getShortHotCategory(workDirection) {
  56. return new Promise(async (resolve, reject) => {
  57. try {
  58. // 初始化
  59. Taro.request({
  60. url: '/app/appComponent/getHotCategory',
  61. method: 'GET',
  62. data: { workDirection },
  63. success: (res) => {
  64. if(JSON.stringify(indexStore.indexHotCategory) !== JSON.stringify(res.data.data)){
  65. indexStore.setData({ indexHotCategory: res.data.data })
  66. }
  67. resolve(res)
  68. },
  69. fail: (err) => {
  70. reject(err);
  71. }
  72. })
  73. } catch (error) {
  74. reject(error);
  75. }
  76. })
  77. }
  78. /**
  79. * 获取重磅新书
  80. * */
  81. export function getShortNewBooks(workDirection) {
  82. return new Promise(async (resolve, reject) => {
  83. try {
  84. // 初始化
  85. Taro.request({
  86. url: '/app/appComponent/getNewBooks',
  87. method: 'GET',
  88. data: { workDirection },
  89. success: (res) => {
  90. if(JSON.stringify(indexStore.indexNewBooks) !== JSON.stringify(res.data.data)){
  91. indexStore.setData({ indexNewBooks: res.data.data })
  92. }
  93. resolve(res)
  94. },
  95. fail: (err) => {
  96. reject(err);
  97. }
  98. })
  99. } catch (error) {
  100. reject(error);
  101. }
  102. })
  103. }
  104. /**
  105. * 获取热门推荐
  106. * */
  107. export function getShortHotRec(workDirection) {
  108. return new Promise(async (resolve, reject) => {
  109. try {
  110. // 初始化
  111. Taro.request({
  112. url: '/app/appComponent/getHotRec',
  113. method: 'GET',
  114. data: { workDirection },
  115. success: (res) => {
  116. if(JSON.stringify(indexStore.indexHotRec) !== JSON.stringify(res.data.data)){
  117. indexStore.setData({ indexHotRec: res.data.data })
  118. }
  119. resolve(res)
  120. },
  121. fail: (err) => {
  122. reject(err);
  123. }
  124. })
  125. } catch (error) {
  126. reject(error);
  127. }
  128. })
  129. }
  130. /**
  131. * 获取口碑佳作
  132. * */
  133. export function getShortBestReviews(workDirection) {
  134. return new Promise(async (resolve, reject) => {
  135. try {
  136. // 初始化
  137. Taro.request({
  138. url: '/app/appComponent/getBestReviews',
  139. method: 'GET',
  140. data: { workDirection },
  141. success: (res) => {
  142. if(JSON.stringify(indexStore.indexBestReviews) !== JSON.stringify(res.data.data)){
  143. indexStore.setData({ indexBestReviews: res.data.data })
  144. }
  145. resolve(res)
  146. },
  147. fail: (err) => {
  148. reject(err);
  149. }
  150. })
  151. } catch (error) {
  152. reject(error);
  153. }
  154. })
  155. }
  156. /**
  157. * 获取经典热书
  158. * */
  159. export function getShortClassicBooks(workDirection) {
  160. return new Promise(async (resolve, reject) => {
  161. try {
  162. // 初始化
  163. Taro.request({
  164. url: '/app/appComponent/getClassicBooks',
  165. method: 'GET',
  166. data: { workDirection },
  167. success: (res) => {
  168. if(JSON.stringify(indexStore.indexClassicBooks) !== JSON.stringify(res.data.data)){
  169. indexStore.setData({ indexClassicBooks: res.data.data })
  170. }
  171. resolve(res)
  172. },
  173. fail: (err) => {
  174. reject(err);
  175. }
  176. })
  177. } catch (error) {
  178. reject(error);
  179. }
  180. })
  181. }
  182. /**
  183. * 获取必看
  184. * */
  185. export function getShortBestBooks(workDirection) {
  186. return new Promise(async (resolve, reject) => {
  187. try {
  188. // 初始化
  189. Taro.request({
  190. url: '/app/appComponent/getBestBooks',
  191. method: 'GET',
  192. data: { workDirection },
  193. success: (res) => {
  194. if(JSON.stringify(indexStore.indexBestBooks) !== JSON.stringify(res.data.data)){
  195. indexStore.setData({ indexBestBooks: res.data.data })
  196. }
  197. resolve(res)
  198. },
  199. fail: (err) => {
  200. reject(err);
  201. }
  202. })
  203. } catch (error) {
  204. reject(error);
  205. }
  206. })
  207. }
  208. /**
  209. * 猜你喜欢
  210. * */
  211. export function getShortGuessLike(data) {
  212. return new Promise(async (resolve, reject) => {
  213. try {
  214. // 初始化
  215. Taro.request({
  216. url: '/app/appComponent/getGuessLike',
  217. method: 'GET',
  218. data,
  219. success: (res) => {
  220. if(JSON.stringify(indexStore.indexGuessLike) !== JSON.stringify(res.data.data)){
  221. indexStore.setData({ indexGuessLike: res.data.data })
  222. }
  223. resolve(res)
  224. },
  225. fail: (err) => {
  226. reject(err);
  227. }
  228. })
  229. } catch (error) {
  230. reject(error);
  231. }
  232. })
  233. }
  234. /**
  235. /**
  236. *获取短篇首页热门书籍列表
  237. * */
  238. export function getShortHotBooks(workDirection) {
  239. return new Promise(async (resolve, reject) => {
  240. try {
  241. // 初始化
  242. Taro.request({
  243. url: '/app/appComponent/getHotBooks',
  244. method: 'GET',
  245. data: { workDirection },
  246. success: (res) => {
  247. if(JSON.stringify(indexStore.indexHotBooks) !== JSON.stringify(res.data.data)){
  248. indexStore.setData({ indexHotBooks: res.data.data })
  249. }
  250. resolve(res)
  251. },
  252. fail: (err) => {
  253. reject(err);
  254. }
  255. })
  256. } catch (error) {
  257. reject(error);
  258. }
  259. })
  260. }
  261. /**
  262. * 获取充值模板配置
  263. * */
  264. export function getRechargeTemplate() {
  265. return new Promise(async (resolve, reject) => {
  266. try {
  267. // 初始化
  268. Taro.request({
  269. url: '/app/rechargeTemplate/getInfo',
  270. method: 'GET',
  271. success: (res) => {
  272. indexStore.setData({ rechargeTemplate: res.data.data })
  273. resolve(res)
  274. },
  275. fail: (err) => {
  276. reject(err);
  277. }
  278. })
  279. } catch (error) {
  280. reject(error);
  281. }
  282. })
  283. }
  284. /**
  285. * 获取枚举
  286. * */
  287. export function enumDictList() {
  288. return new Promise(async (resolve, reject) => {
  289. try {
  290. // 初始化
  291. Taro.request({
  292. url: '/app/enumDict/list',
  293. method: 'GET',
  294. success: (res) => {
  295. let enumList = {}
  296. Object.values(res.data?.data?.enums).map((item: any) => {
  297. enumList[item.name] = item
  298. })
  299. setApp({ enumDictList: enumList })
  300. resolve(res)
  301. },
  302. fail: (err) => {
  303. reject(err);
  304. }
  305. })
  306. } catch (error) {
  307. reject(error);
  308. }
  309. })
  310. }
  311. /**
  312. * 分享信息获取
  313. * @param path 路径
  314. */
  315. export function getShareInfo(pagePath:string) {
  316. return new Promise(async (resolve, reject) => {
  317. try {
  318. // 初始化
  319. Taro.request({
  320. url: '/app/appPage/getShareInfo',
  321. method: 'GET',
  322. data:{pagePath},
  323. success: (res) => {
  324. resolve(res)
  325. },
  326. fail: (err) => {
  327. reject(err);
  328. }
  329. })
  330. } catch (error) {
  331. reject(error);
  332. }
  333. })
  334. }