فهرست منبع

add admin and add change user telephone

Csy817 6 سال پیش
والد
کامیت
961c3b6de1

+ 2 - 2
src/App.js

@@ -88,7 +88,7 @@ class App extends Component {
         // console.log('isWechatLogin',isWechatLogin)
         if (isWechatLogin) {
             // setCookie("openid","o2fcFv6Rh2-4rCh3d5_1uCWCT5Yc")
-            setCookie("openid","o2fcFv8x3wy5WtcP116S5GzzkgDQ")
+            // setCookie("openid","o2fcFv8x3wy5WtcP116S5GzzkgDQ")
             let openid = getCookie("openid")
             let user_id = getCookie("user_id")
             console.log('oauthLogin openid', openid)
@@ -225,4 +225,4 @@ const MyUnselectedIcon = () => (
 
 const MySelectedIcon = () => (
     <Icon type="setting" theme="twoTone" style={{fontSize: 22}}/>
-)
+)

+ 2 - 2
src/components/logo/index.css

@@ -1,8 +1,8 @@
 .footer-logo {
     height: 50px;
-    background-color: white;
+    /*background-color: white;*/
     text-align: center;
     line-height: 50px;
     font-size: 16px;
     color: #b9b9b9;
-}
+}

+ 226 - 177
src/pages/my/all/index.js

@@ -1,219 +1,268 @@
 import React, {Component} from 'react'
 import './index.css'
-import {Grid, ActivityIndicator} from 'antd-mobile'
+import {message} from 'antd'
+import {Grid, ActivityIndicator,Modal} from 'antd-mobile'
 import {withRouter} from 'react-router-dom'
 import Logo from '../../../components/logo'
-import {getCookie} from "../../../utils/cookie"
-import {user_by_id} from "../../../utils/gql"
+import {getCookie, setCookie} from "../../../utils/cookie"
+import {user_by_id, admin_by_id} from "../../../utils/gql"
 import {Query} from "react-apollo"
 import gql from "graphql-tag"
 
+const prompt = Modal.prompt;
+
 const orderIcon = [
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/pay.png',
-        text: '待付款',
-        id: 'pay'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/ship.png',
-        text: '待发货',
-        id: 'ship'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/unbox.png',
-        text: '待收货',
-        id: 'unbox'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/judge.png',
-        text: '已完成',
-        id: 'judge'
-    }
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/pay.png',
+    text: '待付款',
+    id: 'pay'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/ship.png',
+    text: '待发货',
+    id: 'ship'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/unbox.png',
+    text: '待收货',
+    id: 'unbox'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/judge.png',
+    text: '已完成',
+    id: 'judge'
+  }
 ]
 
 const toolsIcon = [
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/address.png',
-        text: '收货地址',
-        id: 'address'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/cart.png',
-        text: '购物袋',
-        id: 'cart'
-    },
-    // {
-    //     icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/message.png',
-    //     text: '系统通知',
-    //     id: 'message'
-    // }
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/address.png',
+    text: '收货地址',
+    id: 'address'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/cart.png',
+    text: '购物袋',
+    id: 'cart'
+  },
+  // {
+  //     icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/message.png',
+  //     text: '系统通知',
+  //     id: 'message'
+  // }
 ]
 
 const memberIcon = [
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/card.png',
-        text: '会员卡',
-        id: 'card'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/coupon.png',
-        text: '优惠券',
-        id: 'coupon'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/credit.png',
-        text: '积分',
-        id: 'credit'
-    }
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/card.png',
+    text: '会员卡',
+    id: 'card'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/coupon.png',
+    text: '优惠券',
+    id: 'coupon'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/credit.png',
+    text: '积分',
+    id: 'credit'
+  }
 ]
 
 const shopIcon = [
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/shop.png',
-        text: '店铺展示',
-        id: 'shop'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/goods.png',
-        text: '商品管理',
-        id: 'goods'
-    },
-    {
-        icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/order.png',
-        text: '订单管理',
-        id: 'orders'
-    }
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/shop.png',
+    text: '店铺展示',
+    id: 'shop'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/goods.png',
+    text: '商品管理',
+    id: 'goods'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/order.png',
+    text: '订单管理',
+    id: 'orders'
+  },
+  {
+    icon: 'https://ece-img-1254337200.cos.ap-chengdu.myqcloud.com/icon/settings.png',
+    text: '管理员',
+    id: 'admin'
+  }
 ]
 
 class All extends Component {
-    constructor(props) {
-        super(props)
-        this.state = {}
+  constructor(props) {
+    super(props)
+    this.state = {
+      showAdmin: !!getCookie('showAdmin') || false
     }
+  }
 
-    render() {
-        let user_id = getCookie('user_id')
-        // console.log(user_id)
-        return (
-            <div className='my-wrap all'>
-                <Query query={gql(user_by_id)} variables={{id: user_id}}>
-                    {
-                        ({loading, error, data}) => {
-                            if (loading) {
-                                return (
-                                    <div className="loading-center">
-                                        <ActivityIndicator text="加载中..." size="large"/>
-                                    </div>
-                                )
-                            }
-                            if (error) {
-                                return 'error!'
-                            }
-                            data = data.userbyid
-                            return (
-                                <div className='avatar-area' onClick={()=>{
-                                    this.props.history.push({
-                                        pathname: `/my/profile`,
-                                        state: {}
-                                    })
-                                }}>
-                                    <div className='avatar'/>
-                                    <div className='nickname'>{data.username}</div>
-                                </div>
-                            )
-                        }
-                    }
-                </Query>
+  render() {
+    let {showAdmin} = this.state
+    let user_id = getCookie('user_id')
+    // console.log("user_id", user_id)
+    return (
+      <div className='my-wrap all'>
+        <Query query={gql(user_by_id)} variables={{id: user_id}}>
+          {
+            ({loading, error, data}) => {
+              if (loading) {
+                return (
+                  <div className="loading-center">
+                    <ActivityIndicator text="加载中..." size="large"/>
+                  </div>
+                )
+              }
+              if (error) {
+                return 'error!'
+              }
+              const userData = data.userbyid
+              return (
+                <div>
+                  <div className='avatar-area' onClick={()=>{
+                    this.props.history.push({
+                      pathname: `/my/profile`,
+                      state: {}
+                    })
+                  }}>
+                    <div className='avatar'/>
+                    <div className='nickname'>{userData.username}</div>
+                  </div>
 
-                <div className='my-card order-card'>
+                  <div className='my-card order-card'>
                     <div className='card-title'>
-                        电商订单
+                      电商订单
                     </div>
                     <div className='card-icons'>
-                        <Grid data={orderIcon}
-                              columnNum={4}
-                              hasLine={false}
-                              onClick={(order) => {
-                                  this.props.history.push({
-                                      pathname: '/my/order',
-                                      state: {
-                                          kind: order.id
-                                      }
-                                  })
-                              }}
-                        />
+                      <Grid data={orderIcon}
+                            columnNum={4}
+                            hasLine={false}
+                            onClick={(order) => {
+                              this.props.history.push({
+                                pathname: '/my/order',
+                                state: {
+                                  kind: order.id
+                                }
+                              })
+                            }}
+                      />
                     </div>
-                </div>
+                  </div>
 
-                <div className='my-card tools-card'>
+                  <div className='my-card tools-card'>
                     <div className='card-title'>
-                        我的工具
+                      我的工具
                     </div>
                     <div className='card-icons'>
-                        <Grid data={toolsIcon}
-                              columnNum={4}
-                              hasLine={false}
-                              onClick={(tools) => {
-                                  if (tools.id === 'cart') {
-                                      this.props.history.push({
-                                          pathname: '/cart'
-                                      })
-                                  } else {
-                                      this.props.history.push({
-                                          pathname: '/my/tools',
-                                          state: {
-                                              page: tools.id
-                                          }
-                                      })
+                      <Grid data={toolsIcon}
+                            columnNum={4}
+                            hasLine={false}
+                            onClick={(tools) => {
+                              if (tools.id === 'cart') {
+                                this.props.history.push({
+                                  pathname: '/cart'
+                                })
+                              } else {
+                                this.props.history.push({
+                                  pathname: '/my/tools',
+                                  state: {
+                                    page: tools.id
                                   }
-                              }}
-                        />
+                                })
+                              }
+                            }}
+                      />
                     </div>
-                </div>
+                  </div>
 
-                <div className='my-card member-card' style={{display: 'none'}}>
+                  <div className='my-card member-card' style={{display: 'none'}}>
                     <div className='card-title'>
-                        会员中心
+                      会员中心
                     </div>
                     <div className='card-icons'>
-                        <Grid data={memberIcon}
-                              columnNum={4}
-                              hasLine={false}
-                              onClick={(member) => {
-                                  this.props.history.push({
-                                      pathname: '/my/member',
-                                      state: {
-                                          page: member.id
-                                      }
-                                  })
-                              }}
-                        />
+                      <Grid data={memberIcon}
+                            columnNum={4}
+                            hasLine={false}
+                            onClick={(member) => {
+                              this.props.history.push({
+                                pathname: '/my/member',
+                                state: {
+                                  page: member.id
+                                }
+                              })
+                            }}
+                      />
                     </div>
-                </div>
+                  </div>
 
-                <div className='my-card member-card'>
-                    <div className='card-title'>
-                        商家入口
-                    </div>
-                    <div className='card-icons'>
-                        <Grid data={shopIcon}
-                              columnNum={4}
-                              hasLine={false}
-                              onClick={(shop) => {
-                                  this.props.history.push({
-                                      pathname: '/my/manage',
-                                      state: {
-                                          page: shop.id
-                                      }
-                                  })
-                              }}
-                        />
-                    </div>
+                  <Query query={gql(admin_by_id)} variables={{id: userData.telephone}}>
+                    {
+                      ({data}) => {
+                        const adminData = data.adminbyid
+                        // console.log("admin_by_id adminData",adminData, !!adminData)
+                        if(!!adminData) {
+                          return (
+                            <div className='my-card member-card'>
+                              <div className='card-title'
+                                   onClick={() => prompt(
+                                     '管理员登陆',
+                                     '请输入账户名及密码',
+                                     (login, password) => {
+                                       const {username, password:userPassWord} = adminData
+                                       console.log(`login: ${login}, password: ${password}`)
+                                       if(login === username && password === userPassWord) {
+                                         this.setState({showAdmin:true})
+                                         setCookie('showAdmin',true)
+                                       }else {
+                                         message.error('账户或密码有误')
+                                       }
+                                     },
+                                     'login-password',
+                                     null,
+                                     ['请输入管理员账号', '请输入管理员密码'],
+                                   )}
+                              >
+                                商家入口
+                              </div>
+                              {
+                                showAdmin ?
+                                  <div className='card-icons'>
+                                    <Grid
+                                      data={shopIcon}
+                                      columnNum={4}
+                                      hasLine={false}
+                                      onClick={(shop) => {
+                                        this.props.history.push({
+                                          pathname: '/my/manage',
+                                          state: {
+                                            page: shop.id
+                                          }
+                                        })
+                                      }}
+                                    />
+                                  </div>:''
+                              }
+                            </div>
+                          )
+                        }else {
+                          return null
+                        }
+                      }
+                    }
+                  </Query>
                 </div>
-                <Logo/>
-            </div>
-        )
-    }
+              )
+            }
+          }
+        </Query>
+        <Logo/>
+      </div>
+    )
+  }
 }
 
-export default withRouter(All)
+export default withRouter(All)

+ 55 - 0
src/pages/my/manage/admin/index.css

@@ -0,0 +1,55 @@
+.admin-card {
+    background-color: white;
+    padding: 10px;
+    font-size: 16px;
+    color: black;
+    display: flex;
+    border: 1px solid #F3F3F3;
+    justify-content: space-between;
+    align-items: center;
+}
+
+.admin-add {
+    position: fixed;
+    bottom: 0;
+    width: 100%;
+    text-align: center;
+    font-size: 16px;
+    border-top: 1px solid #F3F3F3;
+    height: 50px;
+    line-height: 50px;
+    box-shadow: 3px -1px 1px #ebedf0;
+    background-color: #f44;
+    color: white;
+}
+
+.admin-info{
+    width: 85%;
+}
+
+.admin-edit {
+    width: 15%;
+    text-align: center;
+}
+
+.admin-username {
+    font-weight: 500;
+}
+
+.ellipsis {
+    overflow: hidden;
+    text-overflow: ellipsis;
+    white-space: nowrap
+}
+
+.admin-admin {
+    font-size: 14px;
+}
+
+.admin-label {
+    font-size: 12px;
+    padding: 0 10px;
+    background-color: #ff6d6d;
+    color: white;
+    border-radius: 10px;
+}

+ 214 - 0
src/pages/my/manage/admin/index.js

@@ -0,0 +1,214 @@
+import {Component} from "react"
+import React from "react"
+import {ActivityIndicator, NavBar, Modal} from 'antd-mobile'
+import {Icon, Row, Col, message} from 'antd'
+import {Query, Mutation} from "react-apollo"
+import gql from "graphql-tag"
+
+import SingleAdmin from "./singleadmin"
+import {getCookie} from "../../../../utils/cookie"
+import {all_admin, delete_admin} from "../../../../utils/gql"
+import './index.css'
+const alert = Modal.alert
+
+class Admin extends Component {
+  constructor(props) {
+    super(props)
+    this.state = {
+      single: false,
+      adminID: '',
+      adminChoosed: {}
+    }
+  }
+
+  componentWillMount() {
+    let state = this.props.history.location.state || ''
+    if (state && state.single) {
+      this.setState({
+        single: true,
+        adminID: 'add'
+      })
+    }
+  }
+
+  changePage = (bool) => {
+    this.setState({
+      single: bool
+    })
+  }
+
+  changeAdmin = (admin) => {
+    this.setState({
+      adminID: admin.id,
+      adminChoosed: admin
+    })
+  }
+
+  render() {
+    let {adminChoosed, adminID, single} = this.state
+    let user_id = getCookie('user_id')
+    let navContent = single ? '编辑管理员' : '管理员'
+
+    return (
+      <div>
+        <div className='navbar'>
+          <NavBar
+            mode="light"
+            icon={<Icon type="left"/>}
+            onLeftClick={() => {
+              if(single){
+                this.changePage(false)
+              }else {
+                this.props.history.go(-1)
+              }
+            }}
+          >{navContent}</NavBar>
+        </div>
+        <div className='content-wrap'>
+          <Query query={gql(all_admin)}>
+            {
+              ({loading, error, data, refetch}) => {
+                if (loading) {
+                  return (
+                    <div className="loading-center">
+                      <ActivityIndicator text="加载中..." size="large"/>
+                    </div>
+                  )
+                }
+                if (error) {
+                  return 'error!'
+                }
+
+                data = data.alladmin
+                // console.log('admin data',data)
+
+                return (
+                  <div>
+                    {
+                      this.state.single ?
+                        <SingleAdmin
+                          adminID={adminID}
+                          adminChoosed={adminChoosed}
+                          history={this.props.history}
+                          user_id={user_id}
+                          changePage={this.changePage}
+                          refetch={refetch}
+                        />
+                        :
+                        <AdminRender
+                          oneAdmin={data}
+                          changePage={this.changePage}
+                          changeAdmin={this.changeAdmin}
+                          history={this.props.history}
+                          refetch={refetch}
+                        />
+                    }
+                  </div>
+                )
+              }
+            }
+          </Query>
+        </div>
+      </div>
+    )
+  }
+}
+
+export default Admin
+
+class AdminRender extends Component {
+  constructor(props) {
+    super(props)
+    this.state = {}
+  }
+
+  changeOrdersAdmin =() => {
+    // console.log('admin',admin,this.props.history)
+    this.props.history.go(-1)
+  }
+
+  deleteAdmin = (delete_admin, deleteId) => {
+    alert('', `确定要删除此管理员吗?`, [
+      { text: '取消', onPress: () => console.log('cancel') },
+      {
+        text: '确定',
+        onPress: () => {
+          delete_admin({variables:{id:deleteId}}).then((data)=>{
+            // console.log('delete data',data)
+            // let num = data.data.deleteuserAdmin.replace(/[^0-9]/ig,"")
+            const result = data.data.deleteadmin
+            if(result === 'ok'){
+              message.success('删除成功')
+              this.props.refetch()
+            }
+          })
+        }
+      }
+    ])
+  }
+
+  render() {
+    let {changePage, changeAdmin, oneAdmin} = this.props
+
+    return (
+      <div>
+        <div className='admin-add' onClick={() => {
+          changePage(true)
+          changeAdmin({id: 'add'})
+        }}>
+          <Icon type="plus"/>&nbsp;
+          添加新管理员
+        </div>
+        {
+          !oneAdmin.length ?
+            <div className='kind-empty gray'>
+              <p>暂无管理员</p>
+              <p>点击下方按钮可新增管理员</p>
+            </div>:''
+        }
+        {
+          oneAdmin.length ?
+            <div className='other-admin'>
+              {oneAdmin.map(admin => {
+                return (
+                  <div key={admin.id} className='admin-card'>
+                    <div className='admin-info' onClick={() => this.changeOrdersAdmin}>
+                      <Row className='admin-username-telephone'>
+                        <Col span={6} className='admin-username ellipsis'>{admin.username}</Col>
+                        <Col span={18} className='admin-phone ellipsis'>
+                          {admin.telephone}&nbsp;&nbsp;
+                        </Col>
+                      </Row>
+                    </div>
+                    <div className='admin-edit'>
+                      <Icon
+                        type="edit"
+                        onClick={()=>{
+                          changePage(true)
+                          changeAdmin(admin)
+                        }}
+                      />
+                    </div>
+                    <Mutation mutation={gql(delete_admin)}
+                              onError={error=>console.log('error',error)}
+                    >
+                      {(delete_admin,{ loading, error }) => (
+                        <div className='admin-edit'>
+                          <Icon
+                            type="delete"
+                            onClick={()=>{
+                              this.deleteAdmin(delete_admin,admin.id)
+                            }}
+                          />
+                        </div>
+                      )}
+                    </Mutation>
+                  </div>
+                )
+              })}
+            </div>:''
+        }
+      </div>
+    )
+  }
+}

+ 19 - 0
src/pages/my/manage/admin/singleadmin/index.css

@@ -0,0 +1,19 @@
+.admin-button-group {
+    margin-top: 30px;
+}
+
+.admin-button {
+    margin-top: 5px;
+}
+
+.admin-default-checked {
+    background: white;
+    font-size: 16px;
+    padding: 10px 10px 15px 15px;
+    border-top: 1px solid #ebedf0;
+    width: 100%;
+}
+
+.admin-default-checked span:last-child{
+    float: right;
+}

+ 184 - 0
src/pages/my/manage/admin/singleadmin/index.js

@@ -0,0 +1,184 @@
+import React, {Component} from "react"
+import {message} from 'antd'
+import {InputItem} from 'antd-mobile'
+import {Mutation} from "react-apollo"
+import gql from "graphql-tag"
+import moment from 'moment'
+
+import {create_admin, update_admin, all_admin} from "../../../../../utils/gql"
+import './index.css'
+
+class SingleAdmin extends Component {
+  constructor(props) {
+    super(props)
+    let state = {
+      username: '',
+      telephone: '',
+      password: '',
+      confirmPassword: '',
+      oldPassword: '',
+      newPassword:''
+    }
+    if (props.adminID === 'add') {
+      this.state = {...state}
+    } else {
+      // console.log("SingleAdmin props",props)
+      let {telephone='', username, password} = props.adminChoosed
+      this.state = {...state, telephone, username, password}
+    }
+  }
+
+  saveAdmin = (user_id, mutate) => {
+    const {adminID} = this.props
+    const createdAt = moment().format('YYYY-MM-DD HH:mm:ss')
+    let {username, telephone, password, confirmPassword, oldPassword, newPassword} = this.state
+    const testPhoneNum = /^1[0-9]{10}$/;
+    const isPoneAvailable = testPhoneNum.test(telephone);
+    const passwordLength = adminID === 'add' ? confirmPassword.length >= 6 : newPassword.length >= 6;
+    const testAddPassword = password && confirmPassword && password === confirmPassword;
+    const testOldPassword = oldPassword && password === oldPassword;
+    const testUpdatePassword = oldPassword && newPassword && oldPassword !== newPassword;
+    const havePassword = adminID === 'add' ? testAddPassword : testOldPassword && testUpdatePassword
+
+    if(username && havePassword && passwordLength && isPoneAvailable){
+      const updatePassword = adminID === 'add' ? password : newPassword
+
+      const adminContent = {
+        updatedAt: "",
+        telephone,
+        username,
+        createdAt,
+        id: telephone,
+        password: updatePassword,
+      }
+
+      if(adminID === 'add') {
+        adminContent.createdAt = createdAt;
+        adminContent.email = ""
+      }
+
+      mutate({variables:adminContent}).then((data)=>{
+        // console.log("add data",data)
+        this.props.refetch()
+        this.props.changePage(false)
+      })
+
+    }else if(!username){
+      message.warning('账户名称不能为空',1)
+    }else if(!telephone){
+      message.warning('手机号不能为空',1)
+    }else if(!passwordLength){
+      message.warning('登陆密码至少6位',1)
+    }else if(adminID === 'add' && !password){
+      message.warning('登陆密码不能为空',1)
+    }else if(adminID === 'add' && !confirmPassword){
+      message.warning('请再次输入登陆密码确认',1)
+    }else if(adminID !== 'add' && !oldPassword){
+      message.warning('旧密码不能为空',1)
+    }else if(adminID !== 'add' && !newPassword){
+      message.warning('新密码不能为空',1)
+    }else if(password && confirmPassword && !testAddPassword){
+      message.warning('两次输入的密码不一致',1)
+    }else if(oldPassword && !testOldPassword){
+      message.warning('旧密码输入有误',1)
+    }else if(oldPassword && newPassword && !testUpdatePassword){
+      message.warning('新密码与旧密码不能相同',1)
+    }else if(telephone && !isPoneAvailable){
+      message.warning('请输入11位有效手机号码',1)
+    }else {
+      message.warning('信息未完善',2)
+    }
+  }
+
+  render() {
+    const {adminID, user_id} = this.props
+    let {username, telephone} = this.state
+
+    return (
+      <div>
+        <div>
+          <InputItem placeholder="请填写账户名称" value={username}
+                     onChange={(username) => {
+                       this.setState({username})
+                     }}
+          >
+            <div>账户名称</div>
+          </InputItem>
+          {
+            adminID === 'add' ?
+              [
+                <InputItem
+                  type="password"
+                  key="password"
+                  placeholder="请输入登陆密码"
+                  onChange={(password) => {
+                    this.setState({password})
+                  }}
+                >
+                  <div>密码</div>
+                </InputItem>,
+                <InputItem
+                  type="password"
+                  key="confirmPassword"
+                  placeholder="请再次输入登陆密码"
+                  onChange={(confirmPassword) => {
+                    this.setState({confirmPassword})
+                  }}
+                >
+                  <div>确认密码</div>
+                </InputItem>
+              ]:[
+                <InputItem
+                  type="password"
+                  key="oldPassword"
+                  placeholder="请输入旧登陆密码"
+                  onChange={(oldPassword) => {
+                    this.setState({oldPassword})
+                  }}
+                >
+                  <div>旧密码</div>
+                </InputItem>,
+                <InputItem
+                  type="password"
+                  key="newPassword"
+                  placeholder="请输入新登陆密码"
+                  onChange={(newPassword) => {
+                    this.setState({newPassword})
+                  }}
+                >
+                  <div>新密码</div>
+                </InputItem>
+              ]
+
+          }
+          <InputItem placeholder="请填写联系电话" value={telephone} onChange={(telephone) => {
+            this.setState({telephone})
+          }}>
+            <div>联系电话</div>
+          </InputItem>
+        </div>
+
+        <div className='admin-button-group'>
+          <Mutation mutation={adminID === 'add' ? gql(create_admin) : gql(update_admin)}
+                    refetchQueries={[
+                      {query: gql(all_admin)}
+                    ]}
+                    onError={error=>console.log('error',error)}
+          >
+            {(mutate,{ loading, error }) => (
+              <div className='admin-add'
+                   onClick={()=>{
+                     this.saveAdmin(user_id, mutate)
+                   }}
+              >
+                保存并使用
+              </div>
+            )}
+          </Mutation>
+        </div>
+      </div>
+    )
+  }
+}
+
+export default SingleAdmin;

+ 3 - 1
src/pages/my/manage/index.js

@@ -2,6 +2,7 @@ import React, {Component} from 'react'
 import Shop from './shop'
 import Goods from './goods'
 import Orders from './orders'
+import Admin from './admin'
 import {withRouter, Route, Switch} from 'react-router-dom'
 
 class Manage extends Component {
@@ -29,6 +30,7 @@ class Manage extends Component {
                     <Route path="/my/manage/shop" component={Shop}/>
                     <Route path="/my/manage/goods" component={Goods}/>
                     <Route path="/my/manage/orders" component={Orders}/>
+                    <Route path="/my/manage/admin" component={Admin}/>
                     <Route path="/my/manage/*" component={Goods}/>
                 </Switch>
             </div>
@@ -36,4 +38,4 @@ class Manage extends Component {
     }
 }
 
-export default withRouter(Manage)
+export default withRouter(Manage)

+ 10 - 2
src/pages/my/manage/shop/index.js

@@ -168,7 +168,8 @@ class ShopRender extends Component {
                         files={files}
                         onChange={this.onChange}
                         onImageClick={(index, fs) => console.log(index, fs)}
-                        selectable={true}
+                        // selectable={true}
+                        selectable={files.length < 7}
                         multiple={true}
                     />
                     <Item>
@@ -339,7 +340,14 @@ class CreateShopButton extends Component {
                                 let slideshow = imgDatas.length === 1 ? prefix + imgDatas[0]['file-name'] : imgDatas.map((imgData, index) => (
                                     prefix + imgDatas[index]['file-name']
                                 ))
-                                createstore({variables: {...varObj, slideshow}})
+                                createstore({variables: {...varObj, slideshow}}).then((data)=>{
+                                  // console.log("createstore data",data)
+                                  if(data.data && data.data.createshop.result === "ok"){
+                                    message.success('创建成功')
+                                  }else {
+                                    message.success('创建失败,请稍后重试')
+                                  }
+                                })
                             })
                         }}>创建</Button>
                     )

