index.ux 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <import name="home-page" src="../Home/index.ux"></import>
  2. <import name="category-page" src="../Category/index.ux"></import>
  3. <import name="shelf-page" src="../Shelf/index.ux"></import>
  4. <import name="my-page" src="../My/index.ux"></import>
  5. <import name="leader-board" src="../Leaderboard/index.ux"></import>
  6. <import name="sign-page" src="../../components/sign/index.ux"></import>
  7. <import name="short-page" src="../../components/short/index.ux"></import>
  8. <import name="policy-page" src="../../components/yinsi/policy.ux"></import>
  9. <template>
  10. <stack class="stack-wrap">
  11. <div class="index-wrap">
  12. <tabs class="tab-content" onchange="tabbarChange" index="{{current}}">
  13. <tab-content>
  14. <shelf-page @change="pageTohome" tabindex="{{current}}"></shelf-page>
  15. <home-page @change="pageSwitch" tabindex="{{current}}"></home-page>
  16. <!-- <category-page tabindex="{{current}}"></category-page> -->
  17. <my-page @customer="openCustomer" tabindex="{{current}}"></my-page>
  18. </tab-content>
  19. </tabs>
  20. <div class="fixed-tabbar">
  21. <image src="../../assets/imgs/shadow.png" class="shadow"></image>
  22. <div class="tabbar-item__wrap">
  23. <block for="tab in tabbar">
  24. <div class="tabbar-item " @click="tabbarChange(tab)">
  25. <image
  26. src="{{tab.index === current ? tab.active_icon : tab.icon}}"
  27. ></image>
  28. <text
  29. class="{{tab.index === current ? 'tabbar-name__cur' : ''}}"
  30. >{{ tab.name }}</text
  31. >
  32. </div>
  33. </block>
  34. </div>
  35. </div>
  36. </div>
  37. <stack>
  38. <!-- <image src="../../assets/imgs/sign_show.png" class="sign-icon" @click="changeSignPop"> </image> -->
  39. <image
  40. src="../../assets/imgs/rukou.png"
  41. class="sign-icon"
  42. @click="goTask"
  43. if="{{home_show}}"
  44. >
  45. </image>
  46. <sign-page if="{{showSignPop}}"></sign-page>
  47. <short-page
  48. if="{{!showActivitys && showShortPop}}"
  49. @addshort="shortEnd"
  50. ></short-page>
  51. <div class="stack-popup" @click="closeWrap" if="showPopup">
  52. <div class="customer-popup">
  53. <text class="title">联系客服</text>
  54. <text class="desc">
  55. 复制微信号或者保存二维码到本地至微信添加客服好友
  56. </text>
  57. <image src="{{cutomerQrcode}}" @longpress="saveImg"></image>
  58. <div class="duplication">
  59. <text class="duplication-text">微信号:{{ cutomerName }}</text
  60. ><text class="duplication-button" @click="duplication">复制</text>
  61. </div>
  62. </div>
  63. </div>
  64. <div
  65. class="mask"
  66. @click="closeAcitivity"
  67. if="{{showActivitys && home_alert}}"
  68. >
  69. <image
  70. src="{{home_alert.img}}"
  71. class="banner"
  72. @click="goActicity"
  73. ></image>
  74. <image
  75. src="../../assets/imgs/pop_close.png"
  76. class="close-pop"
  77. @click="closeAcitivity"
  78. ></image>
  79. </div>
  80. </stack>
  81. <block if="display">
  82. <policy-page @change="dispatchEvent"></policy-page>
  83. </block>
  84. </stack>
  85. </template>
  86. <script>
  87. import clipboard from '@system.clipboard'
  88. import prompt from '@system.prompt'
  89. import device from '@system.device'
  90. import storage from '@system.storage'
  91. import it from '../../helper/interface.js'
  92. import { getCustomQrcode, userAddDsktop, getUserInfo } from '../../api/index.js'
  93. import { downImg, getStore, getAppConfig } from '../../api/utils.js'
  94. import router from '@system.router'
  95. let getConfig
  96. export default {
  97. public: {
  98. curPage: 1,
  99. push_id: '',
  100. bid: '',
  101. chapter_id: '',
  102. send_order_id: '',
  103. link_url: ''
  104. },
  105. protected: {
  106. current: 0,
  107. user: {}
  108. },
  109. home_alert: [],
  110. private: {
  111. tabbar: [
  112. {
  113. name: '书架',
  114. title: '我的书架',
  115. icon: '../../assets/imgs/shelf.png',
  116. active_icon: '../../assets/imgs/shelf_choose.png',
  117. index: 0
  118. },
  119. {
  120. name: '精选',
  121. title: '天天好书',
  122. icon: '../../assets/imgs/home.png',
  123. active_icon: '../../assets/imgs/home_choose.png',
  124. index: 1
  125. },
  126. // {
  127. // name: '分类',
  128. // title: '分类',
  129. // icon: '../../assets/imgs/classify.png',
  130. // active_icon: '../../assets/imgs/classify_choose.png',
  131. // index: 2
  132. // },
  133. {
  134. name: '我的',
  135. title: '个人中心',
  136. icon: '../../assets/imgs/my.png',
  137. active_icon: '../../assets/imgs/my_choose.png',
  138. index: 2
  139. }
  140. ],
  141. // current: 0,
  142. showPopup: false,
  143. showActivitys: false,
  144. showShortPop: false,
  145. showSignPop: false,
  146. home_show: 0,
  147. home_alert: null,
  148. back_alert: 0,
  149. isInit: false,
  150. display: false,
  151. },
  152. async onInit() {
  153. let isFromPush = false
  154. this.$on('dispathEvt', this.changeSignPop)
  155. this.$watch('current', 'watchCurrent')
  156. if (this.push_id) {
  157. await storage.set({ key: 'push_id', value: this.push_id })
  158. }
  159. if (this.send_order_id) {
  160. await storage.set({ key: "send_order_id", value: this.send_order_id });
  161. } else {
  162. let send_order_id = (await storage.get({ key: "send_order_id" })).data;
  163. if (send_order_id) this.send_order_id = send_order_id;
  164. }
  165. //获取当前是否隐私弹窗
  166. let showPolicy = (await storage.get({ key: "agreeFlag" })).data;
  167. if (!this.send_order_id && !showPolicy) this.display = true;
  168. //今日已签到过不在弹框签到
  169. if (this.curPage && this.curPage > 0) {
  170. this.current = this.curPage
  171. }
  172. getConfig = getAppConfig(this)
  173. let { home_show } = await getConfig('task_center')
  174. this.home_show = home_show
  175. let { home_alert } = await getConfig('position')
  176. if (home_alert.length > 0) {
  177. this.home_alert = home_alert[0]
  178. this.showActivitys = true
  179. }
  180. let { sign_out_app_show } = await getConfig('add_desk_alert')
  181. this.back_alert = sign_out_app_show
  182. this.getCoustom()
  183. this.getUser()
  184. this.current = 0;
  185. },
  186. goActicity() {
  187. router.push({
  188. uri: '/views/Activity',
  189. params: this.home_alert.params
  190. })
  191. },
  192. showActivity() {
  193. this.showActivitys = true
  194. },
  195. closeAcitivity() {
  196. this.showActivitys = false
  197. },
  198. dispatchEvent(evt) {
  199. this.display = evt.detail.display
  200. this.save()
  201. },
  202. save() {
  203. storage.set({
  204. key: 'agreeFlag',
  205. value: 'agree',
  206. })
  207. },
  208. toMyRead(evt) {
  209. console.log(evt.detail.count)
  210. },
  211. async onShow() {
  212. const hasInit = this.$app.getAppData('hasInit')
  213. if (hasInit) {
  214. this.$broadcast('refreshData', { current: this.current })
  215. }
  216. it.getShortCut(value => {
  217. this.showShortPop = !value
  218. if (value) {
  219. this.$app.$def.data.backClickCount = 1
  220. } else {
  221. this.$app.$def.data.backClickCount = 0
  222. }
  223. })
  224. this.$app.setAppData('hasInit', true)
  225. },
  226. shortEnd(value) {
  227. if (value.detail.msg) {
  228. prompt.showToast({ message: '用户禁止创建' })
  229. } else if (value.detail.installed) {
  230. prompt.showToast({ message: '添加桌面成功!请前往任务中心领取奖励' })
  231. }
  232. this.showShortPop = !value.detail.installed
  233. },
  234. watchCurrent(i) {
  235. this.current = i
  236. },
  237. async getUser() {
  238. let user = await getUserInfo()
  239. this.user = user
  240. this.isInit = true
  241. if (this.send_order_id && this.link_url) {
  242. let params = {
  243. push_id: this.push_id,
  244. bid: this.bid,
  245. chapter_id: this.chapter_id,
  246. send_order_id: this.send_order_id
  247. }
  248. setTimeout(() => {
  249. router.push({
  250. uri: this.link_url,
  251. params: params
  252. })
  253. }, 800)
  254. }
  255. },
  256. goTask() {
  257. router.push({
  258. uri: '/views/Task'
  259. })
  260. },
  261. onBackPress() {
  262. // 退出逻辑
  263. if (this.$app.$def.data.backClickCount === 0 && this.back_alert == 1) {
  264. this.$app.$def.data.backClickCount++
  265. this.$app.$def.createShortcut()
  266. return true
  267. }
  268. },
  269. changeShortCut() {
  270. this.showShortPop = false
  271. },
  272. async getCoustom() {
  273. userAddDsktop(this.$app.$def.data.backClickCount)
  274. .then(res => {
  275. //TODO 加桌后统计上报
  276. })
  277. .catch(r => {
  278. //TODO 失败后统计上报
  279. })
  280. let res = await getCustomQrcode()
  281. this.cutomerQrcode = res.url
  282. this.cutomerName = res.name
  283. },
  284. tabbarChange(tab) {
  285. this.current = tab.index
  286. //this.$page.setTitleBar({ text: this.tabbar[tab.index].title });
  287. },
  288. pageSwitch() {
  289. this.current = 0
  290. },
  291. pageTohome() {
  292. this.current = 1
  293. },
  294. changeSignPop() {
  295. this.showSignPop = !this.showSignPop
  296. },
  297. closeWrap() {
  298. this.showPopup = false
  299. },
  300. //复制客服微信
  301. duplication() {
  302. clipboard.set({
  303. text: this.cutomerName,
  304. success: function (data) {
  305. prompt.showToast({
  306. message: '复制成功!'
  307. })
  308. }
  309. })
  310. },
  311. //长按保存图片
  312. saveImg() {
  313. downImg(this.cutomerQrcode)
  314. },
  315. openCustomer() {
  316. this.showPopup = true
  317. }
  318. }
  319. </script>
  320. <style lang="less">
  321. @import '../../assets/less/index.less';
  322. </style>