index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. // pages/index-guest/index-guest.js
  2. const app = getApp();
  3. const util = require('../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgPath: app.globalData.imgPath,
  10. path: app.globalData.path,
  11. app_bottom: '大城细管·大城众管·大城智管',
  12. nowTime: util.formatDate(null, 'yyyy.MM.dd'),
  13. nextMeeting: null,
  14. hasNext: false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. let that = this;
  21. if (!app.globalData.userInfo.usernameShow || !app.globalData.userInfo.nickName || !app.globalData.userInfo.headImgUrl) {
  22. wx.showModal({
  23. title: '提示',
  24. content: '轻应用需要取您的用户信息',
  25. showCancel: false,
  26. confirmText: '确定',
  27. success: (res) => {
  28. if (res.confirm) {
  29. wx.getUserProfile({
  30. desc: '提升用户体验感',
  31. success: (res) => {
  32. app.globalData.userInfo.usernameShow = res.userInfo.nickName;
  33. app.globalData.userInfo.nickName = res.userInfo.nickName;
  34. app.globalData.userInfo.headImgUrl = res.userInfo.avatarUrl;
  35. that.setData({
  36. username: app.globalData.userInfo.usernameShow,
  37. role_name: app.globalData.roleInfo.name,
  38. roleCode: app.globalData.roleInfo.code,
  39. });
  40. util.post({
  41. url: '/sys/user/updateNoAuth',
  42. data: {
  43. id: app.globalData.userInfo.id,
  44. nickName: res.userInfo.nickName,
  45. usernameShow: res.userInfo.nickName,
  46. headImgUrl: res.userInfo.avatarUrl
  47. }
  48. });
  49. },
  50. fail: (res) => {
  51. util.toast('拒绝授权将影响您的体验感');
  52. that.setData({
  53. username: '未知用户',
  54. role_name: app.globalData.roleInfo.name,
  55. roleCode: app.globalData.roleInfo.code,
  56. });
  57. }
  58. });
  59. }
  60. },
  61. });
  62. } else {
  63. that.setData({
  64. username: app.globalData.userInfo.usernameShow,
  65. role_name: app.globalData.roleInfo.name,
  66. roleCode: app.globalData.roleInfo.code,
  67. });
  68. }
  69. // 加入群聊
  70. if (wx.getStorageSync('groupId')) {
  71. let groupId = wx.getStorageSync('groupId');
  72. util.post({
  73. url: '/api/easemob/addGroupUser',
  74. data: {
  75. chatgroupid: groupId,
  76. usernames: [wx.getStorageSync('myUsername')]
  77. },
  78. success: (res) => {
  79. wx.hideLoading();
  80. console.info('addGroupUser', res);
  81. if (res.data.code != 200) {
  82. util.toast(res.data.msg);
  83. } else {
  84. let datas = res.data.data;
  85. if (datas && datas.error) {
  86. if (datas.error == 'not_found') {
  87. wx.showModal({
  88. content: '您要加入的群聊不存在',
  89. showCancel: false
  90. });
  91. } else if (datas.error == 'forbidden_op') {
  92. wx.showModal({
  93. content: '您已经在群聊中了,请不要重复加入',
  94. showCancel: false
  95. });
  96. } else {
  97. util.toast(datas.error);
  98. }
  99. } else {
  100. wx.showModal({
  101. content: '群聊加入成功',
  102. showCancel: false
  103. });
  104. }
  105. }
  106. wx.removeStorageSync('groupId');
  107. }
  108. });
  109. }
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. let that = this;
  121. // 下一场会议
  122. util.get({
  123. url: '/api/meeting/info/getNextMeeting',
  124. success: (res) => {
  125. wx.hideLoading();
  126. if (res.data.code != 200) {
  127. util.toast(res.data.msg);
  128. } else {
  129. let datas = res.data.data;
  130. if (datas) {
  131. that.setData({
  132. hasNext: true,
  133. nextMeeting: datas,
  134. nextTitle: datas.title,
  135. nextTime: util.formatDate(datas.receptionTime),
  136. nextUnit: datas.receptionObject
  137. });
  138. } else {
  139. // util.toast('暂无下一场会议');
  140. }
  141. }
  142. }
  143. });
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面卸载
  152. */
  153. onUnload: function () {
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. onPullDownRefresh: function () {
  159. },
  160. /**
  161. * 页面上拉触底事件的处理函数
  162. */
  163. onReachBottom: function () {
  164. },
  165. /**
  166. * 调试使用:切换角色菜单
  167. */
  168. changeRole: function () {
  169. let that = this;
  170. console.info('changeRole', that.data);
  171. if (that.data.roleCode == 'GUEST') {
  172. that.setData({
  173. role_name: '运维人员',
  174. roleCode: 'OPERATION',
  175. });
  176. } else if (that.data.roleCode == 'OPERATION') {
  177. that.setData({
  178. role_name: '工作人员',
  179. roleCode: 'ADMIN',
  180. });
  181. } else if (that.data.roleCode == 'ADMIN') {
  182. that.setData({
  183. role_name: '来宾',
  184. roleCode: 'GUEST',
  185. });
  186. }
  187. },
  188. /**
  189. * 点击查看下一场会议详情
  190. */
  191. meetingInfo: function () {
  192. let nextMeeting = this.data.nextMeeting;
  193. if (nextMeeting) {
  194. wx.navigateTo({
  195. url: '../meeting-cover/meeting-cover?id=' + JSON.stringify(nextMeeting.id),
  196. });
  197. } else {
  198. util.toast('暂无下一场会议');
  199. }
  200. },
  201. /**
  202. * 日常巡检
  203. */
  204. dailyInspection: function () {
  205. wx.navigateTo({
  206. url: '../daily-inspection/daily-inspection',
  207. });
  208. },
  209. /**
  210. * 发布会议信息
  211. */
  212. informationRelease: function () {
  213. wx.navigateTo({
  214. url: '../information-release/information-release',
  215. });
  216. },
  217. /**
  218. * 会议巡检
  219. */
  220. meetingInspection: function () {
  221. wx.navigateTo({
  222. url: '../meeting-list/meeting-list?type=INSPECTION',
  223. });
  224. },
  225. /**
  226. * 分享海报
  227. */
  228. meetingCover: function () {
  229. util.toast('功能暂未开放');
  230. wx.navigateTo({
  231. url: '../meeting-list/meeting-list',
  232. });
  233. },
  234. /**
  235. * 点击参观议程跳转至会议列表
  236. */
  237. visitAgenda: function () {
  238. wx.navigateTo({
  239. url: '../meeting-list/meeting-list',
  240. });
  241. },
  242. /**
  243. * 图片回传
  244. */
  245. uploadImage: function () {
  246. let that = this;
  247. wx.chooseImage({
  248. count: 1,
  249. success: function (res) {
  250. console.info(res);
  251. wx.uploadFile({
  252. filePath: res.tempFilePaths[0],
  253. name: 'file',
  254. url: that.data.path + '/api/upload/record/upload',
  255. header: {
  256. "Content-Type": "multipart/form-data",
  257. "Authorization": app.globalData.Authorization
  258. },
  259. formData: {
  260. fileType: 10
  261. },
  262. success(res) {
  263. wx.hideLoading();
  264. let datas = JSON.parse(res.data);
  265. console.info(datas)
  266. if (datas.code != 200) {
  267. util.toast(datas.msg);
  268. } else {
  269. util.toast(datas.msg);
  270. }
  271. }
  272. });
  273. }
  274. });
  275. },
  276. /**
  277. * 内容投屏
  278. */
  279. contentScreen: function () {
  280. let wifi, pass;
  281. // 打开微信扫一扫
  282. wx.scanCode({
  283. onlyFromCamera: true,
  284. scanType: 'qrCode',
  285. success: (res) => {
  286. console.info(res);
  287. if (res.result.indexOf('WIFI') < 0) {
  288. util.toast('请扫描WIFI二维码');
  289. return;
  290. }
  291. wx.showLoading({
  292. title: '加载中...',
  293. mask: true
  294. });
  295. try {
  296. let a = res.result.split(',');
  297. wifi = a[0].split(':')[1];
  298. pass = a[1].split(':')[1];
  299. } catch (error) {
  300. util.toast('请扫描WIFI二维码');
  301. return;
  302. }
  303. // 获取设备系统类型
  304. wx.getSystemInfo({
  305. success: (res) => {
  306. console.info(res);
  307. if (!res.wifiEnabled) {
  308. wx.hideLoading();
  309. util.toast('请打开WIFI功能');
  310. return;
  311. }
  312. // 1、初始化Wi-Fi模块
  313. wx.startWifi({
  314. success: (res) => {
  315. console.info('startWifi', res)
  316. if (res.errMsg == 'startWifi:ok') {
  317. // 4、连接Wi-Fi
  318. wx.connectWifi({
  319. SSID: wifi,
  320. password: pass,
  321. success: (res) => {
  322. wx.hideLoading();
  323. console.info('connectWifi', res);
  324. if (res.errMsg == 'connectWifi:ok') {
  325. util.toast('WIFI连接成功', 'success');
  326. } else {
  327. util.toast(res.errMsg);
  328. }
  329. },
  330. fail: (e) => {
  331. console.info(e);
  332. util.toast('WIFI连接失败');
  333. }
  334. });
  335. } else {
  336. util.toast(res.errMsg);
  337. }
  338. },
  339. fail: (e) => {
  340. console.info(e);
  341. util.toast('初始化WiFi模块失败');
  342. }
  343. });
  344. },
  345. fail: (e) => {
  346. util.toast('获取设备系统类型失败');
  347. return;
  348. }
  349. });
  350. },
  351. fail: (e) => {
  352. console.info('chooseImage fail', e)
  353. if (e.errMsg == 'scanCode:fail cancel') {
  354. util.toast('取消扫码');
  355. } else {
  356. util.toast('扫码失败,请重试');
  357. }
  358. }
  359. });
  360. },
  361. /**
  362. * 聊天室
  363. * @param {*} e
  364. */
  365. chatRoom: function (e) {
  366. wx.navigateTo({
  367. url: '../chat-room/chat-room',
  368. });
  369. },
  370. /**
  371. * 地图
  372. */
  373. lightMap: function () {
  374. wx.getSetting({
  375. withSubscriptions: true,
  376. success: function (res) {
  377. console.info(res);
  378. if (res.authSetting['scope.userLocation'] == undefined) {
  379. wx.authorize({
  380. scope: 'scope.userLocation',
  381. success: function (res) {
  382. console.info(res);
  383. wx.navigateTo({
  384. url: '../light-map/light-map',
  385. });
  386. },
  387. fail: function (e) {
  388. console.info(e);
  389. wx.showToast({
  390. title: '用户拒绝授权',
  391. icon: 'error'
  392. });
  393. }
  394. });
  395. } else if (res.authSetting['scope.userLocation'] == true) {
  396. wx.navigateTo({
  397. url: '../light-map/light-map',
  398. });
  399. } else {
  400. wx.showModal({
  401. content: '请开启相关权限,以便更好地体验小程序',
  402. success: (res) => {
  403. if (res.confirm) {
  404. wx.openSetting({
  405. success: (res) => {
  406. console.info('openSetting', res.authSetting)
  407. if (res.authSetting['scope.userLocation']) {
  408. util.toast('授权成功');
  409. wx.navigateTo({
  410. url: '../light-map/light-map',
  411. });
  412. } else {
  413. util.toast('用户未授权');
  414. }
  415. }
  416. });
  417. }
  418. }
  419. });
  420. }
  421. }
  422. });
  423. },
  424. /**
  425. * 文件浏览
  426. */
  427. fileBrowse: function () {
  428. wx.navigateTo({
  429. url: '../file-browse/file-browse',
  430. });
  431. },
  432. /**
  433. * 故障处理
  434. */
  435. faultHandle: function () {
  436. wx.navigateTo({
  437. url: '../fault-list/fault-list',
  438. })
  439. }
  440. })