index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <?php
  2. ?>
  3. <div id="app" v-cloak>
  4. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  5. <div slot="header">
  6. <span>名片列表</span>
  7. </div>
  8. <el-row :gutter="10" style="margin-bottom: 10px">
  9. <el-col :span="8">
  10. <el-card shadow="hover">
  11. <div slot="header" class="clearfix">
  12. <strong>名片总数量</strong>
  13. </div>
  14. <div>
  15. <strong style="font-size: 18px">{{pagination.totalCount}}</strong>
  16. </div>
  17. </el-card>
  18. </el-col>
  19. <el-col :span="8">
  20. <el-card shadow="hover">
  21. <div slot="header" class="clearfix">
  22. <strong>分享总次数</strong>
  23. </div>
  24. <div>
  25. <strong style="font-size: 18px">{{sum.share}}</strong>
  26. </div>
  27. </el-card>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-card shadow="hover">
  31. <div slot="header" class="clearfix">
  32. <strong>访问总次数</strong>
  33. </div>
  34. <div>
  35. <strong style="font-size: 18px">{{sum.view}}</strong>
  36. </div>
  37. </el-card>
  38. </el-col>
  39. </el-row>
  40. <div class="table-body">
  41. <div id="qrcode-info" style="position: fixed;top: 10000000000px;">
  42. <!-- 二维码 -->
  43. <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  44. </div>
  45. <div class="input-item">
  46. <el-input @keyup.enter.native="handle('search')" size="small" placeholder="请输入用户ID/昵称/手机号" v-model="keyword"
  47. clearable @clear="handle('search')">
  48. <el-button slot="append" icon="el-icon-search" @click="handle('search')"></el-button>
  49. </el-input>
  50. </div>
  51. <el-table :data="list" border v-loading="loading" size="small" style="margin-bottom: 15px;">
  52. <el-table-column prop="user_id" label="会员ID" width="100" align="center"></el-table-column>
  53. <el-table-column align="left" label="用户信息" :show-overflow-tooltip="true">
  54. <template slot-scope="scope">
  55. <div flex="cross:center">
  56. <div style="margin-right: 10px;">
  57. <el-image
  58. style="width: 50px; height: 50px;border-radius: 5px;"
  59. :src="scope.row.user.avatar_url?scope.row.user.avatar_url:'/resources/img/common/default-avatar.png'">
  60. </el-image>
  61. </div>
  62. <div class="table-info-text">
  63. <div>{{scope.row.user.nickname}}</div>
  64. </div>
  65. </div>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="姓名" align="center">
  69. <template slot-scope="scope">
  70. <div>{{scope.row.nickname}}</div>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="手机号码" align="center">
  74. <template slot-scope="scope">
  75. <div>{{scope.row.mobile}}</div>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="角色" align="center">
  79. <template slot-scope="scope">
  80. <div>{{roles[scope.row.cardUser.role_type] ? roles[scope.row.cardUser.role_type] : '无角色'}}</div>
  81. </template>
  82. </el-table-column>
  83. <el-table-column prop="user_type" label="职位" align="center">
  84. <template slot-scope="scope">
  85. <div>{{position[scope.row.position_id] ? position[scope.row.position_id] : '无职位'}}</div>
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="user_type" label="分享次数" align="center" width="100">
  89. <template slot-scope="scope">
  90. <div>{{scope.row.share_num}}</div>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="user_type" label="访问次数" align="center" width="100">
  94. <template slot-scope="scope">
  95. <div>{{scope.row.browse_num}}</div>
  96. </template>
  97. </el-table-column>
  98. <el-table-column prop="user_type" label="点赞次数" align="center" width="100">
  99. <template slot-scope="scope">
  100. <div>{{scope.row.like_num}}</div>
  101. </template>
  102. </el-table-column>
  103. <el-table-column prop="user_type" label="名片码" align="center">
  104. <template slot-scope="scope">
  105. <el-tooltip effect="dark" v-if="scope.row.qrcode" content="点击查看/下载二维码" placement="top">
  106. <el-image @click="onDownloadQrcode(scope.row)" style="width: 80px; height: 80px;" :src="scope.row.qrcode"></el-image>
  107. </el-tooltip>
  108. <div v-else>
  109. 生成中...
  110. </div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="操作" align="center" width="150">
  114. <template slot-scope="scope">
  115. <el-button type="text" style="display:none;" size="mini" circle @click.native="handle('getQrcode', scope.row)">名片码</el-button>
  116. <el-button type="text" size="mini" circle @click.native="handle('info', scope.row.id)">查看</el-button>
  117. <el-button @click="handle('delete', scope.row, scope.$index)" type="text" circle size="mini">删除</el-button>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <div flex="box:last cross:center">
  122. <div></div>
  123. <div>
  124. <el-pagination v-if="pagination" :page-size="pagination.defaultPageSize"
  125. style="display: inline-block;float: right;" background @current-change="handle('pageChange', $event)"
  126. layout="prev, pager, next" :total="pagination.totalCount">
  127. </el-pagination>
  128. </div>
  129. </div>
  130. </div>
  131. <el-dialog title="分享" :visible.sync="showQrcodeDialog" :append-to-body="true" width="30%">
  132. <div>
  133. <div class="share-name">分享链接</div>
  134. <el-input style="width: 50%;" v-model="shareData.url" placeholder="暂无链接" disabled>
  135. <template slot="append">
  136. <el-button circle size="mini" type="text" @click="copyLink(shareData.url)" class="copy_btn">复制</el-button>
  137. </template>
  138. </el-input>
  139. </div>
  140. <div style="padding-top: 10px" class="share-pop-model" flex>
  141. <div class="share-name">二维码</div>
  142. <div style="width: 180px; height: 180px;background: #F2F2F2;margin-right: 12px;" flex="main:center cross:center">
  143. <el-image id="code-img" style="width: 144px; height: 144px;" :src="shareData.qrcode"></el-image>
  144. </div>
  145. <el-button flex type="text" @click="downloadShareImg()">下载二维码</el-button>
  146. </div>
  147. </el-dialog>
  148. </el-card>
  149. </div>
  150. <script>
  151. const app = new Vue({
  152. el: '#app',
  153. data: {
  154. page: 1,
  155. keyword: '',
  156. loading: false,
  157. list: [],
  158. position: [],
  159. pagination: {
  160. totalCount: 0
  161. },
  162. QRcodeLoading: false,
  163. sharePop: false,
  164. web_url:'',
  165. mall_sign:'',
  166. shareData: {
  167. url: '',
  168. qrcode: ''
  169. },
  170. sum: {
  171. share: 0,
  172. view: 0
  173. },
  174. roles: {},
  175. store_collection_url: '',
  176. showQrcodeDialog: false
  177. },
  178. mounted() {
  179. this.send('getPosition');
  180. this.send('getData');
  181. },
  182. methods: {
  183. async handle(type, param1 = null, param2 = null) {
  184. switch (type) {
  185. case 'pageChange':
  186. this.page = param1;
  187. this.send('getData');
  188. break;
  189. case 'search':
  190. this.send('getData');
  191. break;
  192. case 'delete':
  193. this.$confirm('删除该卡片, 是否继续?', '提示', {
  194. confirmButtonText: '确定',
  195. cancelButtonText: '取消',
  196. type: 'warning'
  197. }).then(e=>{
  198. this.loading = true;
  199. request({
  200. params: {
  201. r: 'business-card/card/delete',
  202. },
  203. method: 'post',
  204. data: {
  205. id: param1.id,
  206. }
  207. }).then(e=>{
  208. this.loading = false;
  209. if (e.data.code === 0) {
  210. this.$message.success(e.data.msg);
  211. this.list.splice(param2, 1);
  212. } else {
  213. this.$message.error(e.data.msg);
  214. }
  215. }).catch(e=>{
  216. this.loading = false;
  217. this.$message.error(e.data.msg);
  218. })
  219. }).catch(() => {
  220. this.$message.info('已取消删除')
  221. });
  222. break;
  223. case 'getQrcode':
  224. this.QRcodeLoading = true;
  225. this.sharePop = true;
  226. let url = this.web_url+"/#/plugins/Card/index?card_id="+param1.id+'&mall_sign='+this.mall_sign+'&sign='+this.mall_sign+'&pid='+param1.user_id+'&share_id='+param1.user_id+'&share_type=1';
  227. this.shareData.img = await this.handle('createQrcode', url);
  228. this.shareData.url = url;
  229. this.QRcodeLoading = false;
  230. break;
  231. case 'createQrcode':
  232. let qrcodeInfo = document.getElementById("qrcode-info");
  233. document.getElementById("qrcode").remove(); //删除生成的二维码
  234. let addCodeDom = document.createElement("div")
  235. addCodeDom.setAttribute("id", "qrcode");
  236. addCodeDom.setAttribute("style", "width:300px; height:300px;");
  237. qrcodeInfo.appendChild(addCodeDom) //添加标签
  238. let qrCodeDom = document.getElementById("qrcode")
  239. var qrcode = new QRCode(qrCodeDom, {
  240. width: 300,
  241. height: 300
  242. });
  243. qrcode.makeCode(param1);
  244. // 获取二维码生成的图片信息
  245. return new Promise((req, rej) => {
  246. setTimeout(() => {
  247. src = qrCodeDom.getElementsByTagName("img")[0].src;
  248. req(src)
  249. }, 200);
  250. })
  251. break;
  252. case 'copyLink':
  253. if (!this.shareData.url) {
  254. alert('请输入要复制的内容')
  255. } else {
  256. var copyurl = this.shareData.url;
  257. // createElement() 方法通过指定名称创建一个元素
  258. var copyInput = document.createElement('input')
  259. copyInput.setAttribute('value', copyurl)
  260. document.body.appendChild(copyInput)
  261. copyInput.select()
  262. try {
  263. var copyed = document.execCommand('copy')
  264. if (copyed) {
  265. document.body.removeChild(copyInput)
  266. this.$message.success('复制成功')
  267. }
  268. } catch {
  269. this.$message.success('复制失败,请检查浏览器兼容')
  270. }
  271. }
  272. break;
  273. case 'info':
  274. navigateTo({
  275. r: 'business-card/card/card-info',
  276. id: param1
  277. })
  278. break;
  279. }
  280. },
  281. async batchGenQrcode(item, index) {
  282. let url = `${this.web_url}/#/plugins2/BusinessCard/index?card_id=${item.id}&mall_sign=${this.mall_sign}&sign=${this.mall_sign}&pid=${item.user_id}&share_id=${item.user_id}&share_type=1`
  283. // let url = this.web_url+"/#/plugins/BusinessCard/index?card_id="+item.id+'&mall_sign='+this.mall_sign+'&pid='+item.user_id+'&share_id='+item.user_id+'&share_type=1';
  284. this.$set(this.list[index], 'qrcode', await this.handle('createQrcode', url))
  285. this.$set(this.list[index], 'h5_url', url)
  286. // this.shareData.img = await this.handle('createQrcode', url);
  287. // this.shareData.url = url;
  288. },
  289. showCollectionCode(url, fun) {
  290. this.store_collection_url = url;
  291. setTimeout(() => {
  292. fun();
  293. }, 300)
  294. },
  295. downloadShareImg() {
  296. fetch(this.shareData.qrcode).then(res => res.blob().then(blob => {
  297. var a = document.createElement('a');
  298. var url = window.URL.createObjectURL(blob);
  299. a.href = url;
  300. a.download = "";
  301. a.click();
  302. window.URL.revokeObjectURL(url);
  303. }))
  304. },
  305. onDownloadQrcode(item) {
  306. this.shareData.url = item.h5_url
  307. this.shareData.qrcode = item.qrcode
  308. this.showQrcodeDialog = true
  309. },
  310. copyLink(str) {
  311. var clipboard = new ClipboardJS('.copy_btn', {
  312. text: function() {
  313. return str;
  314. }
  315. });
  316. var self = this;
  317. clipboard.on('success', function(e) {
  318. // console.log("success")
  319. self.$message.success('复制成功');
  320. e.clearSelection();
  321. clipboard.destroy()
  322. });
  323. clipboard.on('error', function(e) {
  324. // console.log("error")
  325. self.$message.error('复制失败,请手动复制');
  326. });
  327. },
  328. send(type, param1 = null) {
  329. switch(type) {
  330. case 'getPosition':
  331. request({
  332. params: {
  333. r: 'business-card/card/get-position'
  334. }
  335. }).then(e=>{
  336. if (e.data.code == 0) {
  337. this.position = e.data.data;
  338. console.log('this.position', this.position)
  339. }
  340. }).catch(e=>{
  341. })
  342. break;
  343. case 'getData':
  344. this.loading = true;
  345. request({
  346. params: {
  347. r: 'business-card/card/index',
  348. keyword: this.keyword,
  349. page: this.page
  350. }
  351. }).then(e=>{
  352. if (e.data.code == 0) {
  353. this.list = e.data.data.list;
  354. this.web_url = e.data.data.web_url;
  355. this.mall_sign = e.data.data.mall_sign;
  356. if (this.list.length > 0) {
  357. for (let listKey in this.list) {
  358. this.batchGenQrcode(this.list[listKey], listKey)
  359. }
  360. }
  361. this.pagination = e.data.data.pagination;
  362. this.sum = e.data.data.sum
  363. this.roles = e.data.data.roles
  364. } else{
  365. this.$message.error(e.data.msg);
  366. }
  367. this.loading = false;
  368. }).catch(e=>{
  369. this.loading = false;
  370. this.$message.error(e.data.msg);
  371. })
  372. break;
  373. }
  374. }
  375. }
  376. })
  377. </script>
  378. <style>
  379. .el-tabs__header {
  380. font-size: 16px;
  381. }
  382. .table-body {
  383. padding: 20px;
  384. background-color: #fff;
  385. }
  386. .table-body .el-button {
  387. padding: 0 !important;
  388. border: 0;
  389. margin: 0 5px;
  390. }
  391. .input-item {
  392. width: 250px;
  393. margin: 0 0 20px;
  394. display: inline-block;
  395. }
  396. .input-item .el-input__inner {
  397. border-right: 0;
  398. }
  399. .input-item .el-input__inner:hover {
  400. border: 1px solid #dcdfe6;
  401. border-right: 0;
  402. outline: 0;
  403. }
  404. .input-item .el-input__inner:focus {
  405. border: 1px solid #dcdfe6;
  406. border-right: 0;
  407. outline: 0;
  408. }
  409. .input-item .el-input-group__append {
  410. background-color: #fff;
  411. border-left: 0;
  412. width: 10%;
  413. padding: 0;
  414. }
  415. .input-item .el-input-group__append .el-button {
  416. padding: 0;
  417. }
  418. .input-item .el-input-group__append .el-button {
  419. margin: 0;
  420. }
  421. .batch {
  422. margin: 0 0 20px;
  423. display: inline-block;
  424. }
  425. .batch .el-button {
  426. padding: 9px 15px !important;
  427. }
  428. .item-box{
  429. margin-right: 20px;
  430. }
  431. .item-box .label{
  432. margin-right: 8px;
  433. }
  434. .el-tag + .el-tag {
  435. margin-left: 10px;
  436. }
  437. .el-table th>.cell{
  438. color: #333;
  439. font-weight: bold;
  440. font-size: 14px;
  441. }
  442. .el-table__footer-wrapper, .el-table__header-wrapper{
  443. }
  444. .el-table .warning-row {
  445. background: #F5F7FC;
  446. }
  447. .el-table .success-row {
  448. background: #ffffff;
  449. }
  450. .popoverClass{
  451. text-align: center;
  452. background: #FFFFFF;
  453. box-shadow: 3px 5px 20px rgba(0, 0, 0, 0.16);
  454. opacity: 1;
  455. border-radius: 5px;
  456. }
  457. .share-name {
  458. width: 90px;
  459. display: inline-block;
  460. margin-right: 18px;
  461. text-align: end;
  462. }
  463. .share-pop-model {
  464. margin-top: 20px;
  465. }
  466. </style>