index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:主页应用
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * admin 2024-02-20 1.00 首页
  9. *******************************************************************************/
  10. const app = getApp()
  11. const api = require('@/utils/api.js');
  12. const config = require('@/config/config.js');
  13. const util = require('@/utils/util.js')
  14. const Constants = require('@/utils/Constants');
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. imageUrl: config.image_url + '/static/img/',
  21. editTip: '长按拖动可以调整应用位置',
  22. size: 4,
  23. showMore: false,
  24. editFlag: false, // 编辑模式
  25. comMenuList: [], // 常用功能
  26. comMenuListForCheck: [],// 常用功能(简单数组)用于判断
  27. allCondition: '',//搜索菜单
  28. noticeShowFlag: true,// 是否显示通知的
  29. loadingShow: false,
  30. // 功能分区全部勾选标识
  31. RegionCheck: true,
  32. bingFlag: 0,
  33. //用户信息
  34. userInfo: {},
  35. //角标
  36. infocodes: ['0303'],
  37. infos: [
  38. // 公告查阅
  39. {
  40. code: '0303',
  41. num: 6
  42. }
  43. ],
  44. functionItem: {
  45. text: '功能分区'
  46. },
  47. functionRegion: [
  48. ],
  49. functionRegions: [],
  50. //功能分类-大功能模块
  51. regions: [
  52. ],
  53. //功能分类-大功能模块-页面
  54. functionItems: [
  55. ],
  56. },
  57. /**
  58. * @desc : 展开收缩
  59. * @author : 周兴
  60. * @date : 2024/1/26 11:46
  61. */
  62. expand() {
  63. let showMore = this.data.showMore;
  64. this.setData({
  65. showMore: !showMore
  66. })
  67. },
  68. /**
  69. * @desc : 操作常用应用
  70. * @author : 周兴
  71. * @date : 2024/3/29
  72. */
  73. comItemClick(e) {
  74. // 操作常用应用
  75. this.toApp(e, true);
  76. setTimeout(() => {
  77. this.initDrag()
  78. }, 50)
  79. },
  80. /**
  81. * @desc : 初始化drag组件
  82. * @author : 周兴
  83. * @date : 2024/3/29
  84. */
  85. initDrag() {
  86. let drag = this.selectComponent('#drag');
  87. if (drag) {
  88. drag.init();
  89. }
  90. },
  91. /**
  92. * @desc : drag结束
  93. * @author : 周兴
  94. * @date : 2024/3/29
  95. */
  96. dragEnd(e) {
  97. this.setData({
  98. comMenuList: e.detail.listData
  99. })
  100. },
  101. /**
  102. * @desc : 进入编辑模式
  103. * @author : 周兴
  104. * @date : 2024/3/29
  105. */
  106. toEdit() {
  107. let editFlag = this.data.editFlag
  108. // 变为编辑模式
  109. if (!editFlag) {
  110. wx.setNavigationBarTitle({
  111. title: '管理应用',
  112. })
  113. editFlag = !editFlag;
  114. let showMore = this.data.showMore
  115. if (editFlag) {
  116. showMore = true;
  117. }
  118. this.setData({
  119. showMore: showMore,
  120. editFlag: editFlag
  121. })
  122. // 模仿异步加载数据
  123. setTimeout(() => {
  124. this.initDrag();
  125. }, 100)
  126. } else {
  127. // 保存常用功能
  128. this.saveComMenu();
  129. }
  130. },
  131. /**
  132. * @desc : 退出编辑模式
  133. * @author : 周兴
  134. * @date : 2024/3/29
  135. */
  136. cancel() {
  137. wx.setNavigationBarTitle({
  138. title: '应用中心',
  139. })
  140. this.setData({
  141. editFlag: false,
  142. showMore: false
  143. })
  144. },
  145. /**
  146. * @desc : 保存常用功能
  147. * @author : 周兴
  148. * @date : 2024/3/29
  149. */
  150. saveComMenu() {
  151. let comMenuList = this.data.comMenuList || []
  152. comMenuList.forEach((it, index) => {
  153. it.staffId = app.globalData.user.staffId,
  154. it.appCode = Constants.APP_CODE,
  155. it.displayNo = index
  156. })
  157. let service = app.globalData['comMenuService']
  158. api.request(service.prefix + service.save, 'POST', comMenuList).then(res => {
  159. if (res.data.code == Constants.SUCESS_CODE) {
  160. wx.showToast({
  161. title: "保存成功",
  162. image: '/static/image/success.png',
  163. duration: 1000
  164. })
  165. // 收起来
  166. this.cancel();
  167. }
  168. });
  169. },
  170. /**
  171. * @desc : 查询常用应用
  172. * @author : 周兴
  173. * @date : 2024/3/29
  174. */
  175. getComMenu() {
  176. let params = {
  177. staffId: app.globalData.user.staffId,
  178. appCode: Constants.APP_CODE,
  179. }
  180. let service = app.globalData['comMenuService']
  181. api.request(service.prefix + service.selectByCond, 'POST', params).then(res => {
  182. if (res.data.code == Constants.SUCESS_CODE) {
  183. let comMenuList = res.data.data
  184. let comMenuListForCheck = comMenuList.map(it => it.menuUuid)
  185. this.setData({
  186. comMenuList: comMenuList,
  187. comMenuListForCheck: comMenuListForCheck
  188. })
  189. }
  190. });
  191. },
  192. /**
  193. * 过滤菜单
  194. */
  195. filterFunction() {
  196. let _this = this
  197. let searchtext = _this.data.allCondition
  198. let regionsAll = [...app.globalData.menus]
  199. let functionRegionItem = {}
  200. let region = {}
  201. // 导航权限数组
  202. let functionRegion = []
  203. let functionRegions = []
  204. let regions = []
  205. let navigrightsTemp = []
  206. navigrightsTemp = regionsAll.filter((item) => item.menuType == 0 && item.objectCode != 'mine') || []
  207. if (searchtext) {
  208. navigrightsTemp = navigrightsTemp.filter((item) => item.menuName.indexOf(searchtext) >= 0)
  209. }
  210. navigrightsTemp.forEach(item => {
  211. functionRegionItem = {
  212. title: item.menuName,
  213. checked: true
  214. }
  215. region = {
  216. FunctionName: item.menuName,
  217. FunctionCodeOrder: item.menuUuid
  218. }
  219. functionRegion.push(functionRegionItem)
  220. functionRegions.push(item.menuName)
  221. regions.push(region)
  222. })
  223. //页面权限数组
  224. let functionItems = []
  225. let pagerights = regionsAll.filter((item) => item.menuType == 1) || []
  226. let pagerightsTemp = pagerights.filter((item) => item.objectPath) || []
  227. let pagerightsTempTwo = []
  228. pagerightsTempTwo = pagerightsTemp.filter((item) => item.objectCode != 'store-index') || []
  229. if (searchtext) {
  230. //过滤子级
  231. pagerightsTempTwo = pagerightsTempTwo.filter((item) => item.menuName.indexOf(searchtext) >= 0) || []
  232. // 增加子级菜单的父级
  233. let copyRights = [...pagerightsTempTwo]
  234. for (let i in pagerightsTempTwo) {
  235. let rightitem = regionsAll.filter((item) => item.menuUuid.indexOf(pagerightsTempTwo[i].parentUuid) >= 0 && item.menuType == 0 && item.objectCode != 'mine')
  236. if (rightitem.length > 0) {
  237. rightitem.forEach(item => {
  238. functionRegionItem = {
  239. title: item.menuName,
  240. checked: true
  241. }
  242. region = {
  243. FunctionName: item.menuName,
  244. FunctionCodeOrder: item.menuUuid
  245. }
  246. functionRegion.push(functionRegionItem)
  247. functionRegions.push(item.menuName)
  248. regions.push(region)
  249. })
  250. }
  251. }
  252. functionRegion = this.uniqueFunc(functionRegion, 'title')
  253. functionRegions = this.removeDuplicate(functionRegions)
  254. regions = this.uniqueFunc(regions, 'FunctionName')
  255. }
  256. pagerightsTempTwo.forEach(item => {
  257. let pageitem = {
  258. FunctionName: item.menuName,
  259. FormName: item.objectPath,
  260. ImageUri: item.icon ? (this.data.imageUrl + item.icon + '.png') : '',
  261. PFunctionCode: item.parentUuid,
  262. isVip: item.isVip,
  263. FunctionCode: item.menuUuid,
  264. objectCode: item.objectCode,
  265. }
  266. functionItems.push(pageitem)
  267. })
  268. this.setData({
  269. regions: regions,
  270. functionItems: functionItems,
  271. functionRegion: functionRegion,
  272. functionRegions: functionRegions,
  273. regionsAll: regionsAll,
  274. })
  275. // 画面的按钮的数组
  276. },
  277. uniqueFunc(arr, uniId) {
  278. const res = new Map();
  279. return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
  280. },
  281. removeDuplicate(arr) {
  282. const newArr = []
  283. arr.forEach(item => {
  284. if (newArr.indexOf(item) === -1) {
  285. newArr.push(item)
  286. }
  287. })
  288. return newArr // 返回一个新数组
  289. },
  290. /**
  291. * 设置权限
  292. * @param {*} rights
  293. * @param {*} initFlag
  294. */
  295. // 测试fixed函数
  296. // this.testObjectValue()
  297. setRight: function (rights, initFlag) {
  298. this.setData({
  299. rights: rights
  300. })
  301. let regions = []
  302. let regionsAll = []
  303. let functionItems = []
  304. let functionRegion = []
  305. let functionRegionItem = {}
  306. let functionRegions = []
  307. if (rights != null) {
  308. for (let i in rights) {
  309. var item = rights[i]
  310. if (!item.FunctionFlag) {
  311. // 功能分区
  312. regions.push(item)
  313. if (initFlag) {
  314. regionsAll.push(item)
  315. }
  316. functionRegionItem = { title: item.FunctionName, checked: true }
  317. functionRegion.push(functionRegionItem)
  318. functionRegions.push(item.FunctionName)
  319. }
  320. else {
  321. // 子级功能
  322. functionItems.push(item)
  323. }
  324. }
  325. }
  326. this.setData({
  327. regions: regions,
  328. functionItems: functionItems,
  329. functionRegion: functionRegion,
  330. functionRegions: functionRegions
  331. })
  332. if (initFlag) {
  333. this.setData({
  334. regionsAll: regionsAll,
  335. })
  336. }
  337. },
  338. /**
  339. * 选择下拉后查询
  340. */
  341. dropdowncommit(e) {
  342. this.setData({
  343. functionRegions: e.detail.dataTitle
  344. })
  345. this.selectComponent('#functionItem').toggle();
  346. },
  347. /**
  348. * 生命周期函数--监听页面加载
  349. */
  350. onLoad: function (options) {
  351. // 调用权限时候放开
  352. this.filterFunction();
  353. // 查询常用功能
  354. this.getComMenu();
  355. },
  356. /* 点击icon事件 */
  357. toApp(e, comFlag) {
  358. // 编辑模式不跳页
  359. if (this.data.editFlag) {
  360. if (comFlag) {
  361. // 删除常用功能
  362. this.delCom(e.detail.data);
  363. } else {
  364. // 增加到常用功能
  365. this.addToCom(e.currentTarget.dataset.item);
  366. // 刷新drag组件
  367. setTimeout(() => {
  368. this.initDrag();
  369. }, 100)
  370. }
  371. // let comFlag = e.currentTarget.dataset.com
  372. // // 删除常用功能
  373. // if (comFlag) {
  374. // this.delCom(e.currentTarget.dataset.item);
  375. // } else {
  376. // // 增加到常用功能
  377. // this.addToCom(e.currentTarget.dataset.item);
  378. // }
  379. return;
  380. }
  381. let url = e.currentTarget.dataset.url
  382. let code = e.currentTarget.dataset.code
  383. if(comFlag){
  384. url = e.detail.data.objectPath
  385. code = e.detail.data.objectCode
  386. }
  387. if (!url) {
  388. wx.showToast({
  389. title: '功能开发中',
  390. image: '/static/image/warning.png',
  391. duration: 2000
  392. })
  393. return
  394. }
  395. let guideUrl = null;
  396. let menuList = app.globalData.menus
  397. if (menuList && menuList.length > 0) {
  398. let filters = menuList.filter(it => it.id == code);
  399. if (filters && filters.length > 0) {
  400. guideUrl = filters[0].guideUrl
  401. }
  402. }
  403. // 调转页面
  404. wx.navigateTo({
  405. url: url,
  406. success: function (res) {
  407. res.eventChannel.emit('params', { formMode: 'index', menuUuid: code, guideUrl: guideUrl,objectCode:e.currentTarget.dataset.item.objectCode})
  408. }
  409. })
  410. },
  411. /**
  412. * @desc : 删除常用应用
  413. * @author : 周兴
  414. * @date : 2024/3/29 9:16
  415. */
  416. delCom(item) {
  417. let comMenuList = this.data.comMenuList
  418. let comMenuListForCheck = this.data.comMenuListForCheck
  419. comMenuList = comMenuList.filter(it => it.menuUuid != item.menuUuid)
  420. comMenuListForCheck = comMenuListForCheck.filter(it => it != item.menuUuid)
  421. this.setData({
  422. comMenuList: comMenuList,
  423. comMenuListForCheck: comMenuListForCheck
  424. })
  425. },
  426. /**
  427. * @desc : 添加到常用应用中
  428. * @author : 周兴
  429. * @date : 2024/3/29 9:16
  430. */
  431. addToCom(item) {
  432. let comMenuList = this.data.comMenuList
  433. let comMenuListForCheck = this.data.comMenuListForCheck
  434. let it = {}
  435. it.menuUuid = item.FunctionCode
  436. it.objectPath = item.FormName
  437. let imageUri = item.ImageUri + ''
  438. it.objectIcon = imageUri ? (imageUri.substring(imageUri.lastIndexOf('/') + 1)) : ''
  439. it.menuName = item.FunctionName
  440. let filters = comMenuList.filter(t => t.menuUuid == it.menuUuid);
  441. if (!filters || filters.length == 0) {
  442. if (comMenuList && comMenuList.length >= 9) {
  443. util.showToast('常用应用不能超过9个');
  444. return
  445. }
  446. comMenuList.push(it);
  447. comMenuListForCheck.push(it.menuUuid)
  448. }
  449. this.setData({
  450. comMenuList: comMenuList,
  451. comMenuListForCheck: comMenuListForCheck
  452. })
  453. },
  454. /**
  455. * 页面相关事件处理函数--监听用户下拉动作
  456. */
  457. onPullDownRefresh: function () {
  458. let that = this
  459. //调用刷新时将执行的方法
  460. this.getBindStatus().then(res => {
  461. // 调用权限时候放开
  462. this.filterFunction()
  463. //隐藏导航条加载动画
  464. wx.hideNavigationBarLoading();
  465. setTimeout(function () {
  466. that.setData({
  467. loadingShow: false,
  468. })
  469. //停止下拉刷新
  470. wx.stopPullDownRefresh();
  471. }, 800)
  472. })
  473. },
  474. /**
  475. * 从app。js中获取真实的 企业userid和企业corpid
  476. * @param {*} param
  477. */
  478. getBindStatus() {
  479. return new Promise((resolve, reject) => {
  480. this.setData({
  481. loadingShow: true,
  482. })
  483. let p = {
  484. qvcorpid: app.globalData.qvcorpid,
  485. qvuserid: app.globalData.qvuserid,
  486. appUuid: Constants.APP_WX_HEGII,
  487. clientId: Constants.CLIENT_ID
  488. }
  489. // 从app。js中获取真实的 企业userid和企业corpid
  490. app.getBindStatus(p).then(resstatus => {
  491. // 返回值 用户对象存在
  492. if (resstatus.data.data) {
  493. let user = resstatus.data.data
  494. app.globalData.user = user
  495. app.globalData.token = user.token
  496. app.globalData.menus = user.menu
  497. //按钮权限
  498. if (user.menus && user.menus.length > 0) {
  499. let buttonRights = []
  500. user.menus.forEach(it => {
  501. buttonRights.push(it.levelCode)
  502. })
  503. app.globalData.buttonRights = buttonRights
  504. }
  505. }
  506. })
  507. resolve()
  508. })
  509. },
  510. toprint() {
  511. wx.navigateTo({
  512. url: '/package4/pages/order-printing/order-printing',
  513. })
  514. },
  515. toOrgCategory() {
  516. wx.navigateTo({
  517. url: '/package-purchase/pages/kpi-org-category/kpi-org-category',
  518. })
  519. },
  520. toOrgSpu() {
  521. wx.navigateTo({
  522. url: '/package-purchase/pages/kpi-org-spu/kpi-org-spu',
  523. })
  524. },
  525. toStaffCategory() {
  526. wx.navigateTo({
  527. url: '/package-purchase/pages/kpi-staff-category/kpi-staff-category',
  528. })
  529. },
  530. toStaffSpu() {
  531. wx.navigateTo({
  532. url: '/package-purchase/pages/kpi-staff-spu/kpi-staff-spu',
  533. })
  534. },
  535. })