index.js 14 KB

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