device.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="device-layout">
  3. <div class="d-header">
  4. <ul class="tab-list">
  5. <li @click="tabActive = item.id" :class="{active:tabActive === item.id}" v-for="(item,i) in tabList" :key="i">
  6. {{item.name}}
  7. </li>
  8. </ul>
  9. <div class="tab-search">
  10. <input v-model="searchKey" @keyup.enter="getList(searchKey)" type="text" placeholder="搜索设备ID">
  11. <i class="iconfont icon-sousuo" @click="getList(searchKey)"></i>
  12. </div>
  13. </div>
  14. <div class="d-con" v-if="total">
  15. <div class="edit-item item" @click="addDevice">
  16. <div class="plus-con">
  17. <div class="iconplus">
  18. <span></span>
  19. <span></span>
  20. </div>
  21. <p>添加新设备</p>
  22. </div>
  23. </div>
  24. <div class="d-item item" v-for="(item,i) in mydevice.list" :key="i">
  25. <div class="i-left" :style="{marginTop:tabActive===4?'15px':'25px'}">
  26. <template v-if="tabActive===4">
  27. <p class="d-id">ID:{{item.childName}}</p>
  28. <p class="p-sub">{{item.spaceEndTime||'云存储空间'}}</p>
  29. <div class="capacity">
  30. <div class="c-line">
  31. <div class="active" :style="{width:getBar(item.usedSpace,item.totalSpace)}"></div>
  32. </div>
  33. </div>
  34. <p class="p-sub">{{item.usedSpaceStr}} / {{item.totalSpaceStr}}</p>
  35. <div class="d-edit">
  36. <span @click="$router.push({path:'/privilege'})">升级</span>
  37. <span @click="$router.push({name:'introduce',params:{id:item.childName}})">扩容</span>
  38. <span @click="unbind(item)">解绑</span>
  39. </div>
  40. </template>
  41. <template v-else>
  42. <p class="d-id">ID:{{item.childName}}</p>
  43. <p class="p-sub">剩余点数:{{item.balance}}</p>
  44. <div class="d-edit">
  45. <span @click="$router.push({name:'introtow',params:{id:item.childName}})">充值</span>
  46. <span @click="unbind(item)">解绑</span>
  47. </div>
  48. </template>
  49. </div>
  50. <div class="i-right">
  51. <img :src="tabActive===4?`${$cdn}images/banner_pro.png`:`${$cdn}images/t_product.png`" alt="">
  52. <img v-if="item.spaceEndTime" class="king" :src="`${$cdn}images/icon-huiyuan.png`" alt="">
  53. </div>
  54. </div>
  55. </div>
  56. <div class="scene-nothing" v-else>
  57. <img src="@/assets/images/nothing.png">
  58. <div>居然还没有新时代空间建模神器<br/>赶紧入手吧</div>
  59. </div>
  60. <div class="paging" v-if="total">
  61. <Paging @clickHandle="pageChange" :current="currentPage" :total="total" :equable="pageSize" />
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import { mapState } from 'vuex'
  67. import Paging from '@/components/Paging'
  68. export default {
  69. components: {Paging},
  70. data () {
  71. let tabList = [
  72. {
  73. name: '四维看看Pro',
  74. id: 4
  75. }, {
  76. name: '四维看看Lite',
  77. id: 0
  78. }
  79. ]
  80. return {
  81. tabList,
  82. tabActive: 4,
  83. currentPage: 1,
  84. total: 0,
  85. searchKey: '',
  86. pageSize: 8
  87. }
  88. },
  89. computed: {
  90. ...mapState({
  91. token: state => state.user.token,
  92. mydevice: state => {
  93. let type = Object.prototype.toString.call(state.user.mydevice)
  94. if (type === '[object Object]') {
  95. return state.user.mydevice
  96. }
  97. let condition = state.user.mydevice && state.user.mydevice !== 'null' && type !== '[object Array]'
  98. return (condition ? JSON.parse(state.user.mydevice) : {})
  99. }
  100. })
  101. },
  102. watch: {
  103. currentPage () {
  104. this.getList()
  105. },
  106. tabActive (newVal) {
  107. this.currentPage === 1 ? this.getList() : this.currentPage = 1
  108. }
  109. },
  110. mounted () {
  111. this.getList()
  112. },
  113. methods: {
  114. getPercent (a, b) {
  115. let temp = a / b
  116. if (temp < 1) {
  117. return '<1'
  118. }
  119. return Math.round(temp)
  120. },
  121. getBar (a, b) {
  122. let temp = a / b
  123. if (temp < 1) {
  124. return '1%'
  125. }
  126. return Math.round(temp) + '%'
  127. },
  128. async unbind (item) {
  129. this.$toast.showConfirm('warn', '确定要解绑当前设备吗?', async () => {
  130. let params = {
  131. cameraId: item.id
  132. }
  133. let res = await this.$http({
  134. method: 'post',
  135. data: params,
  136. headers: {
  137. token: this.token
  138. },
  139. url: '/user/unbindCamera'
  140. })
  141. let data = res.data
  142. if (data.code === 0) {
  143. return this.$toast.show('warn', '解绑成功', () => {
  144. this.getList()
  145. })
  146. }
  147. return this.$toast.show('error', `解绑失败,${data.msg}`)
  148. })
  149. },
  150. pageChange (data) {
  151. this.currentPage = data
  152. },
  153. addDevice () {
  154. let val = this.tabActive === 4 ? 1 : 0
  155. this.$toast.showBinding(val)
  156. },
  157. async getList (searchKey = '') {
  158. window.scrollTo(0, 0)
  159. let params = {
  160. cameraType: this.tabActive,
  161. childName: searchKey,
  162. pageNum: searchKey ? 1 : this.currentPage,
  163. pageSize: this.pageSize
  164. }
  165. await this.$store.dispatch('getUserDevice', params)
  166. this.pageSize = this.mydevice.pageSize
  167. this.total = this.mydevice.total || 0
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. $theme-color: #1fe4dc;
  174. $font-color: #2d2d2d;
  175. .device-layout{
  176. margin: 30px 0 30px 0;
  177. width: 995px;
  178. color: $font-color;
  179. .d-header{
  180. margin-left: 40px;
  181. height: 30px;
  182. .tab-list{
  183. display: inline-block;
  184. li{
  185. display: inline-block;
  186. margin-right: 40px;
  187. cursor: pointer;
  188. font-size: 14px;
  189. line-height: 1.5;
  190. }
  191. .active{
  192. color: $theme-color;
  193. border-bottom: 1px solid $theme-color;
  194. }
  195. }
  196. .tab-search{
  197. float: right;
  198. position: relative;
  199. width: 200px;
  200. padding-left: 10px;
  201. margin-right: 35px;
  202. border: 1px solid #ccc;
  203. display: flex;
  204. .iconfont{
  205. width: 28px;
  206. height: 28px;
  207. padding: 6px;
  208. background: #e4e4e4;
  209. }
  210. input{
  211. width: 100%;
  212. font-size: 14px;
  213. appearance: none;
  214. line-height: 28px;
  215. height: 28px;
  216. border: 0;
  217. }
  218. }
  219. }
  220. .d-con{
  221. margin-left: 40px;
  222. display: inline-block;
  223. .item{
  224. display: inline-block;
  225. box-shadow: 0 4px 4px rgba($color: #000000, $alpha: 0.1);
  226. position: relative;
  227. width: 280px;
  228. height: 180px;
  229. margin: 36px 36px 0 0;
  230. }
  231. .edit-item{
  232. cursor: pointer;
  233. vertical-align: top;
  234. .plus-con{
  235. position: absolute;
  236. text-align: center;
  237. transform: translate(-50%,-50%);
  238. top: 50%;
  239. left: 50%;
  240. .iconplus{
  241. position: relative;
  242. width: 50px;
  243. height: 50px;
  244. margin: 0 auto;
  245. span{
  246. position: absolute;
  247. transform: translate(-50%,-50%);
  248. top: 50%;
  249. left: 50%;
  250. display: inline-block;
  251. width: 50px;
  252. height: 6px;
  253. background: $font-color;
  254. &:last-child{
  255. transform: translate(-50%,-50%) rotate(90deg)
  256. }
  257. }
  258. }
  259. p{
  260. margin-top: 28px;
  261. }
  262. }
  263. }
  264. .d-item{
  265. padding: 10px 24px 10px 30px;
  266. .i-left{
  267. display: inline-block;
  268. vertical-align: top;
  269. width: 145px;
  270. margin-top: 25px;
  271. .d-id{
  272. color: 16px;
  273. font-weight: bold;
  274. margin-bottom: 5px;
  275. }
  276. .capacity{
  277. margin: 5px 0;
  278. .c-line{
  279. width: 100%;
  280. height: 10px;
  281. background-color: #ccc;
  282. .active{
  283. background-color:$theme-color;
  284. height: 100%;
  285. }
  286. }
  287. }
  288. .p-sub{
  289. color: #969696;
  290. font-size: 14px;
  291. }
  292. .d-edit{
  293. margin-top: 10px;
  294. font-size: 14px;
  295. position: absolute;
  296. bottom: 30px;
  297. span{
  298. cursor: pointer;
  299. }
  300. }
  301. }
  302. .i-right{
  303. vertical-align: top;
  304. float: right;
  305. height: 100%;
  306. position: relative;
  307. img{
  308. height:100%;
  309. }
  310. .king{
  311. position: absolute;
  312. top: -17px;
  313. right: -22px;
  314. width: 44px;
  315. height: 34px;
  316. }
  317. }
  318. }
  319. }
  320. .scene-nothing{
  321. padding: 42px 0 0 40px;
  322. img{
  323. padding-bottom: 22px;
  324. }
  325. div{
  326. font-size: 16px;
  327. color: #969696;
  328. text-align: center;
  329. width: 230px;
  330. }
  331. }
  332. .paging {
  333. // border-left: #e5e5e5 1px solid;
  334. height: 100%;
  335. margin: 40px 0;
  336. & /deep/ .layout {
  337. text-align: left;
  338. margin-top: 0;
  339. margin-left: 15px;
  340. }
  341. & /deep/ .layout a:not(:last-child) {
  342. margin: 10px 8px;
  343. font-size: 16px;
  344. display: inline-block;
  345. font-weight: 500;
  346. cursor: pointer;
  347. user-select: none;
  348. color: #999;
  349. position: relative;
  350. transition: color 0.3s;
  351. }
  352. & /deep/ .layout a:last-child {
  353. position: relative;
  354. top: -5px;
  355. display: -ms-inline-flexbox;
  356. display: inline-flex;
  357. -ms-flex-align: center;
  358. align-items: center;
  359. height: 22px;
  360. padding: 0 9.6px;
  361. padding: 0 0.6rem;
  362. }
  363. & /deep/ .layout a:last-child::before,
  364. & /deep/ .layout a:last-child::after {
  365. content: "";
  366. display: inline-block;
  367. will-change: transform;
  368. transition: transform 0.3s;
  369. }
  370. & /deep/ .layout a:not(:last-child).active::after,
  371. & /deep/ .layout a:not(:last-child).active,
  372. & /deep/ .layout a:not(:last-child):hover,
  373. & /deep/ .layout a:not(:last-child):hover::after {
  374. color: #111111;
  375. transform: scaleX(1);
  376. }
  377. & /deep/ .layout a:not(:last-child)::after {
  378. content: "";
  379. height: 3px;
  380. width: 140%;
  381. background-color: #111;
  382. display: block;
  383. margin-left: -20%;
  384. margin-top: 3px;
  385. transform-origin: 50% 50%;
  386. transform: scaleX(0);
  387. will-change: transform;
  388. transition: transform 0.3s;
  389. }
  390. }
  391. }
  392. </style>