index.ux 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <import name="short-page" src="../../components/short/index.ux"></import>
  2. <import name="wechat-page" src="../../components/wechat/index.ux"></import>
  3. <template>
  4. <div id="reader-content">
  5. <stack>
  6. <div class="reader-wrap" id='list' style="background-color:{{currentColor.color}}">
  7. <div class="reader-title">
  8. <text class="title" style="color:{{isNight=='night'?'#666':'#333'}}">{{bookinfo.chapter_name}}</text>
  9. <!-- <text class="add-shelf" @click="addShelf">加入书架1</text> -->
  10. </div>
  11. <div class="reader-content">
  12. <div class="readContent" @click="showMore"><text class="chapter-text" for='content' style="color:{{currentColor.fontColor}};font-size:{{`${readFontSize}px`}}">{{$item}}</text></div>
  13. <div class="bottom-setting" style="background-color:{{currentColor.btColor}}" if={{showSetting}} @click="stopPop">
  14. <div class="item-content">
  15. <text class="label-min" style="color:{{isNight=='night'?'#666':'#333'}}">A</text>
  16. <slider class="slider" min="30" max="48" step="2" value="{{readFontSize}}" onchange="changeFontSize" style="blockColor: #fff"></slider>
  17. <text class="label-max" style="color:{{isNight=='night'?'#666':'#333'}}">A</text>
  18. </div>
  19. <div class="item-color">
  20. <text class="colori" for="colorList" onclick="changeColor($item,undefined)" style="border-color:{{currentColor.color==$item.color? currentBorder: $item.borderColor}};background-color:{{$item.color}};"></text>
  21. <text class="color-icon {{ isNight }}" onclick="changeColor(nightColor,isNight)"></text>
  22. </div>
  23. <div class="item-page">
  24. <text @click="getPrevChapter" style="color:{{isNight=='night'?'#666':'#333'}}">上一章</text>
  25. <text @click="toCatalog" style="color:{{isNight=='night'?'#666':'#333'}}">目录</text>
  26. <text @click="getNextChapter" style="color:{{isNight=='night'?'#666':'#333'}}">下一章</text>
  27. </div>
  28. <div>
  29. </div>
  30. <div class="setting-top" style="background-color:{{currentColor.color}}" if={{showSetting}} @click="backRouter">
  31. <image src="{{getImgUrl}}" class="back-icon"></image> <text style="color:{{isNight=='night'?'#666':'#333'}}">{{bookinfo.chapter_name}}</text><text style="text-indent:-999px">1</text>
  32. </div>
  33. </div>
  34. <div class="banner-list" if="{{reader_banner.length>0}}">
  35. <swiper class="swipe-bar" autoplay="true" indicator="false">
  36. <block for="reader_banner">
  37. <div class="swipe-item">
  38. <image class="cover" src="{{$item.img}}" @click="goActivity($item)"></image>
  39. </div>
  40. </block>
  41. </swiper>
  42. </div>
  43. </div>
  44. <short-page if="{{showShortPop}}" @addshort="shortEnd"></short-page>
  45. <!-- <wechat-page></wechat-page> -->
  46. <div class='toast' if="{{showtoast}}">
  47. <text>正在加载中...</text>
  48. </div>
  49. </stack>
  50. <div class="reader-bottom">
  51. <div class="reader-operator-next" @click="getNextChapter"><text class="operator">下一章</text></div>
  52. <div class="reader-operator">
  53. <text class="operator prev" @click="getPrevChapter">上一章</text>
  54. <text>|</text>
  55. <text class="operator catalog" @click="toCatalog">目录</text>
  56. </div>
  57. </div>
  58. <div class="mustToask" show="{{showMustTost}}">
  59. <div class="mustBox">
  60. <text class="title-must">
  61. 提示
  62. </text>
  63. <text class="content">
  64. 添加桌面后方可继续阅读精彩内容
  65. </text>
  66. <text class="button-must" @click="addDestop">添加到桌面</text>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import prompt from '@system.prompt';
  73. import router from "@system.router";
  74. import storage from '@system.storage';
  75. import it from "../../helper/interface.js";
  76. import { getChapters, getIsonshelf, postUserShelfBooks, chapterOrders, userAddDsktop } from "../../api";
  77. import { getAppConfig } from '../../api/utils.js';
  78. let getConfig;
  79. export default {
  80. // protected: {
  81. // bid: '',
  82. // chapter_id: ''
  83. // },
  84. public: {
  85. bid: '',
  86. chapter_id: '',
  87. send_order_id: "",
  88. push_id: "",
  89. canReadecid: "",
  90. showtoast: false
  91. },
  92. private: {
  93. bookinfo: {},
  94. content: [],
  95. reader_banner: [],
  96. showShortPop: false,
  97. readFontSize: 38,
  98. isNight: 'sun',
  99. hasShort: false,
  100. showSetting: false,
  101. force_add_desk_type: 0,
  102. showMustTost: false,
  103. back_reader: 0,
  104. colorList: [
  105. { color: '#DFDAC7', borderColor: '#6090AE', btColor: '#E8F6FF', isIcon: false },
  106. { color: '#E6E6E6', borderColor: '#CCC', btColor: '#F2F2F2', isIcon: false },
  107. { color: '#EED9BB', borderColor: '#C6A473', btColor: '#FFFBE8', isIcon: false },
  108. { color: '#B3E2CB', borderColor: '#68AA8A', btColor: '#D5F2D8', isIcon: false },
  109. { color: '#B3D0E2', borderColor: '#6090AE', btColor: '#E8F6FF', isIcon: false },
  110. ],
  111. currentBorder: '#EE6159',
  112. nightColor: {
  113. fontColor: '#666',
  114. btColor: '#333',
  115. color: '#1a1a1a'
  116. },
  117. currentColor: {
  118. color: '#DFDAC7', btColor: '#F2F2F2', fontColor: '#1a1a1a'
  119. }
  120. },
  121. computed: {
  122. getImgUrl() {
  123. return this.isNight == 'night' ? '../../assets/imgs/white_back.png' : '../../assets/imgs/black_back.png'
  124. }
  125. },
  126. async onInit() {
  127. if (this.send_order_id) {
  128. await storage.set({ key: "send_order_id", value: this.send_order_id });
  129. } else {
  130. let send_order_id = (await storage.get({ key: "send_order_id" })).data;
  131. if (send_order_id) this.send_order_id = send_order_id;
  132. }
  133. if (this.push_id) {
  134. await storage.set({ key: "push_id", value: this.push_id });
  135. }
  136. /* let s = (await storage.get({ key: "send_order_id" })).data;
  137. console.log("save send_order_id in storage");
  138. console.log("send_order_id", this.send_order_id);
  139. console.log("storage send_order_id", s); */
  140. await this.getChapters(this.bid, this.chapter_id);
  141. let setting = (await storage.get({ key: "readSetting" })).data;
  142. if (setting) {
  143. let sets = JSON.parse(setting)
  144. this.currentColor = sets;
  145. this.isNight = sets.isNight;
  146. }
  147. let font = (await storage.get({ key: "readFont" })).data;
  148. if (font) {
  149. this.readFontSize = font;
  150. }
  151. getConfig = getAppConfig(this);
  152. let { reader_banner } = await getConfig('position');
  153. this.reader_banner = reader_banner;
  154. let { sign_out_reader_show } = await getConfig('add_desk_alert');
  155. this.back_reader = sign_out_reader_show;
  156. userAddDsktop(this.$app.$def.data.backClickCount).then(res => {
  157. //TODO 加桌后统计上报
  158. }).catch(r => {
  159. //TODO 失败后统计上报
  160. });
  161. },
  162. goActivity(item) {
  163. router.push({
  164. uri: item.url,
  165. params: item.params
  166. })
  167. },
  168. backRouter() {
  169. if (this.back_reader == 1) {
  170. it.backCreateShortCut(res => {
  171. if (res == 'back') {
  172. if (router.getLength() === 1) {
  173. router.replace({ uri: "/views/Index" });
  174. return true;
  175. } else {
  176. router.back()
  177. }
  178. }
  179. });
  180. } else {
  181. if (router.getLength() === 1) {
  182. router.replace({ uri: "/views/Index" });
  183. return true;
  184. } else {
  185. router.back()
  186. }
  187. }
  188. },
  189. async onShow() {
  190. it.getShortCut((value) => {
  191. this.showSetting = false;
  192. this.showShortPop = !value;
  193. this.hasShort = value;
  194. if (value) {
  195. this.$app.$def.data.backClickCount = 1
  196. } else {
  197. this.$app.$def.data.backClickCount = 0
  198. }
  199. })
  200. let params = {
  201. bid: this.bid,
  202. chapter_id: this.chapter_id,
  203. }
  204. await storage.set({ key: "lastCapter", value: JSON.stringify(params) });
  205. },
  206. stopPop(evt) {
  207. evt.stopPropagation();
  208. return;
  209. },
  210. showMore() {
  211. this.showSetting = !this.showSetting;
  212. if (this.showSetting) {
  213. this.showShortPop = false;
  214. } else {
  215. if (!this.hasShort) this.showShortPop = true;
  216. }
  217. },
  218. async changeFontSize(evt) {
  219. this.readFontSize = evt.progress;
  220. await storage.set({ key: "readFont", value: this.readFontSize });
  221. },
  222. async changeColor(item, type) {
  223. if (type) {
  224. if (type == 'sun') {
  225. this.isNight = 'night';
  226. this.currentColor = this.nightColor;
  227. await storage.set({ key: "readSetting", value: JSON.stringify({ ...this.nightColor, isNight: 'night' }) });
  228. } else {
  229. this.isNight = 'sun';
  230. this.currentColor = { color: '#E6E6E6', borderColor: '#CCC', btColor: '#F2F2F2', isIcon: false };
  231. await storage.set({ key: "readSetting", value: JSON.stringify({ ...this.currentColor, isNight: 'sun' }) });
  232. }
  233. } else {
  234. this.isNight = 'sun';
  235. this.currentColor = {
  236. color: item.color,
  237. btColor: item.btColor,
  238. fontColor: '#1a1a1a'
  239. }
  240. await storage.set({ key: "readSetting", value: JSON.stringify({ ...this.currentColor, isNight: 'sun' }) });
  241. }
  242. },
  243. addShelf() {
  244. console.log("add shelf");
  245. getIsonshelf({ bid: this.bid }).then(r => {
  246. r.is_on ? '' : postUserShelfBooks({ bid: this.bid })
  247. })
  248. },
  249. shortEnd(value) {
  250. if (value.detail.installed) {
  251. this.showMustTost = false;
  252. prompt.showToast({ message: "添加桌面成功!请前往任务中心领取奖励" });
  253. }
  254. this.showShortPop = !value.detail.installed;
  255. this.hasShort = value.detail.installed;
  256. },
  257. getChapters(bid, chapter_id) {
  258. this.showtoast = true
  259. console.log("router length:", router.getLength());
  260. getChapters({ bid: bid, chapter_id: chapter_id }).then(r => {
  261. this.force_add_desk_type = r.force_add_desk_type;
  262. this.content = r.chapter_content.trim().split(/\n/)
  263. this.bookinfo = r;
  264. // this.$element('list').scrollTo({ index: 0 })
  265. this.addShelf();
  266. this.showtoast = false
  267. }).catch(e => {
  268. console.log('e code')
  269. console.log(e.data)
  270. console.log(e.data.code == '10016' || e.data.code == '10019')
  271. if (e.data.code == '10016' || e.data.code == '10019' || e.data.code == '10017') {
  272. chapterOrders({ bid: bid, chapter_id: chapter_id }).then(r => {
  273. this.content = r.chapter_content.trim().split(/\n/)
  274. this.bookinfo = r
  275. this.showtoast = false
  276. // this.$element('list').scrollTo({ index: 0 })
  277. }).catch(f => {
  278. console.log('f code')
  279. console.log(f.data)
  280. this.showtoast = false
  281. if (f.data.code == '10014' || f.data.code == '10015' || f.data.code == '10016') {
  282. this.getChapters(bid, this.canReadecid)
  283. router.push({
  284. uri: "/views/Pay",
  285. params: {
  286. code: f.data.code,
  287. fee: e.data.data.fee,
  288. bid: this.bid
  289. }
  290. })
  291. }
  292. })
  293. } else if (e.data.code == '10014' || e.data.code == '10015') {
  294. this.showtoast = false
  295. this.getChapters(bid, this.canReadecid)
  296. router.push({
  297. uri: "/views/Pay",
  298. params: {
  299. code: e.data.code,
  300. fee: e.data.data.fee,
  301. bid: this.bid
  302. }
  303. })
  304. }
  305. })
  306. },
  307. toCatalog(evt) {
  308. evt.stopPropagation();
  309. router.replace({
  310. uri: "/views/Catalog",
  311. params: {
  312. chapter_sequence: this.bookinfo.chapter_sequence,
  313. bid: this.bid,
  314. chapter_id: this.chapter_id,
  315. fromReader: true,
  316. }
  317. })
  318. },
  319. getPrevChapter(evt) {
  320. evt.stopPropagation();
  321. console.log("get prev chapter");
  322. if (this.bookinfo.prev_cid == 0) {
  323. return prompt.showToast({ message: '已经是第一章啦' });
  324. }
  325. router.replace({
  326. uri: "/views/Reader",
  327. params: {
  328. bid: this.bookinfo.bid,
  329. chapter_id: this.bookinfo.prev_cid,
  330. canReadecid: this.bookinfo.chapter_id
  331. }
  332. })
  333. },
  334. addDestop() {
  335. it.mustCreateShort((res, code) => {
  336. if (res) {
  337. this.goNext();
  338. } else {
  339. prompt.showToast({ message: '开启加桌权限可以领取新人福利哟~' });
  340. }
  341. })
  342. },
  343. getNextChapter(evt) {
  344. evt.stopPropagation();
  345. let _this = this;
  346. if (this.force_add_desk_type == 1) {
  347. it.getShortCut(res => {
  348. if (!res) { this.showMustTost = true; } else {
  349. this.goNext();
  350. }
  351. })
  352. } else if (this.force_add_desk_type == 2) {
  353. it.loseLevelShortCut(res => {
  354. this.goNext();
  355. })
  356. } else {
  357. this.goNext();
  358. }
  359. },
  360. goNext() {
  361. let self =this;
  362. if (this.bookinfo.next_cid == 0) {
  363. router.push({
  364. uri: "/views/Raderover",
  365. params: {
  366. bid: this.bid
  367. }
  368. })
  369. return
  370. }
  371. //判断是否自然流量自然流量付费章节开启付费提醒
  372. if (!this.send_order_id && this.bookinfo.next_chapter_status == 2) {
  373. prompt.showDialog({
  374. title: '温馨提示',
  375. message: `下一章即将消耗${this.bookinfo.next_price}书币哟~`,
  376. buttons: [
  377. {
  378. text: '阅读下一章',
  379. color: '#EF5952'
  380. },
  381. {
  382. text: '我再想想',
  383. color: '#999'
  384. }
  385. ],
  386. success: function (data) {
  387. if (data.index === 0) {
  388. router.replace({
  389. uri: "/views/Reader",
  390. params: {
  391. bid: self.bookinfo.bid,
  392. chapter_id: self.bookinfo.next_cid,
  393. canReadecid: self.bookinfo.chapter_id
  394. }
  395. })
  396. }
  397. },
  398. cancel: function () {
  399. console.log('取消前往')
  400. },
  401. })
  402. } else {
  403. router.replace({
  404. uri: "/views/Reader",
  405. params: {
  406. bid: this.bookinfo.bid,
  407. chapter_id: this.bookinfo.next_cid,
  408. canReadecid: this.bookinfo.chapter_id
  409. }
  410. })
  411. }
  412. // this.getChapters(this.bookinfo.bid, this.bookinfo.next_cid)
  413. },
  414. onBackPress() {
  415. if (this.back_reader == 1) {
  416. it.backCreateShortCut(res => {
  417. if (res == 'back') {
  418. if (router.getLength() === 1) {
  419. router.replace({ uri: "/views/Index" });
  420. return true;
  421. } else {
  422. router.back()
  423. }
  424. }
  425. });
  426. } else {
  427. if (router.getLength() === 1) {
  428. router.replace({ uri: "/views/Index" });
  429. return true;
  430. } else {
  431. router.back()
  432. }
  433. }
  434. return true;
  435. }
  436. }
  437. </script>
  438. <style lang="less">
  439. @import '../../assets/less/reader.less';
  440. </style>