topTab.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import React from 'react';
  2. import { Row, Col, Modal, Form, Input, Spin, message } from "antd";
  3. import './topTab.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. const TopTab = React.createClass({
  7. getInitialState() {
  8. return {
  9. username: 'admin',
  10. loading: false
  11. };
  12. },
  13. logOut() {
  14. $.ajax({
  15. method: "get",
  16. dataType: "json",
  17. url: globalConfig.context + "/login",
  18. }).done(function (data) {
  19. window.location.href = globalConfig.context + "/admin/login"
  20. });
  21. },
  22. onCancel() {
  23. this.setState({
  24. visible: false,
  25. password: undefined,
  26. usedPwd: undefined
  27. })
  28. },
  29. changePwd() {
  30. this.setState({
  31. loading: true
  32. })
  33. $.ajax({
  34. method: "post",
  35. dataType: "json",
  36. url: globalConfig.context + "/api/admin/updateAdmin",
  37. data: {
  38. password: this.state.password,
  39. usedPwd: this.state.usedPwd,
  40. },
  41. success: function(data) {
  42. if(data.error && data.error.length) {
  43. message.warning(data.error[0].message)
  44. }else {
  45. message.success("修改密码成功!")
  46. this.onCancel()
  47. }
  48. }.bind(this)
  49. }).always(
  50. function() {
  51. this.setState({
  52. loading: false
  53. });
  54. }.bind(this)
  55. );
  56. },
  57. componentWillMount () {
  58. this.loadData();
  59. },
  60. loadData() {
  61. // this.setState({
  62. // loading: true
  63. // });
  64. // $.ajax({
  65. // method: "get",
  66. // dataType: "json",
  67. // crossDomain: false,
  68. // url: globalConfig.context + "/api/admin/notice/unreadCount",
  69. // success: function (data) {
  70. // if (!data.data) {
  71. // if (data.error[0] && data.error[0]) {
  72. // message.warning(data.error[0].message);
  73. // return;
  74. // };
  75. // };
  76. // this.setState({
  77. // badge: data.data,
  78. // });
  79. // }.bind(this),
  80. // }).always(function (data) {
  81. // this.setState({
  82. // loading: false
  83. // });
  84. // }.bind(this));
  85. },
  86. render() {
  87. const FormItem = Form.Item;
  88. return (
  89. <div className="account-top">
  90. <div className="acc-top-user">
  91. <span className="acc-top-user-name">
  92. <a
  93. onClick={e => {
  94. e.stopPropagation();
  95. this.setState({ visible: true });
  96. }}
  97. >
  98. 欢迎您,{" "}
  99. {this.state.username || adminData.name || adminData.mobile}
  100. </a>{" "}
  101. <a onClick={this.logOut}>[ 退出 ]</a>
  102. </span>
  103. <span className="acc-top-title">科德官网内容管理</span>
  104. <span className="acc-top-user-toindex">
  105. <a href={globalConfig.context + "/portal/index.html"}>
  106. 返回首页
  107. </a>
  108. </span>
  109. </div>
  110. <Modal
  111. className="customeDetails"
  112. title="修改密码"
  113. visible={this.state.visible}
  114. onOk={this.changePwd}
  115. width={"330px"}
  116. onCancel={this.onCancel}
  117. >
  118. <Form
  119. layout="horizontal"
  120. onSubmit={this.edithandleSubmit}
  121. id="demand-form"
  122. >
  123. <Spin spinning={this.state.loading}>
  124. <div className="clearfix">
  125. <FormItem
  126. className="half-item"
  127. labelCol={{ span: 8 }}
  128. wrapperCol={{ span: 12 }}
  129. label="账号"
  130. >
  131. <Input
  132. placeholder="请输入账号"
  133. value={window.adminData.account}
  134. disabled
  135. style={{ width: "150px" }}
  136. />
  137. </FormItem>
  138. </div>
  139. <div className="clearfix">
  140. <FormItem
  141. className="half-item"
  142. labelCol={{ span: 8 }}
  143. wrapperCol={{ span: 12 }}
  144. label="原密码"
  145. >
  146. <Input
  147. placeholder="请输入原密码"
  148. value={this.state.usedPwd}
  149. onChange={e => {
  150. this.setState({ usedPwd: e.target.value });
  151. }}
  152. style={{ width: "150px" }}
  153. />
  154. </FormItem>
  155. </div>
  156. <div className="clearfix">
  157. <FormItem
  158. className="half-item"
  159. labelCol={{ span: 8 }}
  160. wrapperCol={{ span: 12 }}
  161. label="新密码"
  162. >
  163. <Input
  164. placeholder="请输入新密码"
  165. value={this.state.password}
  166. onChange={e => {
  167. this.setState({ password: e.target.value });
  168. }}
  169. style={{ width: "150px" }}
  170. />
  171. </FormItem>
  172. </div>
  173. </Spin>
  174. </Form>
  175. </Modal>
  176. </div>
  177. );
  178. }
  179. });
  180. export default TopTab;