+ 103 - 58
src/pages/my/profile/index.js

@@ -1,72 +1,117 @@
 import React, {Component} from 'react'
 import './index.css'
+import {message} from 'antd'
 import {NavBar, Icon, InputItem, List, Button, ActivityIndicator} from 'antd-mobile'
 import {withRouter} from 'react-router-dom'
 import {Mutation} from "react-apollo"
-import {update_user, user_by_id} from "../../../utils/gql"
+import {request} from 'graphql-request'
+import {user_by_id, update_user} from "../../../utils/gql"
 import gql from "graphql-tag"
 import {getCookie} from "../../../utils/cookie"
+import {graphqlFC} from "../../../configs/url"
 
 class Profile extends Component {
-    constructor(props) {
-        super(props)
-        this.state = {
-            username: ''
-        }
+  constructor(props) {
+    super(props)
+    this.state = {
+      username: '',
+      telephone: '',
+      oldTelephone: ''
     }
+  }
 
-    render() {
-        let {username} = this.state
-        let user_id = getCookie('user_id')
-        return (
-            <div>
-                <div className='profile-navbar-wrap'>
-                    <NavBar
-                        className='profile-navbar'
-                        mode="light"
-                        icon={<Icon type="left"/>}
-                        onLeftClick={() => {
-                            this.props.history.push({
-                                pathname: '/my'
-                            })
-                        }}
-                    >我的信息</NavBar>
-                </div>
+  componentDidMount() {
+    let user_id = getCookie('user_id')
+    let _this = this
+    request(graphqlFC, user_by_id, {id: user_id})
+      .then(data => {
+        // console.log('find user data', data)
+        const {username, telephone} = data.userbyid
+        _this.setState({
+          username,
+          telephone,
+          oldTelephone: telephone
+        })
+        }
+      )
+      .catch(err => {
+        console.log(err, `graphql-request find user error`)
+      })
+  }
 
-                <Mutation
-                    mutation={gql(update_user)}
-                    refetchQueries={[{query: gql(user_by_id), variables: {id: user_id}}]}
-                >
-                    {(update_user, {loading, error}) => {
-                        if (loading) {
-                            return (
-                                <div className="loading-center">
-                                    <ActivityIndicator text="加载中..." size="large"/>
-                                </div>
-                            )
-                        }
-                        if (error) {
-                            return 'error!'
-                        }
-                        return (
-                            <div>
-                                <List renderHeader={() => '修改个人信息'} className="my-list">
-                                    <InputItem onChange={(e) => {
-                                        this.setState({username: e})
-                                    }} value={username} placeholder="请输入昵称">昵称</InputItem>
-                                </List>
-                                <Button onClick={() => {
-                                    console.log(username)
-                                    console.log(user_id)
-                                    update_user({variables: {id: user_id, username}})
-                                }}>确认</Button>
-                            </div>
-                        )
-                    }}
-                </Mutation>
-            </div>
-        )
-    }
+  render() {
+    let {username,telephone, oldTelephone} = this.state
+    let user_id = getCookie('user_id')
+    return (
+      <div>
+        <div className='profile-navbar-wrap'>
+          <NavBar
+            className='profile-navbar'
+            mode="light"
+            icon={<Icon type="left"/>}
+            onLeftClick={() => {
+              this.props.history.push({
+                pathname: '/my'
+              })
+            }}
+          >我的信息</NavBar>
+        </div>
+        <Mutation
+          mutation={gql(update_user)}
+          refetchQueries={[{query: gql(user_by_id), variables: {id: user_id}}]}
+        >
+          {(update_user, {loading, error}) => {
+            if (loading) {
+              return (
+                <div className="loading-center">
+                  <ActivityIndicator text="加载中..." size="large"/>
+                </div>
+              )
+            }
+            if (error) {
+              return 'error!'
+            }
+            return (
+              <div>
+                <List renderHeader={() => '修改个人信息'} className="my-list">
+                  <InputItem onChange={(e) => {
+                    this.setState({username: e})
+                  }} value={username} placeholder="请输入昵称">
+                    昵称
+                  </InputItem>
+                  <InputItem placeholder="请填写联系电话" value={telephone} onChange={(telephone) => {
+                    this.setState({telephone})
+                  }}>
+                    <div>联系电话</div>
+                  </InputItem>
+                </List>
+                <Button onClick={() => {
+                  const testPhoneNum = /^1[0-9]{10}$/;
+                  const isPoneAvailable = testPhoneNum.test(telephone);
+                  if(isPoneAvailable && telephone !== oldTelephone){
+                    update_user({variables: {id: user_id, username, telephone}}).then((data)=>{
+                      // console.log("update_user data",data)
+                      if(data.data && data.data.updateuser.result === "ok"){
+                        message.success('更新成功')
+                        this.props.history.go(-1)
+                      }else {
+                        message.success('更新失败,请稍后重试')
+                      }
+                    })
+                  }else if(telephone === oldTelephone){
+                    // console.log("号码未变")
+                    this.props.history.go(-1)
+                  }else {
+                    message.warning('请输入11位有效手机号码',1)
+                  }
+                }}>确认</Button>
+              </div>
+            )
+          }}
+        </Mutation>
+      </div>
+    )
+  }
 }
 
-export default withRouter(Profile)
+export default withRouter(Profile)

+ 3 - 2
src/utils/cookie.js

@@ -2,8 +2,9 @@ export function setCookie(name, value, exdays) {
     // expires表示过期时间。如果不设置,默认会话结束即关闭浏览器的时候就消失。
     // 第一步,设置过期时间
     let date = new Date();
-    date.setDate(date.getDate() + (exdays * 24 * 60 * 60 * 1000));
-    document.cookie = name + "=" + value + ";expires=" + date;
+    date.setTime(date.getTime() + (exdays * 24 * 60 * 60 * 1000));
+    let expires = "expires=" + date.toUTCString();
+    document.cookie = name + "=" + value + ";" + expires;
     // alert(document.cookie);
 }
 

+ 76 - 3
src/utils/gql.js

@@ -24,6 +24,74 @@ const find_user_by_openid = `
     }
 `
 
+const all_admin = `
+    query alladmin {
+        alladmin: admin_by_props {
+            email
+            password
+            telephone
+            username
+            openid
+            id 
+        }
+    }
+`
+
+const admin_by_id = `
+    query adminbyid($id: ID!) {
+        adminbyid: admin_by_id(id: $id) {
+            email
+            password
+            telephone
+            username
+            openid
+            id 
+        }
+    }
+`
+
+const create_admin = `
+    mutation createadmin($id: ID!, $openid: String, $username: String, $password: String, $telephone: String, $email: String, $createdAt: String, $updatedAt: String) {
+        createadmin: create_admin(id: $id openid: $openid username: $username password: $password telephone: $telephone email: $email createdAt: $createdAt updatedAt: $updatedAt) {
+            result
+            admin {
+                id
+                openid
+                username
+                password
+                telephone
+                email
+                createdAt
+                updatedAt
+            }
+        }
+    }
+`
+
+const update_admin = `
+    mutation updateadmin($id: ID!, $email: String, $updatedAt: String, $where: admin_filter, $password: String, $telephone: String, $username: String) {
+        updateadmin: update_admin(id: $id email: $email updatedAt: $updatedAt where: $where password: $password telephone: $telephone username: $username) {
+            result
+            admin {
+                id
+                openid
+                username
+                password
+                telephone
+                email
+                createdAt
+                updatedAt
+            }
+        }
+    }
+`
+
+const delete_admin = `
+    mutation deleteadmin($id: ID) {
+        deleteadmin: delete_admin(id: $id)
+    }
+`
+
 const user_by_id = `
     query userbyid($id: ID) {
         userbyid: user_by_id(id: $id) {
@@ -335,7 +403,7 @@ const delete_userCart_by_id = `
 `
 
 const create_update_userAddress = `
-    mutation createuserAddress( $id: ID!, $address: String, $updatedAt: String, $telephone: String, $default: Int, $city: String, $username: String, $postcode: String, $createdAt: String, $deletedAt: String, $user_id: ID, $area: String, $province: String,
+    mutation createuserAddress($id: ID!, $address: String, $updatedAt: String, $telephone: String, $default: Int, $city: String, $username: String, $postcode: String, $createdAt: String, $deletedAt: String, $user_id: ID, $area: String, $province: String,
                                $updateID: ID!, $updateDefault: Int, $newUpdatedAt: String) {
         createuserAddress: create_userAddress(id: $id address: $address updatedAt: $updatedAt telephone: $telephone default: $default city: $city username: $username postcode: $postcode createdAt: $createdAt deletedAt: $deletedAt user_id: $user_id area: $area province: $province) {
             result
@@ -772,7 +840,7 @@ const shop_by_props = `
 `
 
 const update_shop = `
-    mutation updateshop($description: String, $address: String, $updatedAt: String, $where: shop_filter, $telephone: String, $name: String, $createdAt: String, $status: String, $id: ID, $slideshow: String, $notice: String, $intro: String, $img: String) {
+    mutation updateshop($id: ID, $description: String, $address: String, $updatedAt: String, $where: shop_filter, $telephone: String, $name: String, $createdAt: String, $status: String, $slideshow: String, $notice: String, $intro: String, $img: String) {
         updateshop: update_shop(id: $id description: $description address: $address updatedAt: $updatedAt where: $where telephone: $telephone name: $name createdAt: $createdAt status: $status slideshow: $slideshow notice: $notice intro: $intro img: $img) {
             result
             shop {
@@ -923,5 +991,10 @@ export {
     update_product,
     delete_product_by_id,
 	  slideshow_by_props,
-	  slideshow_by_shop
+	  slideshow_by_shop,
+    all_admin,
+    admin_by_id,
+    create_admin,
+    update_admin,
+    delete_admin
 }