Links.jsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. import React, { Component } from "react";
  2. import {
  3. Table,
  4. Modal,
  5. message,
  6. Spin,
  7. Input,
  8. Select,
  9. Button,
  10. Form,
  11. Upload,
  12. Popconfirm,
  13. AutoComplete,
  14. DatePicker,
  15. Col,
  16. Tabs,
  17. Tag,
  18. Radio,
  19. Group,
  20. InputNumber,
  21. } from "antd";
  22. import SpinContainer from "../../SpinContainer";
  23. import $ from "jquery/src/ajax";
  24. const { TextArea } = Input;
  25. const RadioGroup = Radio.Group;
  26. const Option = AutoComplete.Option;
  27. const confirm = Modal.confirm;
  28. class Links extends Component {
  29. constructor(props) {
  30. super(props);
  31. this.state = {
  32. dataView: null,
  33. PublicView: null,
  34. contentView: "",
  35. remarksView: "",
  36. contentViewLength: 0,
  37. contentViewLength1: 0,
  38. hid: 'none',
  39. pagination: {
  40. defaultCurrent: 1,
  41. defaultPageSize: 10,
  42. showQuickJumper: true,
  43. pageSize: 10,
  44. onChange: function (page) {
  45. this.linkList(page);
  46. this.setState({
  47. selectedRowKeys: [],
  48. });
  49. }.bind(this),
  50. showTotal: function (total) {
  51. return "共" + total + "条数据";
  52. },
  53. },
  54. columns: [
  55. {
  56. title: "序号",
  57. dataIndex: "id",
  58. key: "id",
  59. width: "80px",
  60. },
  61. {
  62. title: "排序",
  63. dataIndex: "sort",
  64. key: "sort",
  65. width: "80px",
  66. },
  67. {
  68. title: "友情链接地址",
  69. dataIndex: "url",
  70. key: "url",
  71. width: "100",
  72. },
  73. {
  74. title: "显示名称",
  75. dataIndex: "name",
  76. key: "name",
  77. width: "100",
  78. },
  79. {
  80. title: "互链",
  81. dataIndex: "mutualChain",
  82. key: "mutualChain",
  83. width: "100",
  84. render: (text, record) => {
  85. return <div>{text == 0 ? "否" : "是"}</div>;
  86. },
  87. },
  88. {
  89. title: "备注",
  90. dataIndex: "remarks",
  91. key: "remarks",
  92. width: "100",
  93. },
  94. {
  95. title: "状态",
  96. dataIndex: "status",
  97. key: "status",
  98. width: "100",
  99. render: (text, record) => {
  100. return <div>{text == 0 ? "正常" : "冻结"}</div>;
  101. },
  102. },
  103. {
  104. title: "操作",
  105. dataIndex: "cz",
  106. key: "cz",
  107. width: "100px",
  108. render: (text, record) => {
  109. return (
  110. <div>
  111. <Popconfirm
  112. title={record.status == 0 ? "确认冻结?" : "确认恢复?"}
  113. onConfirm={() => this.linksUpdate(record)}
  114. okText="确定"
  115. cancelText="取消"
  116. >
  117. <Button
  118. style={{ background: record.status ? '#009966' : '' }}
  119. type={record.status == 0 ? 'primary' : 'primary'}
  120. onClick={(e) => {
  121. e.stopPropagation();
  122. // this.setState({
  123. // addFlag: false,
  124. // });
  125. }}
  126. >
  127. {record.status == 0 ? "冻结" : "恢复"}
  128. </Button>
  129. </Popconfirm>
  130. </div>
  131. );
  132. },
  133. },
  134. ],
  135. dataSourceView: [],
  136. coorVisible: "none",
  137. list: [],
  138. visible: false,
  139. viewKey: 0,
  140. modalView: false,
  141. modalRecord: false,
  142. closable: false,
  143. disabledView: "none",
  144. loading: false,
  145. };
  146. this.formRef = {};
  147. this.submitOrder = this.submitOrder.bind(this);
  148. this.linkList = this.linkList.bind(this);
  149. this.linksUpdate = this.linksUpdate.bind(this);
  150. this.reset = this.reset.bind(this);
  151. this.tableRowClick = this.tableRowClick.bind(this)
  152. this.cleanAllLinks = this.cleanAllLinks.bind(this)
  153. }
  154. componentDidMount() {
  155. this.linkList(1);
  156. }
  157. // 清除缓存
  158. cleanAllLinks() {
  159. $.ajax({
  160. method: "get",
  161. dataType: "json",
  162. crossDomain: false,
  163. url: globalConfig.context + "/api/admin/links/cleanAllLinks",
  164. success: function (data) {
  165. if (data.error.length) {
  166. this.setState({
  167. loading: false,
  168. });
  169. message.warning(data.error[0].message);
  170. } else {
  171. message.success("清除成功");
  172. }
  173. }.bind(this),
  174. }).always(
  175. function () {
  176. this.setState({
  177. loading: false,
  178. });
  179. }.bind(this)
  180. );
  181. }
  182. // 修改链接状态
  183. linksUpdate(record) {
  184. if (!this.state.sort && !record.sort) {
  185. message.warning("请填写排序");
  186. return;
  187. } else if (!this.state.url && !record.url) {
  188. message.warning("请填写友情链接");
  189. return;
  190. } else if (!this.state.name && !record.name) {
  191. message.warning("请输入链接名");
  192. return;
  193. }
  194. this.setState({
  195. loading: true,
  196. });
  197. $.ajax({
  198. method: "post",
  199. dataType: "json",
  200. crossDomain: false,
  201. url: globalConfig.context + "/api/admin/links/update",
  202. data: {
  203. sort: record.sort || this.state.sort,
  204. status: record.status == 0 ? '1' : '0' || this.state.status,
  205. mutualChain: record.mutualChain || this.state.mutualChain,
  206. name: record.name || this.state.name,
  207. url: record.url || this.state.url,
  208. remarks: record.remarks || this.state.remarks,
  209. id: record.id || this.state.id,
  210. },
  211. success: function (data) {
  212. this.setState({
  213. loading: false,
  214. });
  215. if (data.error.length) {
  216. message.warning(data.error[0].message);
  217. } else {
  218. this.setState({
  219. visible: false,
  220. hid: 'none'
  221. })
  222. this.linkList(1);
  223. message.success("修改成功");
  224. }
  225. }.bind(this),
  226. }).always(
  227. function () {
  228. this.setState({
  229. loading: false,
  230. });
  231. }.bind(this)
  232. );
  233. }
  234. reset() {
  235. this.setState({
  236. sortType1: undefined,
  237. name1: undefined,
  238. mutualChain1: undefined,
  239. status1: undefined,
  240. }, () => {
  241. this.linkList();
  242. });
  243. }
  244. // 新增友情链接
  245. submitOrder() {
  246. if (!this.state.sort) {
  247. message.warning("请填写排序");
  248. return;
  249. } else if (!this.state.url) {
  250. message.warning("请填写友情链接");
  251. return;
  252. } else if (!this.state.name) {
  253. message.warning("请输入链接名");
  254. return;
  255. }
  256. this.setState({
  257. loading: true,
  258. });
  259. $.ajax({
  260. method: "post",
  261. dataType: "json",
  262. crossDomain: false,
  263. url: globalConfig.context + "/api/admin/links/add",
  264. data: {
  265. sort: this.state.sort,
  266. status: 0,
  267. mutualChain: this.state.mutualChain || 0,
  268. name: this.state.name,
  269. url: this.state.url,
  270. remarks: this.state.remarks,
  271. },
  272. success: function (data) {
  273. if (data.error.length) {
  274. this.setState({
  275. loading: false,
  276. });
  277. message.warning(data.error[0].message);
  278. } else {
  279. this.setState({
  280. loading: false,
  281. visible: false,
  282. viewKey: this.state.viewKey + 1,
  283. sort: "",
  284. mutualChain: "",
  285. name: "",
  286. url: "",
  287. remarks: "",
  288. });
  289. this.linkList(1);
  290. // this.assistList();
  291. message.success("添加成功");
  292. }
  293. }.bind(this),
  294. }).always(
  295. function () {
  296. this.setState({
  297. loading: false,
  298. });
  299. }.bind(this)
  300. );
  301. }
  302. linkList(page) {
  303. $.ajax({
  304. method: "get",
  305. dataType: "json",
  306. crossDomain: false,
  307. url: globalConfig.context + "/api/admin/links/list",
  308. data: {
  309. sortType: this.state.sortType1 || undefined,
  310. name: this.state.name1 || undefined,
  311. mutualChain: this.state.mutualChain1 || undefined,
  312. status: this.state.status1 || undefined,
  313. pageNo: page || 1,
  314. pageSize: 10,
  315. },
  316. success: function (data) {
  317. if (data.error.length) {
  318. this.setState({
  319. loading: false,
  320. });
  321. message.warning(data.error[0].message);
  322. } else {
  323. this.setState({
  324. list: data.data.list,
  325. pagination: this.state.pagination
  326. });
  327. this.state.pagination.total = data.data.totalCount;
  328. this.state.pagination.current = data.data.pageNo;
  329. }
  330. if (data.data && data.data.list && !data.data.list.length) {
  331. this.state.pagination.total = 0;
  332. }
  333. }.bind(this),
  334. }).always(
  335. function () {
  336. this.setState({
  337. loading: false,
  338. });
  339. }.bind(this)
  340. );
  341. }
  342. // 双击表格弹出修改
  343. tableRowClick(record) {
  344. this.setState({
  345. visible: true,
  346. sort: record.sort,
  347. status: record.status,
  348. mutualChain: record.mutualChain,
  349. name: record.name,
  350. url: record.url,
  351. remarks: record.remarks,
  352. id: record.id,
  353. hid: 'block'
  354. })
  355. }
  356. render() {
  357. const formItemLayout = {
  358. labelCol: { span: 8 },
  359. wrapperCol: { span: 14 },
  360. };
  361. return (
  362. <div>
  363. <div className="user-content">
  364. <div className="content-title">
  365. <span>产品管理</span>
  366. </div>
  367. <div className="user-search">
  368. <Select
  369. placeholder="排序从高到低"
  370. style={{ width: 150 }}
  371. value={this.state.sortType1}
  372. onChange={(e) => {
  373. this.setState({
  374. sortType1: e,
  375. });
  376. }}
  377. >
  378. <Option value="0">排序从高到低</Option>
  379. <Option value="1">排序从低到高</Option>
  380. </Select>
  381. {/* 显示名称关键字 */}
  382. <Input
  383. style={{ bottom: '6px' }}
  384. placeholder="请输入显示名称关键字"
  385. value={this.state.name1}
  386. onChange={(e) => {
  387. this.setState({ name1: e.target.value });
  388. }}
  389. />
  390. {/* 互链 */}
  391. <Select
  392. placeholder="互链"
  393. style={{ width: 150 }}
  394. value={this.state.mutualChain1}
  395. onChange={(e) => {
  396. this.setState({
  397. mutualChain1: e,
  398. });
  399. }}
  400. >
  401. <Option value="1">是,以互链</Option>
  402. <Option value="0">否,没互链</Option>
  403. </Select>
  404. {/* */}
  405. <Select
  406. placeholder="状态"
  407. style={{ width: 150 }}
  408. value={this.state.status1}
  409. onChange={(e) => {
  410. this.setState({
  411. status1: e,
  412. });
  413. }}
  414. >
  415. <Option value="0">正常</Option>
  416. <Option value="1">冻结</Option>
  417. </Select>
  418. <Button
  419. type="primary"
  420. onClick={() => this.linkList(1)}
  421. style={{ marginLeft: "10px" }}
  422. >
  423. 搜索
  424. </Button>
  425. <Button onClick={this.reset}>重置</Button>
  426. <Button
  427. type="primary"
  428. onClick={() => {
  429. this.setState({
  430. visible: true,
  431. sort: "",
  432. mutualChain: "",
  433. name: "",
  434. url: "",
  435. remarks: "",
  436. hid: "none"
  437. });
  438. }}
  439. style={{ marginLeft: "100px" }}
  440. >
  441. 新增链接
  442. </Button>
  443. <Button
  444. type="primary"
  445. onClick={() => this.cleanAllLinks()}
  446. style={{ float: "right" }}
  447. >
  448. 清除友情链接缓存
  449. </Button>
  450. </div>
  451. <div className="patent-table">
  452. <SpinContainer spinning={this.state.loading}>
  453. <Table
  454. columns={this.state.columns}
  455. dataSource={this.state.list}
  456. pagination={this.state.pagination}
  457. onRowClick={this.tableRowClick}
  458. />
  459. </SpinContainer>
  460. </div>
  461. <Modal
  462. width={'600px'}
  463. visible={this.state.visible}
  464. key={this.state.viewKey}
  465. title="新增/编辑友情链接"
  466. onCancel={() => {
  467. this.setState({
  468. visible: false,
  469. viewKey: this.state.viewKey + 1,
  470. });
  471. }}
  472. onOk={() => { }}
  473. footer={false}
  474. >
  475. <Form
  476. onSubmit={this.handleSubmit}
  477. ref={this.formRef}
  478. style={{ marginRight: "120px" }}
  479. >
  480. <Form.Item
  481. {...formItemLayout}
  482. label="排序"
  483. name="sort"
  484. hasFeedback
  485. >
  486. <InputNumber
  487. min={1}
  488. value={this.state.sort}
  489. onChange={(e) => {
  490. if (isNaN(e)) {
  491. message.info("请输入数字")
  492. }
  493. this.setState({ sort: e });
  494. }}
  495. />
  496. <span style={{ color: "red" }}>数字越大排序越前</span>
  497. </Form.Item>
  498. <Form.Item
  499. {...formItemLayout}
  500. label="友链地址"
  501. name="url"
  502. hasFeedback
  503. >
  504. <Input
  505. style={{ width: "140px" }}
  506. value={this.state.url}
  507. placeholder="请输入http://地址"
  508. onChange={(e) => {
  509. this.setState({ url: e.target.value });
  510. }}
  511. />
  512. <span style={{ color: "red", marginLeft: '10px' }}>请输入http://地址</span>
  513. </Form.Item>
  514. <Form.Item
  515. {...formItemLayout}
  516. label="显示名称"
  517. name="name"
  518. hasFeedback
  519. >
  520. <Input
  521. value={this.state.name}
  522. placeholder="请输入显示在页面的网站名称"
  523. onChange={(e) => {
  524. this.setState({ name: e.target.value });
  525. }}
  526. />
  527. </Form.Item>
  528. <Form.Item
  529. {...formItemLayout}
  530. label="是否互链"
  531. name="mutualChain"
  532. hasFeedback
  533. >
  534. <RadioGroup
  535. onChange={(e) => {
  536. this.setState({
  537. mutualChain: e.target.value,
  538. });
  539. }}
  540. value={this.state.mutualChain || 0}
  541. >
  542. <Radio value={0}>否</Radio>
  543. <Radio value={1}>是</Radio>
  544. </RadioGroup>
  545. </Form.Item>
  546. <Form.Item
  547. {...formItemLayout}
  548. label="备注"
  549. name="remarks"
  550. hasFeedback
  551. >
  552. <TextArea
  553. value={this.state.remarks}
  554. maxLength={500}
  555. placeholder="请输入备注..."
  556. rows={4}
  557. onChange={(e) => {
  558. this.setState({
  559. remarks: e.target.value,
  560. });
  561. }}
  562. />
  563. </Form.Item>
  564. </Form>
  565. <div
  566. style={{
  567. display: "flex",
  568. justifyContent: "center",
  569. }}
  570. >
  571. <Button
  572. style={{ display: this.state.hid == 'none' ? 'block' : 'none' }}
  573. onClick={this.submitOrder}
  574. type="primary"
  575. loading={this.state.loading}
  576. >
  577. 提交
  578. </Button>
  579. <Button
  580. style={{ display: this.state.hid }}
  581. onClick={this.linksUpdate}
  582. type="primary"
  583. loading={this.state.loading}
  584. >
  585. 完成修改
  586. </Button>
  587. <Button
  588. type="dashed"
  589. style={{ marginLeft: "15px" }}
  590. onClick={() => {
  591. this.setState({
  592. visible: false,
  593. viewKey: this.state.viewKey + 1,
  594. sort: "",
  595. mutualChain: "",
  596. name: "",
  597. url: "",
  598. remarks: "",
  599. });
  600. }}
  601. >
  602. 取消
  603. </Button>
  604. </div>
  605. </Modal>
  606. </div>
  607. </div>
  608. );
  609. }
  610. }
  611. export default Links;