crowd-control.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <template>
  2. <div class="crowd-control-content">
  3. <div class="table-page-search-wrapper">
  4. <a-form
  5. layout="inline"
  6. :form="form"
  7. hide-required-mark
  8. @submit="handleQueryList"
  9. >
  10. <a-row :gutter="24">
  11. <a-col :md="8" :sm="8" :xxl="6">
  12. <selectTable :projectId.sync="projectId" ref="selectTable" :requireCheck="false"></selectTable>
  13. </a-col>
  14. <a-col :md="8" :sm="8" :xxl="6">
  15. <a-form-item
  16. label="名称"
  17. >
  18. <a-input
  19. v-decorator="['name']" type="text"
  20. placeholder="请输入"
  21. />
  22. </a-form-item>
  23. </a-col>
  24. <a-col :md="8" :sm="8" :xxl="6">
  25. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  26. <a-button type="primary" icon="search" @click="handleQueryList">查询</a-button>
  27. <a-button type="primary" @click="handleResetForm" icon="reload" class="middle-button">重置</a-button>
  28. <a-button type="primary" @click="handleUploadPerson" class="middle-button">
  29. 上传人群包
  30. </a-button>
  31. <a-button type="primary" @click="handleUpdatePerson" v-if="realShow" :loading="realLoading">
  32. 更新人群
  33. </a-button>
  34. </span>
  35. </a-col>
  36. </a-row>
  37. </a-form>
  38. </div>
  39. <div class="control-con-table">
  40. <a-table
  41. ref="table"
  42. size="middle"
  43. bordered
  44. :columns="columns"
  45. :dataSource="dataSource"
  46. :pagination="false"
  47. >
  48. <span slot="action" slot-scope="text, record">
  49. <a @click="handleEdit(record)">推送</a>
  50. <a-divider type="vertical" />
  51. <a @click="handleDelete(record)">删除</a>
  52. </span>
  53. <span slot="actionMore" slot-scope="text, record">
  54. <a @click="handleHistory(record)">推送历史</a>
  55. </span>
  56. <span slot="cause" slot-scope="text, record">
  57. <a class="cause-text-class" @click="handleCause(record)">失败原因</a>
  58. </span>
  59. <span slot="depRelax" slot-scope="text, record">
  60. <a @click="handleAcountRelax('unit', record)">{{ text }}</a>
  61. </span>
  62. <span slot="acountRelax" slot-scope="text, record">
  63. <a @click="handleAcountRelax('acount', record)">{{ text }}</a>
  64. </span>
  65. </a-table>
  66. <a-pagination
  67. class="pagin-table-class"
  68. :total="totalAll"
  69. :show-total="total => `共 ${totalAll} 条`"
  70. size="small"
  71. show-quick-jumper
  72. @change="onShowSizeChange"
  73. @showSizeChange="onShowSizeChange"
  74. />
  75. </div>
  76. <a-modal
  77. v-if="personVisible"
  78. title="上传人群包"
  79. class="person-modal"
  80. :visible="personVisible"
  81. :confirm-loading="confirmLoading"
  82. @ok="handleOk"
  83. @cancel="handleCancel"
  84. >
  85. <div>
  86. <a-form-model
  87. ref="ruleForm"
  88. :model="personForm"
  89. :rules="personRules"
  90. :label-col="labelCol"
  91. :wrapper-col="wrapperCol"
  92. >
  93. <selectTable
  94. :projectId.sync="uploadProjectId"
  95. :labelCol="labelCol"
  96. :disabled="disabled"
  97. :requireCheck="true"
  98. v-if="!disabled"
  99. ></selectTable>
  100. <a-form-model-item ref="name" label="人群包名称" prop="name">
  101. <a-input
  102. v-model="personForm.name"
  103. placeholder="请输入人群包名称"
  104. :disabled="personNameDisabled"
  105. />
  106. </a-form-model-item>
  107. <a-form-model-item label="匹配类型" prop="resource">
  108. <a-radio-group v-model="personForm.resource" :disabled="personResourceDisabled">
  109. <a-radio v-for="item in mateTypeTasks" :key="item.label" :value="item.label">{{ item.value }}</a-radio>
  110. </a-radio-group>
  111. </a-form-model-item>
  112. <!-- <a-form-model-item label="选择账户" class="grid-form-item-account">
  113. <acount-search class="acount-search-class" :appId.sync="uploadAcountIds" :multiple="false"></acount-search>
  114. </a-form-model-item> -->
  115. <a-form-model-item label="上传人群包">
  116. <a-upload
  117. name="file"
  118. :file-list="fileList"
  119. :before-upload="beforeUpload"
  120. @change="handleChange"
  121. >
  122. <a-button><a-icon type="upload" />文件上传</a-button>
  123. </a-upload>
  124. <p class="upload-txt-rules">
  125. 1、文件格式:支持上传*.txt(utf-8)文本;也支持将单个/多个*.txt文件经过Zip格式压缩上传
  126. </p>
  127. <p class="upload-txt-rules">2、文件大小:单个文件大小不能超过1G</p>
  128. <p class="upload-txt-rules">3、内容编排:每行一条记录</p>
  129. </a-form-model-item>
  130. </a-form-model>
  131. </div>
  132. </a-modal>
  133. <a-modal
  134. title="推送账户"
  135. v-if="pushVisible"
  136. :visible="pushVisible"
  137. :confirm-loading="pushConfirmLoading"
  138. dialog-class="push-modal"
  139. @ok="handlePushSure"
  140. @cancel="handlePushCancel"
  141. >
  142. <div>
  143. <div class="acount-title">
  144. <div class="acount-title-left">已选人群包</div>
  145. <div class="acount-title-right">{{ tableSelectList.orientationName }} (ID: {{ tableSelectList.id }})</div>
  146. </div>
  147. <div class="acount-title push-plate">
  148. <div class="acount-title-left">推送平台</div>
  149. <div class="acount-title-right">
  150. <a-radio-group default-value="a" button-style="solid">
  151. <a-radio-button value="a">效果</a-radio-button>
  152. <a-radio-button value="b" disabled>品牌</a-radio-button>
  153. </a-radio-group>
  154. </div>
  155. </div>
  156. <tree-select :httpSrc="src" @applyType="handleApplyType" :projectId="tableSelectList.projectId" :templateId="tableSelectList.id"></tree-select>
  157. </div>
  158. </a-modal>
  159. <a-modal
  160. title="失败原因"
  161. v-if="causeVisible"
  162. :visible="causeVisible"
  163. :confirm-loading="causeConfirmLoading"
  164. :footer="null"
  165. dialog-class="cause-modal"
  166. @cancel="handleCauseCancel"
  167. >
  168. <div>
  169. <div class="cause-modal-table-class">
  170. <a-table :columns="causeColumns" :data-source="causeData" bordered :pagination="false"></a-table>
  171. </div>
  172. <a-pagination
  173. class="pagin-table-class"
  174. :total="totalAllCause"
  175. size="small"
  176. @change="handleCauseSizeChange"
  177. />
  178. </div>
  179. </a-modal>
  180. <a-modal
  181. :title="relaxStatus === 'unit' ? '相关组' : '相关账户'"
  182. v-if="relaxVisible"
  183. :visible="relaxVisible"
  184. :confirm-loading="relaxConfirmLoading"
  185. :footer="null"
  186. dialog-class="relax-modal"
  187. @cancel="handleRelaxCancel"
  188. >
  189. <div>
  190. <template v-if="relaxStatus === 'unit'">
  191. <AcountSearch :appId.sync="unitAccountId" :multiple="false" request="2,4" ref="treeSelect" style="margin-bottom:8px;width:300px " />
  192. <a-table :columns="depColumns" :data-source="depData" bordered :pagination="accountIpagination">
  193. </a-table>
  194. </template>
  195. <template v-if="relaxStatus === 'acount'">
  196. <a-table :columns="acountColumns" :data-source="acountData" bordered :pagination="accountIpagination"></a-table>
  197. </template>
  198. </div>
  199. </a-modal>
  200. <a-modal
  201. title="推送历史"
  202. v-if="historyVisible"
  203. :visible="historyVisible"
  204. :confirm-loading="causeConfirmLoading"
  205. :footer="null"
  206. dialog-class="cause-modal"
  207. @cancel="historyVisible = false"
  208. >
  209. <div>
  210. <div class="cause-modal-table-class">
  211. <a-table :columns="causeColumns" :data-source="historyData" bordered :pagination="false">
  212. <span slot="action" slot-scope="text, record">
  213. <a-popconfirm
  214. title="是否重新推送?"
  215. ok-text="是"
  216. cancel-text="否"
  217. @confirm="handleAgian(record)"
  218. >
  219. <a :disabled="record.result==='推送成功'">重新推送</a>
  220. </a-popconfirm>
  221. </span>
  222. </a-table>
  223. </div>
  224. <a-pagination
  225. class="pagin-table-class"
  226. :total="totalAllHistory"
  227. size="small"
  228. @change="handleHistorySizeChange"
  229. />
  230. </div>
  231. </a-modal>
  232. </div>
  233. </template>
  234. <script>
  235. import TreeSelect from '@/views/modules/autoLaunch/directional/components/tree-select.vue';
  236. import {getAction, postAction} from '@/api/manage';
  237. import AcountSearch from '@/views/modules/Statistics/components/Treeselect.vue';
  238. import selectTable from '@/views/modules/Statistics/components/selectPagination.vue';
  239. import AppMarketService from './crowd-control-service';
  240. import BMF from 'browser-md5-file';
  241. import { mapGetters } from 'vuex';
  242. let COS = require('cos-js-sdk-v5');
  243. let cos = new COS({
  244. SecretId: 'AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets',
  245. SecretKey: 'tXzuwMfplTTK3c9GFUyETilasvQfePu9'
  246. });
  247. export default {
  248. name: 'crowd-control',
  249. components: {
  250. TreeSelect,
  251. AcountSearch,
  252. selectTable
  253. },
  254. data() {
  255. let that = this;
  256. return {
  257. src: '/kuaishouPopulationPackage/getAccountByProjectId',
  258. unitAccountId: '',
  259. personResourceDisabled: false,
  260. personNameDisabled: false,
  261. totalAllCause: 0,
  262. acountId: undefined, // 搜索的账户ID
  263. projectId: null,
  264. uploadAcountIds: '',
  265. uploadProjectId: '',
  266. totalAll: 10,
  267. finallyRightTree: [],
  268. fileList: [],
  269. relaxVisible: false,
  270. relaxConfirmLoading: false,
  271. pushVisible: false,
  272. pushConfirmLoading: false,
  273. causeVisible: false,
  274. causeConfirmLoading: false,
  275. labelCol: {span: 4},
  276. wrapperCol: {span: 14},
  277. personVisible: false,
  278. confirmLoading: false,
  279. mateTypeTasks: AppMarketService.setMateTypeTasks(), // 匹配类型
  280. populationTypeTasks: AppMarketService.setPopulationTypeTasks(), // 人群包类型
  281. statusTasks: AppMarketService.setStatusTasks(), // 状态枚举
  282. relaxStatus: '',
  283. causeData: [], // 原因的table列表数据,
  284. depData: [], // 相关项目的table列表数据,
  285. acountData: [], // 相关账户的table列表数据,
  286. acountColumns: AppMarketService.setAcountColumns(), // 相关账户的table列表
  287. depColumns: AppMarketService.setDepColumns(), // 相关项目的table列表
  288. causeColumns: AppMarketService.setCauseColumns(), // 原因的table列表
  289. dataSource: [],
  290. columns: [
  291. {
  292. title: '人群包名称',
  293. align: 'center',
  294. width: 200,
  295. ellipsis: true,
  296. dataIndex: 'orientationName'
  297. },
  298. {
  299. title: '匹配类型',
  300. align: 'center',
  301. dataIndex: 'typeStr'
  302. },
  303. {
  304. title: '创建时间',
  305. dataIndex: 'statDate',
  306. align: 'center'
  307. },
  308. {
  309. title: '关联项目',
  310. dataIndex: 'projectName',
  311. align: 'center',
  312. ellipsis: true,
  313. customRender(t) {
  314. if(t) {
  315. return t
  316. }
  317. else {
  318. return '-'
  319. }
  320. }
  321. },
  322. {
  323. title: '相关账户',
  324. dataIndex: 'accountCount',
  325. align: 'center',
  326. scopedSlots: {customRender: 'acountRelax'}
  327. },
  328. {
  329. title: '相关组',
  330. dataIndex: 'unitCount',
  331. align: 'center',
  332. scopedSlots: {customRender: 'depRelax'}
  333. },
  334. {
  335. title: '操作',
  336. dataIndex: 'action',
  337. align: 'center',
  338. scopedSlots: {customRender: 'action'}
  339. },
  340. {
  341. title: '更多',
  342. dataIndex: 'actionMore',
  343. align: 'center',
  344. scopedSlots: {customRender: 'actionMore'},
  345. ellipsis: true
  346. },
  347. ],
  348. personForm: {
  349. name: '',
  350. resource: ''
  351. },
  352. personRules: AppMarketService.setPersonRules(), // 上传人群包表单校验规则
  353. tablePag: {
  354. page: 1,
  355. size: 10
  356. },
  357. // table 原因的分页
  358. causePag: {
  359. page: 1,
  360. size: 10
  361. },
  362. historyPag: {
  363. page: 1,
  364. size: 10
  365. },
  366. tableSelectList: {},
  367. acountRelaxDetail: {},
  368. causeDetailData: {},
  369. historyData: [],
  370. totalAllHistory: 0,
  371. historySelectList: null,
  372. historyVisible: false,
  373. accountIpagination: {
  374. current: 1,
  375. pageSize: 10,
  376. // pageSizeOptions: ['10', '20', '30'],
  377. showTotal: (total, range) => {
  378. return range[0] + "-" + range[1] + " 共" + total + "条"
  379. },
  380. showQuickJumper: true,
  381. showSizeChanger:false,
  382. pageSizeOptions: ['10', '30', '50'],
  383. total: 0,
  384. onChange: (current, pageSize) => {
  385. // 切换分页时的回调,
  386. // 当在页面定义change事件时,切记要把此处的事件清除,因为这两个事件重叠了,可能到时候会导致一些莫名的bug
  387. this.accountIpagination.current = current;
  388. this.accountIpagination.pageSize= pageSize;
  389. this.handleAcountRelax(this.relaxStatus ,this.acountRelaxDetail)
  390. }
  391. },
  392. realShow: false,
  393. realLoading: false
  394. };
  395. },
  396. watch: {
  397. unitAccountId: function(n,o) {
  398. if(this.relaxVisible){
  399. this.handleAcountRelax(this.relaxStatus ,this.acountRelaxDetail)
  400. }
  401. },
  402. },
  403. created() {
  404. this.form = this.$form.createForm(this);
  405. },
  406. mounted() {
  407. this.realShow = this.userInfo().realname === '管理员' ? true : false
  408. if(!this.realShow) {
  409. getAction('/kuaishou/batch/syncUserPopulationList',{ userId:this.userInfo().id, type:1}).then(res => {
  410. if(res.success) {
  411. }
  412. })
  413. }
  414. this.handleGetTableList({});
  415. },
  416. methods: {
  417. ...mapGetters(['nickname', 'avatar', 'userInfo']),
  418. handleAgian(val) {
  419. let params = {};
  420. params.id = val.id;
  421. params.accountIds = [val.accountId];
  422. postAction('/kuaishouPopulationPackage/push' ,params).then(res => {
  423. if(res.success) {
  424. if(!this.realShow) {
  425. getAction('/kuaishou/batch/syncUserPopulationList',{ userId:this.userInfo().id, type:1}).then(res => {
  426. if(res.success) {
  427. this.$message.success(res.message);
  428. this.historyVisible = false;
  429. this.handleGetTableList({});
  430. }
  431. else {
  432. this.$message.error(res.message);
  433. }
  434. })
  435. }
  436. else {
  437. this.$message.success(res.message);
  438. this.historyVisible = false;
  439. this.handleGetTableList({});
  440. }
  441. }
  442. else {
  443. this.$message.error(res.message);
  444. }
  445. })
  446. },
  447. handleHistorySizeChange(current, pageSize) {
  448. this.historyPag = {
  449. page: current,
  450. size: pageSize
  451. };
  452. this.handleHistoryTableData(this.historySelectList.id);
  453. },
  454. handleHistory(list) {
  455. this.historyVisible = true;
  456. this.handleHistoryTableData(list.id);
  457. this.historySelectList = list;
  458. },
  459. handleHistoryTableData(id) {
  460. const paramsData = {
  461. id: id,
  462. pageNo: this.historyPag.page,
  463. pageSize: this.historyPag.size,
  464. status: this.resultHistory
  465. };
  466. getAction('/kuaishouPopulationPackage/queryPushHistory', paramsData).then(result => {
  467. if (result.code === 200) {
  468. this.historyData = result.result.list || [];
  469. this.totalAllHistory = result.result.total || 0;
  470. }
  471. else {
  472. this.$message.error(result.message);
  473. }
  474. }).catch(error => {
  475. console.log(error, 'eeee');
  476. });
  477. },
  478. onShowSizeChange(current, pageSize) {
  479. const paramsData = this.form.getFieldsValue();
  480. this.tablePag = {
  481. page: current,
  482. size: pageSize
  483. };
  484. this.handleGetTableList(paramsData);
  485. },
  486. handleCauseSizeChange(current, pageSize) {
  487. this.causePag = {
  488. page: current,
  489. size: pageSize
  490. };
  491. this.handleCauseTableData();
  492. },
  493. handleGetTableList(data) {
  494. const paramsData = {
  495. orientationName: data.name,
  496. projectId: this.projectId,
  497. status: data.status,
  498. pageNo: this.tablePag.page,
  499. pageSize: this.tablePag.size
  500. };
  501. this.dataSource = []
  502. getAction('/kuaishouPopulationPackage/list', paramsData).then(result => {
  503. if (result.code === 200) {
  504. this.dataSource = result.result.list || [];
  505. this.totalAll = result.result.total || 0;
  506. }
  507. else {
  508. this.$message.error(result.message);
  509. }
  510. }).catch(error => {
  511. console.log(error, 'eeee');
  512. });
  513. },
  514. handleDelete(data) {
  515. let that = this;
  516. this.$confirm({
  517. title: '删除提示',
  518. content: '是否删除该人群包?',
  519. onOk() {
  520. getAction('/kuaishouPopulationPackage/delete', {id: data.id}).then(result => {
  521. if (result.code === 200) {
  522. that.handleGetTableList({});
  523. that.$message.success('删除成功');
  524. }
  525. else {
  526. that.$message.error(result.message);
  527. }
  528. }).catch(error => {
  529. console.log(error, 'eeee');
  530. });
  531. }
  532. });
  533. },
  534. handleAcountRelaxTable() {
  535. let url = this.relaxStatus === 'unit' ? '/kuaishouPopulationPackage/getRelatedGroups' : '/kuaishouPopulationPackage/getRelatedAccounts'
  536. let paramsData = {};
  537. paramsData.id = this.acountRelaxDetail.id;
  538. paramsData.pageNo = this.accountIpagination.current;
  539. paramsData.pageSize = this.accountIpagination.pageSize;
  540. if(this.relaxStatus === 'unit') {
  541. paramsData.accountId = this.unitAccountId;
  542. }
  543. getAction(url, paramsData).then(result => {
  544. if (result.code === 200) {
  545. if (this.relaxStatus === 'unit') {
  546. this.depData = result.result.list;
  547. }
  548. else if (this.relaxStatus === 'acount') {
  549. this.acountData = result.result.list;
  550. }
  551. this.accountIpagination.current = result.result.total;
  552. }
  553. else {
  554. this.$message.error(result.message);
  555. }
  556. }).catch(error => {
  557. console.log(error, 'eeee');
  558. });
  559. },
  560. handleAcountRelax(txt, recd) {
  561. if (txt === 'unit') {
  562. this.relaxStatus = 'unit';
  563. }
  564. else if (txt === 'acount') {
  565. this.relaxStatus = 'acount';
  566. }
  567. this.acountRelaxDetail = recd;
  568. this.handleAcountRelaxTable();
  569. this.relaxVisible = true;
  570. },
  571. handleRelaxCancel() {
  572. this.unitAccountId = '';
  573. this.relaxVisible = false;
  574. },
  575. handleCause(list) {
  576. this.causeVisible = true;
  577. this.causeDetailData = list;
  578. this.handleCauseTableData();
  579. },
  580. handleCauseTableData() {
  581. const paramsData = {
  582. signature: this.causeDetailData.signature,
  583. pageNo: this.causePag.page,
  584. pageSize: this.causePag.size
  585. };
  586. getAction('/kuaishouCrowdPack/queryFailReason', paramsData).then(result => {
  587. if (result.code === 200) {
  588. this.causeData = result.result.list || [];
  589. this.totalAllCause = result.result.total || 0;
  590. }
  591. else {
  592. this.$message.error(result.message);
  593. }
  594. }).catch(error => {
  595. console.log(error, 'eeee');
  596. });
  597. },
  598. handleApplyType(list) {
  599. this.finallyRightTree = list;
  600. },
  601. handleEdit(val) {
  602. this.tableSelectList = val;
  603. this.pushVisible = true;
  604. },
  605. handleCauseCancel() {
  606. this.causeVisible = false;
  607. },
  608. handlePushSure() {
  609. if(this.finallyRightTree.length > 0) {
  610. this.pushConfirmLoading = true;
  611. const paramsData = {
  612. accountIds: this.finallyRightTree.map(item => item.key),
  613. id: this.tableSelectList.id
  614. };
  615. postAction('/kuaishouPopulationPackage/push', paramsData).then(result => {
  616. if (result.code === 200) {
  617. if(!this.realShow) {
  618. getAction('/kuaishou/batch/syncUserPopulationList',{ userId:this.userInfo().id, type:1}).then(res => {
  619. if(res.success) {
  620. this.pushConfirmLoading = false;
  621. this.pushVisible = false;
  622. this.handleGetTableList({});
  623. this.$message.success('推送成功')
  624. }
  625. })
  626. }
  627. else {
  628. this.pushConfirmLoading = false;
  629. this.pushVisible = false;
  630. this.handleGetTableList({});
  631. this.$message.success('推送成功')
  632. }
  633. }
  634. else {
  635. this.pushConfirmLoading = false;
  636. this.$message.error(result.message);
  637. }
  638. }).catch(error => {
  639. this.pushConfirmLoading = false;
  640. console.log(error, 'eeeeeee');
  641. });
  642. }
  643. else {
  644. this.$message.error("请选择要推送的账户")
  645. }
  646. },
  647. handlePushCancel() {
  648. this.pushVisible = false;
  649. },
  650. beforeUpload(file) {
  651. this.cosUpload(file);
  652. },
  653. handleMd5(file) {
  654. let bmf = new BMF();
  655. let that = this;
  656. return new Promise(function (resolve, reject) {
  657. bmf.md5(file, (err, md5) => {
  658. getAction('kuaishouPopulationPackage/checkPopulationPackage', {signature: md5}).then(result => {
  659. if (result.code === 200) {
  660. that.personNameDisabled = false;
  661. that.personResourceDisabled = false;
  662. resolve();
  663. }
  664. else if (result.code === 201) {
  665. that.$message.error(result.message);
  666. that.personForm.name = result.result.orientationName;
  667. that.personForm.resource = result.result.type;
  668. that.personNameDisabled = true;
  669. that.personResourceDisabled = true;
  670. reject();
  671. }
  672. }).catch(error => {
  673. console.log(error, 'eeee');
  674. reject();
  675. });
  676. });
  677. });
  678. },
  679. handleChange(info) {
  680. this.fileList = info.fileList;
  681. },
  682. cosUpload(file) {
  683. let that = this;
  684. let date = new Date();
  685. let y = date.getFullYear();
  686. let MM = date.getMonth() + 1;
  687. MM = MM < 10 ? '0' + MM : MM;
  688. let d = date.getDate();
  689. d = d < 10 ? '0' + d : d;
  690. let timeElse = new Date().getTime();
  691. let arr = file.name.split('.');
  692. let str = '';
  693. for (let i = 0; i < arr.length; i++) {
  694. if (i === arr.length - 1) {
  695. }
  696. else {
  697. if (i === arr.length - 2) {
  698. str += arr[i];
  699. }
  700. else {
  701. str += arr[i] + '.';
  702. }
  703. }
  704. }
  705. cos.putObject(
  706. {
  707. Bucket: 'media-1301855440',
  708. Region: 'ap-chongqing',
  709. // 存储桶所在地域,必须字段
  710. Key: that.uploadType + '/' + y + '-' + MM + '-' + d + '/' + str + '-' + timeElse + '.' + arr[arr.length - 1],
  711. StorageClass: 'STANDARD',
  712. Body: file // 上传文件对象
  713. },
  714. function (err, data) {
  715. if (err) {
  716. that.$message.error('上传失败!!!' + err);
  717. return;
  718. }
  719. that.loadingElse = false;
  720. that.fileList.push({
  721. uid: file.name,
  722. name: file.name,
  723. status: 'done',
  724. url: '//' + data.Location
  725. });
  726. if (that.fileList.length > 1) {
  727. that.fileList = that.fileList.slice(-1);
  728. }
  729. const isZip = file.type.includes('zip') || file.type.includes('text');
  730. const fileOvesize = file.size > (1024 * 1024 * 1024);
  731. if (!isZip) {
  732. that.$message.error('只能上传zip格式的文件或者txt文件');
  733. return;
  734. }
  735. if (fileOvesize) {
  736. that.$message.error('文件大小不能超过1G');
  737. return;
  738. }
  739. that.handleMd5(file);
  740. }
  741. );
  742. },
  743. handleQueryList(event) {
  744. event.preventDefault();
  745. const paramsData = this.form.getFieldsValue();
  746. this.handleGetTableList(paramsData);
  747. },
  748. handleResetForm() {
  749. this.form.resetFields();
  750. this.projectId = undefined;
  751. this.handleGetTableList({});
  752. this.$refs.selectTable.keyValue = "";
  753. this.$refs.selectTable.getData()
  754. },
  755. handleUploadPerson() {
  756. this.personVisible = true;
  757. },
  758. handleUpdatePerson() {
  759. if(this.realShow) {
  760. this.realLoading = true;
  761. getAction('/kuaishou/batch/syncUserPopulationList',{ userId:this.userInfo().id, type:0}).then(res => {
  762. if(res.success) {
  763. this.realLoading = false;
  764. this.$message.success('更新成功');
  765. this.handleResetForm();
  766. }
  767. else {
  768. this.realLoading = false;
  769. this.$message.error('更新失败');
  770. }
  771. })
  772. }
  773. },
  774. handleOk() {
  775. this.$refs.ruleForm.validate(valid => {
  776. if (valid) {
  777. if (!this.uploadProjectId) {
  778. this.$message.error('请选择项目');
  779. return;
  780. }
  781. if (!this.fileList.length) {
  782. this.$message.error('请上传文件');
  783. return;
  784. }
  785. this.confirmLoading = true
  786. this.handleUploadRuleForm();
  787. }
  788. else {
  789. return false;
  790. }
  791. });
  792. },
  793. handleUploadRuleForm() {
  794. const paramsData = {
  795. type: this.personForm.resource,
  796. orientationName: this.personForm.name,
  797. projectId: this.uploadProjectId,
  798. url: this.fileList[0].url
  799. };
  800. postAction('/kuaishouPopulationPackage/add', paramsData).then(result => {
  801. this.confirmLoading = false
  802. if (result.code === 200) {
  803. this.personVisible = false;
  804. this.personResourceDisabled = false;
  805. this.personNameDisabled = false;
  806. this.$message.success('上传成功');
  807. this.handleGetTableList({});
  808. this.fileList = [];
  809. this.personForm.name = '';
  810. this.personForm.resource = '';
  811. this.uploadProjectId = undefined;
  812. }
  813. else {
  814. this.$message.error(result.message);
  815. }
  816. }).catch(error => {
  817. console.log(error, 'eeee');
  818. });
  819. },
  820. handleCancel() {
  821. this.confirmLoading = false
  822. this.personVisible = false;
  823. this.personResourceDisabled = false;
  824. this.personNameDisabled = false;
  825. this.$refs.ruleForm.resetFields();
  826. this.uploadProjectId = '';
  827. this.personForm.name = '';
  828. this.personForm.resource = '';
  829. this.fileList = [];
  830. }
  831. }
  832. };
  833. </script>
  834. <style lang="less" scoped>
  835. @import "crowd-control";
  836. </style>