index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="work-container">
  3. <!-- 轮播图 -->
  4. <uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
  5. <swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
  6. <swiper-item v-for="(item, index) in data" :key="index">
  7. <view class="swiper-item" @click="clickBannerItem(item)">
  8. <image :src="item.image" mode="aspectFill" :draggable="false" />
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. </uni-swiper-dot>
  13. <!-- 宫格组件 -->
  14. <uni-section title="工作台" type="line"></uni-section>
  15. <view class="grid-body">
  16. <uni-grid :column="3" :showBorder="false" >
  17. <uni-grid-item v-if="hasRole(['admin'])">
  18. <view class="grid-item-box" @click="goPage('user')">
  19. <u--image :showLoading="true" src="/static/images/icons/user.png" width="50rpx" height="50rpx" ></u--image>
  20. <text class="text">客户列表</text>
  21. </view>
  22. </uni-grid-item>
  23. <uni-grid-item v-if="isCompanyUser()">
  24. <view class="grid-item-box" @click="goPage('deptuser')">
  25. <u--image :showLoading="true" src="/static/images/icons/user.png" width="50rpx" height="50rpx" ></u--image>
  26. <text class="text">用户管理</text>
  27. </view>
  28. </uni-grid-item>
  29. <uni-grid-item v-if="isCompanyUser()">
  30. <view class="grid-item-box" @click="goPage('device')">
  31. <u--image :showLoading="true" src="/static/images/icons/device.png" width="50rpx" height="50rpx" ></u--image>
  32. <text class="text">设备列表</text>
  33. </view>
  34. </uni-grid-item>
  35. <uni-grid-item>
  36. <view class="grid-item-box" @click="goPage('wifi')">
  37. <u--image :showLoading="true" src="/static/images/icons/wifi.png" width="50rpx" height="50rpx" ></u--image>
  38. <text class="text">设备配网</text>
  39. </view>
  40. </uni-grid-item>
  41. <uni-grid-item v-if="hasRole(['admin'])">
  42. <view class="grid-item-box" @click="goPage('scan')">
  43. <u--image :showLoading="true" src="/static/images/icons/code.png" width="50rpx" height="50rpx" ></u--image>
  44. <text class="text">绑码激活</text>
  45. </view>
  46. </uni-grid-item>
  47. <uni-grid-item v-if="isCompanyUser()">
  48. <view class="grid-item-box" @click="scanCode()">
  49. <u--image :showLoading="true" src="/static/images/icons/scan.png" width="50rpx" height="50rpx" ></u--image>
  50. <text class="text">用户绑定</text>
  51. </view>
  52. </uni-grid-item>
  53. <uni-grid-item>
  54. <view class="grid-item-box" @click="watchDevice()">
  55. <u--image :showLoading="true" src="/static/images/icons/scan.png" width="50rpx" height="50rpx" ></u--image>
  56. <text class="text">查看设备</text>
  57. </view>
  58. </uni-grid-item>
  59. <uni-grid-item v-if="isCompanyUser()">
  60. <view class="grid-item-box" @click="goPage('alert')">
  61. <u--image :showLoading="true" src="/static/images/icons/alert.png" width="50rpx" height="50rpx" ></u--image>
  62. <text class="text">设备告警</text>
  63. </view>
  64. </uni-grid-item>
  65. <uni-grid-item v-if="isCompanyUser()">
  66. <view class="grid-item-box" @click="goPage('error')">
  67. <u--image :showLoading="true" src="/static/images/icons/error.png" width="50rpx" height="50rpx" ></u--image>
  68. <text class="text">异常列表</text>
  69. </view>
  70. </uni-grid-item>
  71. <uni-grid-item v-if="hasRole(['admin'])">
  72. <view class="grid-item-box" @click="goPage('reset')">
  73. <u--image :showLoading="true" src="/static/images/icons/reset.png" width="50rpx" height="50rpx" ></u--image>
  74. <text class="text">注销设备</text>
  75. </view>
  76. </uni-grid-item>
  77. <uni-grid-item>
  78. <view class="grid-item-box" @click="goPage('time')">
  79. <u--image :showLoading="true" src="/static/images/icons/rank.png" width="50rpx" height="50rpx" ></u--image>
  80. <text class="text">时长排名</text>
  81. </view>
  82. </uni-grid-item>
  83. </uni-grid>
  84. <u-modal :show="show" :title="dlgTitle" @cancel="cancel" :showCancelButton="true" @confirm="bingDevice" >
  85. <view class="slot-content">
  86. <view>设备名称:{{ scanDevice.deviceName }}</view>
  87. <view>产品名称:{{ scanDevice.productName }}</view>
  88. <view>设备编号:{{ scanDevice.serialNumber }}</view>
  89. <view>激活日期:{{ scanDevice.activeTime }}</view>
  90. </view>
  91. </u-modal>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. import authObj from '@/plugins/auth.js';
  97. import {getDevcieByQrcode,bingDeviceDept} from '@/api/device/device';
  98. import UImage from "../../uni_modules/uview-ui/components/u--image/u--image";
  99. export default {
  100. components: {UImage},
  101. data() {
  102. return {
  103. deptId:0,
  104. dlgTitle:"",
  105. current: 0,
  106. swiperDotIndex: 0,
  107. show:false,
  108. scanDevice:{},
  109. data: [{
  110. image: '/static/images/banner/banner01.jpg'
  111. },
  112. // {
  113. // image: '/static/images/banner/banner02.jpg'
  114. // },
  115. // {
  116. // image: '/static/images/banner/banner03.jpg'
  117. // }
  118. ]
  119. }
  120. },
  121. onLoad(){
  122. if(this.isCompanyUser()){
  123. this.deptId = this.$store.state.user.user.deptId;
  124. console.log( this.deptId );
  125. }
  126. },
  127. methods: {
  128. bingDevice(){
  129. this.show = false;
  130. bingDeviceDept(this.scanDevice).then(res=>{
  131. if(res.code == 200){
  132. this.$modal.showToast('操作成功')
  133. }else{
  134. this.$modal.showToast(res.msg);
  135. }
  136. })
  137. },
  138. cancel(){
  139. this.show = false;
  140. this.scanDevice = {};
  141. },
  142. clickBannerItem(item) {
  143. console.log();
  144. },
  145. hasRole(role){
  146. return authObj.authRoleAdmin(role);
  147. },
  148. isCompanyUser(){
  149. return authObj.authRoleAdmin(["companymgr"]) || authObj.authRoleAdmin(["companyuser"]);
  150. },
  151. changeSwiper(e) {
  152. this.current = e.detail.current
  153. },
  154. changeGrid(e) {
  155. this.$modal.showToast('模块建设中~')
  156. },
  157. watchDevice(){
  158. let self = this;
  159. uni.scanCode({
  160. success: function (res) {
  161. console.log('条码内容:' + res.result);
  162. getDevcieByQrcode(res.result).then(res=>{
  163. let device = res.data;
  164. if(!self.hasRole(['admin'])){
  165. if(device.deptId == null || device.deptId == 0){
  166. self.$modal.showToast('设备不存在或无权限')
  167. return;
  168. }
  169. }
  170. if(device != null){
  171. uni.navigateTo({
  172. url: '/pages/device/detail?id='+device.deviceId
  173. });
  174. }else{
  175. self.$modal.showToast('设备不存在或无权限')
  176. }
  177. });
  178. }
  179. });
  180. },
  181. scanCode(){
  182. let self = this;
  183. uni.scanCode({
  184. success: function (res) {
  185. console.log('条码内容:' + res.result);
  186. getDevcieByQrcode(res.result).then(res=>{
  187. let device = res.data;
  188. if(!device){
  189. self.$modal.showToast('设备不存在或该已经绑定用户')
  190. }else{
  191. if(device.deptId != null){
  192. self.$modal.showToast('该设备已经绑定了用户')
  193. }else{
  194. self.dlgTitle = "绑定设备";
  195. self.scanDevice = device;
  196. self.show = true;
  197. }
  198. }
  199. });
  200. }
  201. });
  202. },
  203. goPage(path){
  204. if('deptuser' == path){
  205. uni.navigateTo({
  206. url: '/pages/user/list?deptId='+this.deptId
  207. });
  208. }
  209. if('device' == path){
  210. uni.navigateTo({
  211. url: '/pages/device/index'
  212. });
  213. }
  214. if('wifi' == path){
  215. uni.navigateTo({
  216. url: '/pages/wifi/index'
  217. });
  218. }
  219. if('scan' == path){
  220. uni.navigateTo({
  221. url: '/pages/device/scan'
  222. });
  223. }
  224. if('user' == path){
  225. uni.navigateTo({
  226. url: '/pages/user/index'
  227. });
  228. }
  229. if('alert' == path){
  230. uni.navigateTo({
  231. url: '/pages/device/alert'
  232. });
  233. }
  234. if('error' == path){
  235. uni.navigateTo({
  236. url: '/pages/device/error'
  237. });
  238. }
  239. if('reset' == path){
  240. uni.navigateTo({
  241. url: '/pages/device/reset/reset'
  242. });
  243. }
  244. if('time' == path){
  245. uni.navigateTo({
  246. url: '/pages/device/rank'
  247. });
  248. }
  249. }
  250. }
  251. }
  252. </script>
  253. <style lang="scss">
  254. /* #ifndef APP-NVUE */
  255. page {
  256. display: flex;
  257. flex-direction: column;
  258. box-sizing: border-box;
  259. background-color: #fff;
  260. min-height: 100%;
  261. height: auto;
  262. }
  263. view {
  264. font-size: 14px;
  265. line-height: inherit;
  266. }
  267. /* #endif */
  268. .text {
  269. text-align: center;
  270. font-size: 26rpx;
  271. margin-top: 10rpx;
  272. }
  273. .grid-item-box {
  274. flex: 1;
  275. /* #ifndef APP-NVUE */
  276. display: flex;
  277. /* #endif */
  278. flex-direction: column;
  279. align-items: center;
  280. justify-content: center;
  281. padding: 15px 0;
  282. }
  283. .uni-margin-wrap {
  284. width: 690rpx;
  285. width: 100%;
  286. ;
  287. }
  288. .swiper {
  289. height: 300rpx;
  290. }
  291. .swiper-box {
  292. height: 150px;
  293. }
  294. .swiper-item {
  295. /* #ifndef APP-NVUE */
  296. display: flex;
  297. /* #endif */
  298. flex-direction: column;
  299. justify-content: center;
  300. align-items: center;
  301. color: #fff;
  302. height: 300rpx;
  303. line-height: 300rpx;
  304. }
  305. @media screen and (min-width: 500px) {
  306. .uni-swiper-dot-box {
  307. width: 400px;
  308. /* #ifndef APP-NVUE */
  309. margin: 0 auto;
  310. /* #endif */
  311. margin-top: 8px;
  312. }
  313. .image {
  314. width: 100%;
  315. }
  316. }
  317. </style>