You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

720 lines
18 KiB

  1. <template>
  2. <view id="home" class="page">
  3. <!-- 顶部搜索栏 -->
  4. <view class="header text-white">
  5. <!-- #ifndef H5 -->
  6. <l-icon
  7. @click="scanClick"
  8. type="scan"
  9. color="white"
  10. class="header-left text-xxl margin-left-sm"
  11. />
  12. <!-- #endif -->
  13. <view @click="moreClick(1)" class="search header-mid margin-lr-sm">
  14. <l-icon type="search" color="white" class="margin-lr-sm" />
  15. 搜索更多应用
  16. </view>
  17. <l-icon
  18. @click="msgClick"
  19. type="mail"
  20. color="white"
  21. class="header-right text-xxl margin-right-sm"
  22. />
  23. </view>
  24. <!-- 轮播图片 -->
  25. <swiper v-if="imgCount > 0" style="height: 120px">
  26. <swiper-item
  27. v-for="(item, index) of imgData"
  28. :key="index"
  29. style="height: 120px"
  30. >
  31. <image
  32. :src="item"
  33. mode="aspectFill"
  34. style="height: 100%; width: 100%"
  35. ></image>
  36. </swiper-item>
  37. </swiper>
  38. <!-- 功能宫格列表 -->
  39. <view class="col-4 function-list cu-list grid no-border">
  40. <view
  41. v-for="(item, index) in funcListDisplay"
  42. @click="funcListClick(item)"
  43. :key="index"
  44. class="cu-item text-center flex flex-wrap justify-center align-center"
  45. >
  46. <view
  47. class="app-item align-center flex flex-wrap justify-center align-center"
  48. >
  49. <l-icon :type="item.icon" color="white" class="text-sl" />
  50. </view>
  51. <text>{{ item.F_Name }}</text>
  52. </view>
  53. </view>
  54. <view class="text-center bg-white margin-bottom"
  55. ><text
  56. @click="moreClick(0)"
  57. class="function-more-btn margin-tb-sm text-gray"
  58. >更多应用</text
  59. ></view
  60. >
  61. <!-- 统计数据宫格 -->
  62. <l-title>统计数据</l-title>
  63. <view class="count-list cu-list grid col-3 margin-bottom">
  64. <view
  65. v-for="(item, index) in countData"
  66. :key="index"
  67. class="cu-item text-center"
  68. >
  69. <text class="margin-bottom-xs">{{ item.title || "(未命名)" }}</text>
  70. <text class="count-item-value">{{ item.value || "-" }}</text>
  71. </view>
  72. </view>
  73. <!-- 通知列表区块 -->
  74. <view
  75. v-for="(block, blockIndex) of noticeData"
  76. :key="blockIndex"
  77. class="margin-bottom"
  78. >
  79. <!-- <view class="margin-top"></view> -->
  80. <l-title @click="informClick(block.title)">{{ block.title }}</l-title>
  81. <l-list>
  82. <l-list-item
  83. v-for="(item, i) of block.content"
  84. @click="noticeClick(item)"
  85. :key="i"
  86. arrow
  87. >
  88. {{ item.f_title || "(无标题)" }}
  89. <l-tag slot="action" line="gray">{{
  90. postDateTime(item.f_time)
  91. }}</l-tag>
  92. </l-list-item>
  93. </l-list>
  94. </view>
  95. <!-- 图表区块 -->
  96. <view v-for="item of chartData" :key="item.id" class="margin-bottom">
  97. <l-title>{{ item.title }}</l-title>
  98. <view
  99. :style="{ width: cWidth + 'px', height: cHeight + 'px' }"
  100. class="chart-list"
  101. >
  102. <!--#ifndef MP-ALIPAY -->
  103. <canvas
  104. v-if="item.type === 1"
  105. @tap="chartTap(item, $event)"
  106. @touchstart="touchStart(item.id, $event)"
  107. @touchmove="touchMove(item.id, $event)"
  108. @touchend="touchEnd(item.id, $event)"
  109. :style="{ width: cWidth + 'px', height: cHeight + 'px' }"
  110. :canvas-id="item.id"
  111. :id="item.id"
  112. class="charts"
  113. ></canvas>
  114. <canvas
  115. v-else
  116. @tap="chartTap(item, $event)"
  117. :style="{ width: cWidth + 'px', height: cHeight + 'px' }"
  118. :canvas-id="item.id"
  119. :id="item.id"
  120. class="charts"
  121. ></canvas>
  122. <!--#endif -->
  123. <!-- 阿里小程序,需要以2倍尺寸显示,然后缩放为50% -->
  124. <!--#ifdef MP-ALIPAY -->
  125. <canvas
  126. v-if="item.type === 1"
  127. @tap="chartTap(item, $event)"
  128. @touchstart="touchStart(item.id, $event)"
  129. @touchmove="touchMove(item.id, $event)"
  130. @touchend="touchEnd(item.id, $event)"
  131. :style="{
  132. width: cWidth * pixelRatio + 'px',
  133. height: cHeight * pixelRatio + 'px',
  134. transform: 'scale(' + 1 / pixelRatio + ')',
  135. marginLeft: (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  136. marginTop: (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  137. }"
  138. :canvas-id="item.id"
  139. :id="item.id"
  140. class="charts"
  141. ></canvas>
  142. <canvas
  143. v-else
  144. @tap="chartTap(item, $event)"
  145. :style="{
  146. width: cWidth * pixelRatio + 'px',
  147. height: cHeight * pixelRatio + 'px',
  148. transform: 'scale(' + 1 / pixelRatio + ')',
  149. marginLeft: (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  150. marginTop: (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  151. }"
  152. :canvas-id="item.id"
  153. :id="item.id"
  154. class="charts"
  155. ></canvas>
  156. <!--#endif -->
  157. </view>
  158. </view>
  159. </view>
  160. </template>
  161. <script>
  162. import moment from "moment";
  163. import mapValues from "lodash/mapValues";
  164. import uCharts from "@/common/u-charts.js";
  165. // 用于保存图表操作对象
  166. let chartsObject = {};
  167. let chartsConfig = {};
  168. export default {
  169. data() {
  170. return {
  171. imgData: [],
  172. listData: [],
  173. myList: [],
  174. countData: [],
  175. noticeData: [],
  176. chartData: [],
  177. pixelRatio: 1,
  178. cWidth: "",
  179. cHeight: "",
  180. chartsFontSize: 10,
  181. };
  182. },
  183. async onLoad(param) {
  184. if(this.GET_STORAGE('pwd')){
  185. location.href = "http://" + window.location.host + "/#/pages/my/newpassword";
  186. return
  187. }
  188. await this.init(param);
  189. },
  190. // 本页面开启下拉刷新,用于刷新首页数据
  191. onPullDownRefresh() {
  192. this.refresh().then(() => {
  193. this.TOAST("已更新首页数据");
  194. uni.stopPullDownRefresh();
  195. });
  196. },
  197. methods: {
  198. // 页面初始化
  199. async init(param) {
  200. this.HIDE_LOADING();
  201. // 有参数表示可能是打开分享消息;将数据存入全局变量以备后续跳转
  202. if (param && param.learun && param.pagePath) {
  203. this.SET_GLOBAL("jumpParam", param);
  204. }
  205. // 登录状态无效,则跳转到登录页
  206. const stateValid = await this.checkLoginState();
  207. if (!stateValid) {
  208. this.RELAUNCH_TO("/pages/login");
  209. return;
  210. }
  211. // 图表相关参数初始化
  212. this.initCharts();
  213. // 加载页面数据和全局数据
  214. await this.FETCH_CLIENTDATA();
  215. await this.refresh();
  216. // 监听「我的应用」列表修改
  217. this.ON("home-list-change", () => {
  218. this.HTTP_GET("learun/adms/function/mylist").then((newList) => {
  219. this.myList = newList;
  220. });
  221. });
  222. this.SET_STORAGE("nextTime", null);
  223. // 处理小程序分享消息跳转
  224. // #ifdef MP
  225. const jumpParam = this.GET_GLOBAL("jumpParam");
  226. if (jumpParam) {
  227. this.SET_GLOBAL("jumpParam", null);
  228. this.MP_SHARE_DECODE(jumpParam);
  229. }
  230. // #endif
  231. //微信推送跳转
  232. if (!!param.page) {
  233. //通知公告
  234. if (param.page == "notice") {
  235. this.NAV_TO("/pages/LR_OAModule/list");
  236. }
  237. //邮件
  238. if (param.page == "mail") {
  239. this.NAV_TO("/pages/EducationalAdministration/SYS_ReceiveMessage/list");
  240. }
  241. //OA待办
  242. if (param.page == "oa") {
  243. this.NAV_TO("/pages/nworkflow/myflow/list");
  244. }
  245. //公文下发
  246. if (param.page == "file") {
  247. this.NAV_TO("/pages/EducationalAdministration/Sys_ReceiveFile/list");
  248. }
  249. return;
  250. }
  251. },
  252. // 验证登录状态
  253. async checkLoginState() {
  254. const token = this.GET_GLOBAL("token") || uni.getStorageSync("token");
  255. if (!token || token === "null" || token === "undefined") {
  256. this.RELAUNCH_TO("/pages/login");
  257. this.HIDE_LOADING();
  258. return false;
  259. }
  260. this.SET_GLOBAL("token", token);
  261. // 判断是否有 loginUser 对象
  262. if (this.GET_GLOBAL("loginUser")) {
  263. return true;
  264. }
  265. // 拉取用户信息验证登录态;如果失败则跳转至登录页
  266. const userInfo = await this.HTTP_GET("learun/adms/user/info");
  267. if (!userInfo) {
  268. this.SET_GLOBAL("token", null);
  269. this.SET_STORAGE("token", null);
  270. return false;
  271. }
  272. // 有登录态,则设置用户信息和全局数据
  273. const { baseinfo, mpinfo, post, role } = userInfo;
  274. const user = { ...baseinfo, post, role };
  275. if (mpinfo && Array.isArray(mpinfo) && mpinfo.includes(this.PLATFORM)) {
  276. user.miniProgram = true;
  277. }
  278. this.SET_GLOBAL("loginUser", user);
  279. return true;
  280. },
  281. // 刷新首页数据
  282. async refresh() {
  283. // 清空页面数据
  284. chartsObject = {};
  285. this.imgData = [];
  286. this.listData = [];
  287. this.myList = [];
  288. this.countData = [];
  289. this.noticeData = [];
  290. this.chartData = [];
  291. // 同时发出请求,获取轮播图、所有功能列表、我的功能列表、商机通知提醒图表数据
  292. // 商机、通知提醒图表数据,获取的是数据ID,所以还需要进一步请求
  293. const [imgData, listData, myList, settingData] = await Promise.all([
  294. this.HTTP_GET(
  295. "learun/adms/desktop/imgid" +
  296. (this.CONFIG("isDistributed") == true ? "?isDistributed=true" : "")
  297. ),
  298. this.HTTP_GET("learun/adms/function/list").then(
  299. (result) => result.data
  300. ),
  301. this.HTTP_GET("learun/adms/function/mylist"),
  302. this.HTTP_GET("learun/adms/desktop/setting").then(
  303. (result) => result.data
  304. ),
  305. ]);
  306. this.imgData = imgData;
  307. if (!this.CONFIG("isDistributed"))
  308. // 轮播图需要加上 url 前缀
  309. this.imgData = imgData.map((t) => this.API + `/desktop/img?data=${t}`);
  310. // 功能区按钮需要处理 icon
  311. this.listData = listData.map((item) => {
  312. const icon = item.F_Icon
  313. ? item.F_Icon.replace(`iconfont icon-`, ``)
  314. : "";
  315. const existsIcon = this.getUiIcons().some((t) => t === icon);
  316. return {
  317. ...item,
  318. icon: existsIcon ? icon : "roundright",
  319. };
  320. });
  321. // 我的应用列表需要过滤掉不存在的按钮
  322. this.myList = myList.filter((t) =>
  323. listData.find((item) => item.F_Id === t)
  324. );
  325. // 发出请求,获取商机信息、消息通知信息、图表信息;三类数据全部同时请求
  326. await Promise.all([
  327. ...settingData.target.map((item) =>
  328. this.HTTP_GET("learun/adms/desktop/data", {
  329. type: "Target",
  330. id: item.F_Id,
  331. }).then((data) => {
  332. if (data && data.value) {
  333. const { value } = data;
  334. this.countData.push({
  335. title: item.F_Name,
  336. value,
  337. });
  338. }
  339. })
  340. ),
  341. ...settingData.list.map((item) =>
  342. this.HTTP_GET("learun/adms/desktop/data", {
  343. type: "list",
  344. id: item.F_Id,
  345. }).then((data) => {
  346. if (data && data.value) {
  347. const { value } = data;
  348. this.noticeData.push({
  349. title: item.F_Name,
  350. content: value,
  351. });
  352. }
  353. })
  354. ),
  355. ...settingData.chart.map((item) =>
  356. this.HTTP_GET("learun/adms/desktop/data", {
  357. type: "chart",
  358. id: item.F_Id,
  359. }).then((data) => {
  360. if (data && data.value) {
  361. const { value } = data;
  362. this.chartData.push({
  363. title: item.F_Name,
  364. value,
  365. id: item.F_Id,
  366. type: item.F_Type,
  367. });
  368. }
  369. })
  370. ),
  371. ]);
  372. // 渲染图表
  373. this.chartData.forEach((item) => {
  374. // 根据 item.type 的值选用对应的图表初始化配置项
  375. // 0=环形图;1=折线图;2=柱状图
  376. const charts = new uCharts(
  377. [
  378. {
  379. ...chartsConfig,
  380. canvasId: item.id,
  381. type: "ring",
  382. series: item.value.map((t) => ({
  383. name: t.name,
  384. data: t.value,
  385. })),
  386. extra: {
  387. pie: {
  388. offsetAngle: -45,
  389. ringWidth: 20,
  390. labelWidth: 15,
  391. },
  392. },
  393. legend: {
  394. lineHeight: 20,
  395. },
  396. },
  397. {
  398. ...chartsConfig,
  399. canvasId: item.id,
  400. type: "line",
  401. series: [
  402. {
  403. name: item.title,
  404. data: item.value.map((t) => t.value),
  405. },
  406. ],
  407. categories: item.value.map((t) => t.name),
  408. extra: {
  409. line: {
  410. type: "straight",
  411. },
  412. },
  413. xAxis: {
  414. rotateLabel: true,
  415. fontSize: this.chartsFontSize,
  416. itemCount: 8,
  417. },
  418. enableScroll: true,
  419. },
  420. {
  421. ...chartsConfig,
  422. canvasId: item.id,
  423. type: "column",
  424. series: [
  425. {
  426. name: item.title,
  427. data: item.value.map((t) => t.value),
  428. },
  429. ],
  430. categories: item.value.map((t) => t.name),
  431. xAxis: {
  432. rotateLabel: true,
  433. fontSize: this.chartsFontSize,
  434. },
  435. },
  436. ][item.type]
  437. );
  438. chartsObject[item.id] = charts;
  439. });
  440. },
  441. // 初始化图表
  442. initCharts() {
  443. // (阿里小程序)设置图表尺寸为2倍
  444. // #ifdef MP-ALIPAY
  445. const pixelRatio = uni.getSystemInfoSync().pixelRatio;
  446. if (pixelRatio > 1) {
  447. this.pixelRatio = 2;
  448. this.chartsFontSize = 15;
  449. }
  450. // #endif
  451. this.cWidth = uni.upx2px(750);
  452. this.cHeight = uni.upx2px(500);
  453. chartsConfig = {
  454. $this: this,
  455. pixelRatio: this.pixelRatio,
  456. width: this.cWidth * this.pixelRatio,
  457. height: this.cHeight * this.pixelRatio,
  458. background: "#FFFFFF",
  459. dataLabel: true,
  460. padding: [20, 15, 5, 15],
  461. };
  462. },
  463. // 图表点击事件
  464. chartTap(chartItem, e) {
  465. const format = ({ name, data }, category) =>
  466. `${category || ""} ${name}: ${data}`;
  467. // #ifdef MP-DINGTALK
  468. const detail = e.detail;
  469. const item = detail;
  470. e.mp.changedTouches = [item];
  471. // #endif
  472. chartsObject[chartItem.id].showToolTip(e, {
  473. format,
  474. });
  475. },
  476. // 图表拖动事件(开始)
  477. touchStart(chartId, e) {
  478. chartsObject[chartId].scrollStart(e);
  479. },
  480. // 图表拖动事件(拖动)
  481. touchMove(chartId, e) {
  482. chartsObject[chartId].scroll(e);
  483. },
  484. // 图表拖动事件(结束)
  485. touchEnd(chartId, e) {
  486. chartsObject[chartId].scrollEnd(e);
  487. },
  488. // 格式化日期的显示(新闻列表、通知公告等)
  489. postDateTime(timeStr) {
  490. return moment(timeStr).fromNow();
  491. },
  492. // 点击功能按钮
  493. funcListClick(item) {
  494. if (item.F_IsSystem === 2) {
  495. this.NAV_TO(
  496. `/pages/customapp/list?formId=${item.F_FormId}`,
  497. item,
  498. true
  499. );
  500. return;
  501. }
  502. this.NAV_TO(`/pages/${item.F_Url}/list`);
  503. },
  504. // 点击通知公告的标题
  505. noticeClick(item) {
  506. console.log(item);
  507. this.NAV_TO("/pages/home/notice", item, true);
  508. },
  509. informClick(titleName) {
  510. if (titleName == "通知公告") {
  511. this.NAV_TO("/pages/LR_OAModule/list", "", true);
  512. }
  513. },
  514. // #ifndef H5
  515. // 点击左上角扫码图标,H5 无此功能
  516. scanClick() {
  517. uni.scanCode({
  518. scanType: ["qrCode", "barCode"],
  519. success: ({ result, charSet }) => {
  520. // 您可以在这里自行定制扫码后的功能
  521. },
  522. });
  523. },
  524. // #endif
  525. // 点击更多功能按钮
  526. moreClick(openSearch) {
  527. this.NAV_TO(`/pages/home/more${openSearch ? "?search=1" : ""}`);
  528. },
  529. // 点击右上角的消息按钮
  530. msgClick() {
  531. this.TAB_TO("/pages/msg");
  532. },
  533. },
  534. computed: {
  535. // 「我的功能」区域按钮列表
  536. funcListDisplay() {
  537. const { myList, listData } = this;
  538. const myFuncList = myList.reduce((list, id) => {
  539. if (listData.find((t) => t.F_Id === id)) {
  540. return [...list, listData.find((t) => t.F_Id === id)];
  541. }
  542. return list;
  543. }, []);
  544. return myFuncList;
  545. },
  546. // imgData 数组的长度
  547. imgCount() {
  548. return this.imgData.length;
  549. },
  550. },
  551. };
  552. </script>
  553. <style lang="less" scoped>
  554. .page {
  555. background-color: #f3f3f3;
  556. .header {
  557. height: 100rpx;
  558. background-color: #0c86d8;
  559. display: flex;
  560. align-items: center;
  561. .header-left {
  562. flex-grow: 0;
  563. }
  564. .header-mid {
  565. flex-grow: 1;
  566. background-color: #3d9ee0;
  567. line-height: 60rpx;
  568. height: 60rpx;
  569. font-size: 24rpx;
  570. color: #fff;
  571. border-radius: 6rpx;
  572. }
  573. .header-right {
  574. flex-grow: 0;
  575. }
  576. }
  577. .content {
  578. background-color: #fff;
  579. }
  580. .function-list {
  581. padding-bottom: 0;
  582. .cu-item {
  583. .app-item {
  584. border-radius: 50%;
  585. height: 45px;
  586. width: 45px;
  587. }
  588. &:nth-child(7n + 1) > .app-item {
  589. background-color: #62bbff;
  590. }
  591. &:nth-child(7n + 2) > .app-item {
  592. background-color: #7bd2ff;
  593. }
  594. &:nth-child(7n + 3) > .app-item {
  595. background-color: #ffd761;
  596. }
  597. &:nth-child(7n + 4) > .app-item {
  598. background-color: #fe955c;
  599. }
  600. &:nth-child(7n + 5) > .app-item {
  601. background-color: #ff6283;
  602. }
  603. &:nth-child(7n + 6) > .app-item {
  604. background-color: #60e3f3;
  605. }
  606. &:nth-child(7n) > .app-item {
  607. background-color: #acc8fe;
  608. }
  609. }
  610. }
  611. .function-more-btn {
  612. display: inline-block;
  613. border: currentColor 1px solid;
  614. border-radius: 2px;
  615. padding: 10rpx 50rpx;
  616. }
  617. .count-list {
  618. &:after {
  619. content: "";
  620. clear: both;
  621. display: table;
  622. }
  623. .count-item-value {
  624. color: #0188d2;
  625. font-size: 24px;
  626. }
  627. }
  628. .chart-list {
  629. background-color: #fff;
  630. overflow: hidden;
  631. }
  632. }
  633. </style>
  634. <style lang="less">
  635. #home {
  636. width: 750rpx;
  637. overflow-x: hidden;
  638. .function-list .cu-item text[class*="cuIcon"] {
  639. margin-top: 0 !important;
  640. }
  641. }
  642. </style>